From eadebdd35d8afcc9cb36a452ebb49c0209f91c9f Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Mon, 14 Jan 2008 11:31:59 +0100 Subject: [PATCH] Add version generation script, version stamp file Use a single script to generate the version number from git. This script * strips the v from the start of the "git describe" output * changes all "-" occurences to "." * does NOT create a properly sortable version number from "2.1-rc2" type "git describe" output * does NOT generate a "proper" "1.2.3" type version number under any circumstances * will generate "2.1" in case the "git describe" output is "2.1" These policy might need closer adaption to awesome's tagging habit some time. In dist tarballs, ship a "version-stamp" file with the package version in it. If the "version-stamp" file is present (i.e. if it is a source tree from a dist tarball), no git checks will be performed. Concept from autoconf, but code written from scratch to match awesome's requirements. Signed-off-by: Julien Danjou --- Makefile.am | 13 +++++++++++-- autogen.sh | 12 +++++++++--- build-utils/package-version | 22 ++++++++++++++++++++++ configure.ac | 8 +++++++- 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100755 build-utils/package-version diff --git a/Makefile.am b/Makefile.am index 2a85c791..ec0f6cb0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -146,9 +146,12 @@ endif dist-hook: git-version-check distcheck-hook: git-version-check +# Note: We cannot run autogen.sh from here, because we would need some way to +# restart the whole dist process from the start and there is none. +EXTRA_DIST += build-utils/package-version git-version-check: - git_ver=`{ test -d $(top_srcdir)/.git && git --git-dir=$(top_srcdir)/.git describe 2> /dev/null; } || echo devel`; \ - if test "x$${git_ver}" = "x$(PACKAGE_VERSION)" -o "x$${git_ver}" = "xv${PACKAGE_VERSION}"; then :; else \ + git_ver=`$(top_srcdir)/build-utils/package-version $(top_srcdir) version-stamp`; \ + if test "x$${git_ver}" = "x$(PACKAGE_VERSION)"; then :; else \ echo "ERROR: The PACKAGE_VERSION and the 'git describe' version do not match:"; \ echo " current git version: $${git_ver}"; \ echo " current package version: $(PACKAGE_VERSION)"; \ @@ -156,6 +159,12 @@ git-version-check: exit 1; \ fi +# Version stamp files can only exist in tarball source trees. +# +# So there is no need to generate them anywhere else or to clean them +# up anywhere. +dist-hook: + echo "$(PACKAGE_VERSION)" > "$(distdir)/version-stamp" EXTRA_DIST += awesome.doxygen.in diff --git a/autogen.sh b/autogen.sh index 9fde36dd..de5d14eb 100755 --- a/autogen.sh +++ b/autogen.sh @@ -7,13 +7,19 @@ srcdir=`dirname "$0"` # sed program SED=${SED-sed} -# Check whether the version needs to be updated from git infos +# Check whether the version needs to be updated from VCS/version-stamp if [ -d ".git" ] && [ -d "autom4te.cache" ]; then - git_describe=`git describe 2>/dev/null || echo devel` + git_describe=`./build-utils/package-version . version-stamp` for f in autom4te.cache/output.*; do [ -f "$f" ] || continue pkg_ver=`${SED} -n "s/^PACKAGE_VERSION='\(.*\)'\$/\1/p" "$f"` - [ "x$pkg_ver" = "x$git_describe" ] || rm -rf "autom4te.cache" + if [ "x$pkg_ver" = "x$git_describe" ] + then : + else + echo "Cleaning out autom4te.cache (${pkg_ver} -> ${git_describe})" + rm -rf "autom4te.cache" + break + fi done fi diff --git a/build-utils/package-version b/build-utils/package-version new file mode 100755 index 00000000..6a1858c7 --- /dev/null +++ b/build-utils/package-version @@ -0,0 +1,22 @@ +#!/bin/sh +# Syntax: +# $0 +# +# may be relative +# is relative to src/build topdir + +top_srcdir="${1-.}" +test -d "$top_srcdir" || { \ + echo "Could not change to top_srcdir '$1'" >&2; \ + exit 1; \ +} +version_stamp="${2-version-stamp}" + +if test -f "$top_srcdir/$version_stamp"; then # dist source tree + cat "$top_srcdir/$version_stamp" | ${TR-tr} -d '\012' +elif test -d "$top_srcdir/.git"; then # git source tree + git_describe=`${GIT-git} --git-dir="$top_srcdir/.git" describe 2>/dev/null || echo devel` + echo "$git_describe" | ${SED-sed} -e 's/^v//' -e 's/-/./g' | ${TR-tr} -d '\012' +else # ??? + echo "devel" | ${TR-tr} -d '\012' +fi diff --git a/configure.ac b/configure.ac index b14bf28a..51ed2c54 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ AC_PREREQ(2.61) dnl Each time you want an updated version number for your build, you need to dnl (re-)run autoreconf. AC_INIT([awesome window manager], - [m4_esyscmd([{ git describe 2>/dev/null || echo devel; } | tr -d '\n'])], + [m4_esyscmd([./build-utils/package-version . version-stamp])], [http://awesome.naquadah.org/bugs/], [awesome]) AC_CONFIG_AUX_DIR([auto-aux]) @@ -19,6 +19,12 @@ AM_INIT_AUTOMAKE([-Wall -Werror 1.10 dist-bzip2 foreign filename-length-max=99 f AC_DEFINE_UNQUOTED([RELEASE], ["Productivity Breaker"]) +AC_MSG_CHECKING([package version according to autoconf]) +AC_MSG_RESULT([${PACKAGE_VERSION}]) +AC_MSG_CHECKING([package version according to version script]) +version_script=`"${srcdir}/build-utils/package-version" "${srcdir}" version-stamp` +AC_MSG_RESULT([${version_script}]) + # Checks for programs. AC_PROG_SED AC_PROG_CC