]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
configure: Optionally use version information obtained from Git in executables
authorTobias Brunner <tobias@strongswan.org>
Tue, 5 May 2020 14:19:09 +0000 (16:19 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 20 Jul 2020 12:10:52 +0000 (14:10 +0200)
The variable GIT_VERSION is always defined, either obtained from Git or
a file that is embedded in tarballs when they are built.  Optionally,
that version is declared as VERSION in config.h so it will be used e.g. in
the daemons when they print the version number.

There is a check that should catch missing tags (i.e. if the version number
in AC_INIT() isn't a prefix of the version obtained via Git).

Makefile.am
configure.ac
scripts/Makefile.am
scripts/git-version [new file with mode: 0755]

index 958edc6fe2d19d0fddc7b38e9157d262deaf1fa0..762a51c140ada38946f33cc018523ec1f0e79732 100644 (file)
@@ -38,6 +38,9 @@ Android.common.mk :   Android.common.mk.in configure.ac
                -e "s:\@PACKAGE_VERSION\@:$(PACKAGE_VERSION):" \
                $(srcdir)/$@.in > $@
 
+dist-hook:
+               @echo $(GIT_VERSION) > $(distdir)/.tarball-git-version
+
 Doxyfile :     Doxyfile.in
                $(AM_V_GEN) \
                sed \
index d71ddeb38c8bdd10d82a9f130a23941639886f84..6ee47f584c7968ca2609e1cc238fd0f5178f2972 100644 (file)
@@ -326,6 +326,7 @@ ARG_ENABL_SET([tss-tss2],       [enable the use of the TSS 2.0 Trusted Software
 
 # compile options
 ARG_ENABL_SET([coverage],       [enable lcov coverage report generation.])
+ARG_ENABL_SET([git-version],    [use output of 'git describe' as version information in executables.])
 ARG_ENABL_SET([leak-detective], [enable malloc hooks to find memory leaks.])
 ARG_ENABL_SET([lock-profiler],  [enable lock/mutex profiling code.])
 ARG_ENABL_SET([log-thread-ids], [use thread ID, if available, instead of an incremented value starting from 1, to identify threads.])
@@ -1384,6 +1385,21 @@ if test "x$ss_cv_static_plugin_constructors" = xyes; then
        fi
 fi
 
+AC_MSG_CHECKING([version from Git repository])
+AC_SUBST(GIT_VERSION, [$($srcdir/scripts/git-version "$srcdir")])
+case "$GIT_VERSION" in
+       "$PACKAGE_VERSION"*)
+               AC_MSG_RESULT([$GIT_VERSION])
+               ;;
+       *)
+               AC_MSG_ERROR([$PACKAGE_VERSION is not a prefix of $GIT_VERSION, tag missing?])
+               ;;
+esac
+
+if test x$git_version = xtrue; then
+       AC_DEFINE_UNQUOTED(VERSION, ["$GIT_VERSION"])
+fi
+
 # ===============================================
 #  collect plugin list for strongSwan components
 # ===============================================
index a793800b7be09113c37a188c8071223f433a5024..82d92ef791cee9b61c5a0edcba47bda16d9252af 100644 (file)
@@ -1,3 +1,5 @@
+EXTRA_DIST = git-version
+
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/libstrongswan \
        -I$(top_srcdir)/src/libtls \
diff --git a/scripts/git-version b/scripts/git-version
new file mode 100755 (executable)
index 0000000..f92d071
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+SRCDIR=$1
+TARBALL=$SRCDIR/.tarball-git-version
+
+if test -f $TARBALL; then
+       V=$(cat $TARBALL)
+elif test -d $SRCDIR/.git; then
+       V=$(git -C $SRCDIR describe --tags HEAD 2>/dev/null)
+fi
+
+if test -z "$V"; then
+       V="UNKNOWN"
+fi
+
+echo $V