From d9b245f4db6df803b96b8431a660ba14078ec6bd Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 21 Dec 2008 20:20:47 +0000 Subject: [PATCH] auto-version: Separate out version deduction magic. This is useful in simpler non-Autoconf projects, so put the magic in a script. --- Makefile.am | 11 ++++++ aclocal.glob | 20 +++++------ auto-version.in | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 12 deletions(-) create mode 100755 auto-version.in diff --git a/Makefile.am b/Makefile.am index 7ca039d..86b4fb0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -95,6 +95,17 @@ confsubst: confsubst.in Makefile chmod +x $@.new mv $@.new $@ +## auto-version +pkgdata_SCRIPTS += auto-version +CLEANFILES += auto-version +EXTRA_DIST += auto-version.in + +auto-version: auto-version.in Makefile + $(confsubst) $(srcdir)/auto-version.in >$@.new \ + VERSION=$(VERSION) + chmod +x $@.new + mv $@.new $@ + ## Testsuites. pkgdata_DATA += autotest.am pkgdata_DATA += testsuite.at diff --git a/aclocal.glob b/aclocal.glob index 0f5a661..eb0e4d0 100644 --- a/aclocal.glob +++ b/aclocal.glob @@ -38,18 +38,14 @@ dnl version number, worked out in some clever way. AC_DEFUN([mdw_AUTO_VERSION], [nobody cares...]) m4_define([mdw_AUTO_VERSION], [m4_define([AUTO_VERSION], m4_esyscmd([ - if test -d .git && version=$(git describe --abbrev=4 2>/dev/null); then - case "$(git diff-index --name-only HEAD)" in - "") ;; *) version="$version+" ;; - esac - elif cat RELEASE 2>/dev/null; then - version=$(cat RELEASE) - elif test -f debian/changelog; then - version=$(sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog) - else - echo UNKNOWN - fi - echo -n $version + ver=UNKNOWN + for pre in ./ config/; do + for post in "" .in; do + try=${pre}auto-version${post} + if test -x $try; then ver=$("$try"); break; fi + done + done + echo -n "$ver" ]))]) dnl --- *@-mdw_LIBTOOL_VERSION_INFO-@* --- diff --git a/auto-version.in b/auto-version.in new file mode 100755 index 0000000..c9b1e27 --- /dev/null +++ b/auto-version.in @@ -0,0 +1,102 @@ +#! /bin/sh +### -*-sh-*- +### +### Make autoconf-like substitutions in files +### +### (c) 2008 Mark Wooding +### + +###----- Licensing notice --------------------------------------------------- +### +### This file is part of the Common Files Distribution (`common'). +### +### `Common' is free software; you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 2 of the License, or +### (at your option) any later version. +### +### `Common' is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with `common'; if not, write to the Free Software Foundation, +### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +set -e +VERSION="@VERSION@" + +###-------------------------------------------------------------------------- +### Parse command line arguments. + +while [ $# -gt 0 ]; do + case $1 in + -h | --h | --he | --hel | --help) + cat <&2 + exit 1 + ;; + *) + break + ;; + esac + shift +done + +if [ $# -ne 0 ]; then + echo >&2 "Usage: auto-version" + exit 1 +fi + +###-------------------------------------------------------------------------- +### Main program. + +## If this is a Git checkout then Git should be able to identify the version. +if [ -d .git ] && version=$(git describe --abbrev=4 2>/dev/null); then + + ## If the working tree is dirty, indicate with a `+'. + case "$(git diff-index --name-only HEAD)" in + "") ;; + *) version="$version+" ;; + esac + echo "$version" + exit 0 +fi + +## If this was unpacked from a source distribution, the RELEASE file sould +## say what the version was. +if [ -f RELEASE ]; then + cat RELEASE + exit 0 +fi + +## If we're Debianized, then the Debian changelog ought to know. +if [ -f debian/changelog ]; then + sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog + exit 0 +fi + +## Otherwise we're screwed. +echo UNKNOWN +exit 0 + +###----- That's all, folks -------------------------------------------------- -- 2.11.0