From bd8a638e9caa2fa508f8865d9532c821f81fa909 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Sat, 21 Jun 2008 15:54:52 +0200 Subject: Generate version information from git info --- Makefile.am | 2 ++ NEWS | 3 +- build-helpers/package-version | 27 +++++++++++++++++ build-helpers/package-version.mk | 52 ++++++++++++++++++++++++++++++++ configure.ac | 6 ++-- git-buildmsg/Makefile-files | 3 +- m4/ndim-check-sh-command-substitution.m4 | 4 ++- m4/ndim-check-sh-functions.m4 | 3 ++ m4/ndim-check-sh-param-expansion.m4 | 31 +++++++++++++++++++ m4/ndim-require-posix-sh.m4 | 15 +++++++++ 10 files changed, 141 insertions(+), 5 deletions(-) create mode 100755 build-helpers/package-version create mode 100644 build-helpers/package-version.mk create mode 100644 m4/ndim-check-sh-param-expansion.m4 create mode 100644 m4/ndim-require-posix-sh.m4 diff --git a/Makefile.am b/Makefile.am index 8d4b98c..6a0787c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,8 @@ AM_CPPFLAGS = -I${top_builddir}/include ACLOCAL_AMFLAGS = -I m4 --install +include build-helpers/package-version.mk + include Makefile-files include doc/Makefile-files include git-ndim-sh/Makefile-files diff --git a/NEWS b/NEWS index 6735762..885f992 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ -ndim-git-utils 1.17.1 +ndim-git-utils 1.17.39 + * FIXME ndim-git-utils 1.17 New: diff --git a/build-helpers/package-version b/build-helpers/package-version new file mode 100755 index 0000000..61a3018 --- /dev/null +++ b/build-helpers/package-version @@ -0,0 +1,27 @@ +#!/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 GIT_DIR is set, use it. If not, try top_srcdir/.git. +if test -n "$GIT_DIR"; then :; +else GIT_DIR="$top_srcdir/.git"; export GIT_DIR +fi + +if test -f "$top_srcdir/$version_stamp"; then # dist source tree + cat "$top_srcdir/$version_stamp" | ${TR-tr} -d '\012' +elif test -d "$GIT_DIR"; then # git source tree + git_describe=`${GIT-git} describe 2>/dev/null || echo devel` + echo "$git_describe" | ${SED-sed} 's/^v//;s/-/./;s/-g/-/' | ${TR-tr} -d '\012' +else # ??? + echo "devel" | ${TR-tr} -d '\012' +fi diff --git a/build-helpers/package-version.mk b/build-helpers/package-version.mk new file mode 100644 index 0000000..126628e --- /dev/null +++ b/build-helpers/package-version.mk @@ -0,0 +1,52 @@ +BUILD_SCRIPT_DIR = build-helpers + +# Check that package version matches git version before creating dist tarballs +dist-hook: git-version-check git-version-stamp +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. +# FIXME: NEWS check uses ${foo%%-*} POSIX shell, tested +# with bash, dash, busybox. +EXTRA_DIST += $(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version +git-version-check: + @git_ver=`$(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ + if test "x$${git_ver}" = "x$(PACKAGE_VERSION)"; then :; else \ + echo "ERROR: PACKAGE_VERSION and 'git describe' version do not match:"; \ + echo " current 'git describe' version: $${git_ver}"; \ + echo " current PACKAGE_VERSION: $(PACKAGE_VERSION)"; \ + rm -rf "$(top_srcdir)/autom4te.cache"; \ + if test -f "$(top_srcdir)/autogen.sh"; then \ + echo "Update PACKAGE_VERSION by running $(top_srcdir)/autogen.sh."; \ + else \ + echo "Update PACKAGE_VERSION by running autoreconf(1)."; \ + fi; \ + exit 1; \ + fi; \ + case `sed 15q $(top_srcdir)/NEWS` in \ + *"$${git_ver%%-*}"*) : ;; \ + *) \ + echo "NEWS not updated for version $${git_ver%%-*}; not releasing" 1>&2; \ + exit 1;; \ + esac + +# 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. +git-version-stamp: + echo "$(PACKAGE_VERSION)" > "$(distdir)/version-stamp" + +# Update *.h file to contain up-to-date version number +A_V = package-version-internal +CLEANFILES += $(A_V).h +BUILT_SOURCES += $(A_V).h.stamp +$(A_V).h.stamp: + @current_ver=`$(SHELL) $(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ + { echo '#ifndef PACKAGE_VERSION_INTERNAL_H'; \ + echo "#define PACKAGE_VERSION_INTERNAL \"$${current_ver}\""; \ + echo "#endif /* !PACKAGE_VERSION_INTERNAL */"; } > "$(A_V).h.new" + @if test -f "$(A_V).h" \ + && cmp "$(A_V).h.new" "$(A_V).h"; then :; \ + else cat "$(A_V).h.new" > "$(A_V).h"; fi; \ + rm -f "$(A_V).h.new" diff --git a/configure.ac b/configure.ac index 4bb4d74..8e27fa4 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.61) AC_INIT([ndims git utilities], - [1.17.1], + [m4_esyscmd([./build-helpers/package-version . version-stamp])], [hun@n-dimensional.de], [ndim-git-utils]) AC_CONFIG_AUX_DIR([auto-aux]) @@ -10,13 +10,15 @@ AC_CONFIG_HEADER([include/config.h]) AC_CONFIG_SRCDIR([git-amb/git-amb.in]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.10 dist-bzip2 - check-news readme-alpha std-options]) + readme-alpha std-options]) ######################################################################## AC_PROG_SED AC_PROG_CC +m4_pattern_forbid([NDIM_REQUIRE_POSIX_SH])dnl +NDIM_REQUIRE_POSIX_SH()dnl m4_pattern_forbid([NDIM_DETECT_MAN2TXT])dnl NDIM_DETECT_MAN2TXT()dnl diff --git a/git-buildmsg/Makefile-files b/git-buildmsg/Makefile-files index de5a1be..d430bc1 100644 --- a/git-buildmsg/Makefile-files +++ b/git-buildmsg/Makefile-files @@ -50,7 +50,8 @@ check_PROGRAMS += print-buildmsg print_buildmsg_SOURCES = git-buildmsg/print-buildmsg.c nodist_print_buildmsg_SOURCES = $(GIT_BUILDMSG_H) -dist-hook: git-buildmsg.stamp +dist-hook: dist-hook-git-buildmsg +dist-hook-git-buildmsg: git-buildmsg.stamp if test -e "$(GIT_BUILDMSG_H)"; then \ $(SED) -e 's|^#undef GIT_IS_DIST.*|#define GIT_IS_DIST 1|' \ "$(GIT_BUILDMSG_H)" > "$(distdir)/$(GIT_BUILDMSG_H)"; \ diff --git a/m4/ndim-check-sh-command-substitution.m4 b/m4/ndim-check-sh-command-substitution.m4 index 48c5e26..de2e80c 100644 --- a/m4/ndim-check-sh-command-substitution.m4 +++ b/m4/ndim-check-sh-command-substitution.m4 @@ -1,12 +1,14 @@ -# version 1.11 dnl NDIM_CHECK_SH_COMMAND_SUBSTITUTION([ACTION-IF-SUPPORTED], dnl [ACTION-IF-NOT-SUPPORTED)dnl dnl m4_pattern_forbid([NDIM_CHECK_SH_COMMAND_SUBSTITUTION])dnl AC_DEFUN([NDIM_CHECK_SH_COMMAND_SUBSTITUTION],[dnl +AS_IF([test "x$ndim_sh_command_substitution" = "x"], [dnl +AC_MSG_CHECKING([\$(cmd) type sh command substition]) ndim_sh_command_substitution=no test "x$(pwd)" = "x`pwd`" && test "y$(echo "foobar")" = "y`echo foobar`" \ && ndim_sh_command_substitution=yes +AC_MSG_RESULT([$ndim_sh_command_substitution])]) m4_ifval([$1], [ if test "x$ndim_sh_command_substitution" = "xyes"; then $1 diff --git a/m4/ndim-check-sh-functions.m4 b/m4/ndim-check-sh-functions.m4 index a0f5108..0b03dd7 100644 --- a/m4/ndim-check-sh-functions.m4 +++ b/m4/ndim-check-sh-functions.m4 @@ -7,8 +7,11 @@ AC_DEFUN([NDIM_CHECK_SH_FUNCTIONS],[dnl NDIM_CHECK_SH_COMMAND_SUBSTITUTION([], [dnl AC_MSG_ERROR([Sorry, POSIX sh with \$() required.])dnl ])dnl +AS_IF([test "x$ndim_sh_functions" = "x"], [dnl +AC_MSG_CHECKING([whether sh supports POSIX sh functions]) ndim_sh_functions=no test "x$(moo() { echo "meh"; }; moo)" = "xmeh" && ndim_sh_functions=yes +AC_MSG_RESULT([$ndim_sh_functions])]) m4_ifval([$1], [ if test "x$ndim_sh_functions" = "xyes"; then $1 diff --git a/m4/ndim-check-sh-param-expansion.m4 b/m4/ndim-check-sh-param-expansion.m4 new file mode 100644 index 0000000..b253131 --- /dev/null +++ b/m4/ndim-check-sh-param-expansion.m4 @@ -0,0 +1,31 @@ +# version 1.11 +dnl NDIM_CHECK_SH_COMMAND_SUBSTITUTION([ACTION-IF-SUPPORTED], +dnl [ACTION-IF-NOT-SUPPORTED)dnl +dnl +m4_pattern_forbid([NDIM_CHECK_SH_PARAM_SUBSTITUTION])dnl +AC_DEFUN([NDIM_CHECK_SH_PARAM_SUBSTITUTION],[dnl +AS_IF([test "x$ndim_sh_param_substitution" = "x"], [dnl +AC_MSG_CHECKING([\${foo%%bar} type sh param substitution]) +ndim_sh_param_substitution=no +ndim_testvalue="12.34.56-1.23.4-615asdg" +test "x${ndim_testvalue%%-*}" = "x12.34.56" \ + && test "x${ndim_testvalue%-*}" = "x12.34.56-1.23.4" \ + && test "x${ndim_testvalue##*-}" = "x615asdg" \ + && test "x${ndim_testvalue#*-}" = "x1.23.4-615asdg" \ + && ndim_sh_param_substitution=yes +AC_MSG_RESULT([$ndim_sh_param_substitution])]) +m4_ifval([$1], [ +if test "x$ndim_sh_param_substitution" = "xyes"; then +$1 +fi +])dnl +m4_ifval([$2], [ +if test "x$ndim_sh_param_substitution" = "xno"; then +$2 +fi +]) +])dnl +dnl +dnl Local Variables: +dnl mode: autoconf +dnl End: diff --git a/m4/ndim-require-posix-sh.m4 b/m4/ndim-require-posix-sh.m4 new file mode 100644 index 0000000..e5e4814 --- /dev/null +++ b/m4/ndim-require-posix-sh.m4 @@ -0,0 +1,15 @@ +dnl NDIM_REQUIRE_POSIX_SH()dnl +dnl dnl +m4_pattern_forbid([NDIM_REQUIRE_POSIX_SH])dnl +AC_DEFUN([NDIM_REQUIRE_POSIX_SH],[dnl +NDIM_CHECK_SH_COMMAND_SUBSTITUTION([], [dnl +AC_MSG_ERROR([Sorry, POSIX sh with \$() required.])dnl +])dnl +NDIM_CHECK_SH_PARAM_SUBSTITUTION([], [dnl +AC_MSG_ERROR([Sorry, POSIX sh with \${foo%%bar} & Co. required.])dnl +])dnl +])dnl +dnl +dnl Local Variables: +dnl mode: autoconf +dnl End: -- cgit