aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2016-11-02 15:42:11 +0100
committerMarc Schink <swo-dev@marcschink.de>2016-11-02 16:13:58 +0100
commitf13a3aa5914b2e5e9838da2b3dcdef22e07d7d86 (patch)
treeea3e2a8021937a436bf35068fd818b109388255e
parent0d5949e1cb68553bd76c25b25708c1875ed85db9 (diff)
Append Git revision hash to package version
Append the short Git revision hash of the current commit to the package version if there is no release tag for the package version on it and Git is available. This makes the package version more informative and allows the distinction between development and release versions. This code is inspired by, but not derived from, a patch from Daniel Elstner for the libsigrok project.
-rw-r--r--.gitignore3
-rw-r--r--configure.ac21
-rw-r--r--m4/libswo.m463
3 files changed, 68 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 1dec600..1e249b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,8 @@ libswocxx.pc
libswo.pc
libtool
*.lo
-m4
+m4/libtool.m4
+m4/lt*.m4
Makefile
Makefile.in
*.o
diff --git a/configure.ac b/configure.ac
index 6679217..20c0ee8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,14 +19,7 @@
AC_PREREQ([2.69])
-# Package version of libswo. This is not the same as the libtool interface
-# version.
-m4_define([libswo_version_package_major], [0])
-m4_define([libswo_version_package_minor], [1])
-m4_define([libswo_version_package_micro], [0])
-m4_define([libswo_version_package], [libswo_version_package_major.libswo_version_package_minor.libswo_version_package_micro])
-
-AC_INIT([libswo], [libswo_version_package], [BUG-REPORT-ADDRESS])
+AC_INIT([libswo], [0.1.0], [BUG-REPORT-ADDRESS])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
@@ -87,6 +80,8 @@ AC_MSG_RESULT([$HAVE_PYTHON_DEV])
# Check for Python setuptools.
AX_PYTHON_MODULE([setuptools])
+LIBSWO_SET_PACKAGE_VERSION([LIBSWO_VERSION_PACKAGE], [AC_PACKAGE_VERSION])
+
# Libtool interface version of libswo. This is not the same as the package
# version. For information about the versioning system of libtool, see:
# http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning
@@ -172,16 +167,6 @@ fi
AM_CONDITIONAL(BINDINGS_CXX, [test "x$BINDINGS_CXX" = "xyes"])
AM_CONDITIONAL(BINDINGS_PYTHON, [test "x$BINDINGS_PYTHON" = "xyes"])
-LIBSWO_VERSION_PACKAGE_MAJOR=libswo_version_package_major
-LIBSWO_VERSION_PACKAGE_MINOR=libswo_version_package_minor
-LIBSWO_VERSION_PACKAGE_MICRO=libswo_version_package_micro
-LIBSWO_VERSION_PACKAGE=libswo_version_package
-
-AC_SUBST(LIBSWO_VERSION_PACKAGE_MAJOR)
-AC_SUBST(LIBSWO_VERSION_PACKAGE_MINOR)
-AC_SUBST(LIBSWO_VERSION_PACKAGE_MICRO)
-AC_SUBST(LIBSWO_VERSION_PACKAGE)
-
# Use C99 compatible stdio functions on MinGW instead of the incompatible
# functions provided by Microsoft.
AS_CASE([$host_os], [mingw*],
diff --git a/m4/libswo.m4 b/m4/libswo.m4
new file mode 100644
index 0000000..864c038
--- /dev/null
+++ b/m4/libswo.m4
@@ -0,0 +1,63 @@
+##
+## This file is part of the libswo project.
+##
+## Copyright (C) 2016 Marc Schink <swo-dev@marcschink.de>
+##
+## This program 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 3 of the License, or
+## (at your option) any later version.
+##
+## This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+##
+
+# serial 20161102
+
+## _LIBSWO_SET_PACKAGE_VERSION(prefix, version, major, minor, micro)
+##
+m4_define([_LIBSWO_SET_PACKAGE_VERSION], [
+ m4_assert([$# == 5])
+
+ # Get the short Git revision hash of the current commit.
+ git_version=`git rev-parse --short HEAD 2> /dev/null`
+
+ # Try to get the release tag for the package version from the current
+ # commit.
+ tag=`git describe --match "$2" --exact-match 2> /dev/null`
+
+ version=$2
+
+ # If Git is available, append the short Git revision hash of the
+ # current commit to the version string if there is no release tag for
+ # the package version on it.
+ AS_IF([test -n "$git_version" && test -z "$tag"],
+ [version="$version-git-$git_version"])
+
+ AC_SUBST([$1_MAJOR], [$3])
+ AC_SUBST([$1_MINOR], [$4])
+ AC_SUBST([$1_MICRO], [$5])
+ AC_SUBST([$1], [$version])
+])
+
+## LIBSWO_SET_PACKAGE_VERSION(prefix, version)
+##
+## Parse the package version string of the format <major>.<minor>.<micro> and
+## set the variables <prefix>_{MAJOR,MINOR,MICRO} to their corresponding
+## values.
+##
+## Set the variable <prefix> to the package version string. If Git is
+## available, append the short Git revision hash of the current commit to the
+## version string if there is no release tag for the package version on it.
+##
+AC_DEFUN([LIBSWO_SET_PACKAGE_VERSION], [
+ m4_assert([$# == 2])
+
+ _LIBSWO_SET_PACKAGE_VERSION([$1], [$2],
+ m4_unquote(m4_split(m4_expand([$2]), [\.])))
+])