summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2016-11-02 21:45:47 +0100
committerMarc Schink <swo-dev@marcschink.de>2017-01-13 11:50:49 +0100
commite1ea00e7af7492e8b005ab89f9ee488708b9e491 (patch)
tree9a25cd4165583f6e202317a82e18af7bd67bafed
parent451c6bf629c199e5c4defb992bba12d52dcbd5ed (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--.gitignore2
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac5
-rw-r--r--m4/swodec.m465
-rw-r--r--src/main.c4
-rw-r--r--src/version.h.in35
6 files changed, 109 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 75129b3..90e134b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,9 +10,9 @@ configure
.libs
libtool
*.lo
-m4
Makefile
Makefile.in
*.o
stamp-h1
swodec
+version.h
diff --git a/autogen.sh b/autogen.sh
index 97a5c93..bb71d18 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -21,7 +21,7 @@
echo "Generating build system..."
mkdir -p m4 build-aux
-aclocal || exit 1
+aclocal -I m4 || exit 1
autoheader || exit 1
autoconf || exit 1
automake --add-missing --copy || exit 1
diff --git a/configure.ac b/configure.ac
index 9e87c36..cb0639e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,8 @@ PKG_CHECK_MODULES([libswo], [libswo >= 0.1.0])
# Checks for library functions.
+SWODEC_SET_PACKAGE_VERSION([SWODEC_VERSION_PACKAGE], [AC_PACKAGE_VERSION])
+
# Use C99 compatible stdio functions on MinGW instead of the incompatible
# functions provided by Microsoft.
AS_CASE([$host_os], [mingw*],
@@ -62,12 +64,13 @@ AC_SUBST([SWODEC_CFLAGS])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
+AC_CONFIG_FILES([src/version.h])
AC_OUTPUT
echo
echo "swodec configuration summary:"
-echo " - Package version ................ $PACKAGE_VERSION"
+echo " - Package version ................ $SWODEC_VERSION_PACKAGE"
echo " - Installation prefix ............ $prefix"
echo " - Building on .................... $build"
echo " - Building for ................... $host"
diff --git a/m4/swodec.m4 b/m4/swodec.m4
new file mode 100644
index 0000000..f81a9e9
--- /dev/null
+++ b/m4/swodec.m4
@@ -0,0 +1,65 @@
+##
+## This file is part of the swodec 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
+
+## _SWODEC_SET_PACKAGE_VERSION(prefix, version, major, minor, micro)
+##
+m4_define([_SWODEC_SET_PACKAGE_VERSION], [
+ m4_assert([$# == 5])
+
+ # Get the short Git revision hash of the current commit.
+ git_version=`git --git-dir="$srcdir/.git" rev-parse \
+ --short HEAD 2> /dev/null`
+
+ # Try to get the release tag for the package version from the current
+ # commit.
+ tag=`git --git-dir="$srcdir/.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])
+])
+
+## SWODEC_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([SWODEC_SET_PACKAGE_VERSION], [
+ m4_assert([$# == 2])
+
+ _SWODEC_SET_PACKAGE_VERSION([$1], [$2],
+ m4_unquote(m4_split(m4_expand([$2]), [\.])))
+])
diff --git a/src/main.c b/src/main.c
index 7b282c1..8479a09 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,8 @@
#include <libswo/libswo.h>
+#include "version.h"
+
/*
* Exception names according to section B1.5 of ARMv7-M Architecture Reference
* Manual.
@@ -484,7 +486,7 @@ static int packet_cb(struct libswo_context *ctx,
static void show_version(void)
{
- printf("%s\n", PACKAGE_STRING);
+ printf("%s\n", SWODEC_VERSION_PACKAGE_STRING);
printf("Using libswo %s\n", libswo_version_package_get_string());
}
diff --git a/src/version.h.in b/src/version.h.in
new file mode 100644
index 0000000..4a53382
--- /dev/null
+++ b/src/version.h.in
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the swodec 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/>.
+ */
+
+#ifndef SWODEC_VERSION_H
+#define SWODEC_VERSION_H
+
+/* Major version number of the swodec package. */
+#define SWODEC_VERSION_PACKAGE_MAJOR @SWODEC_VERSION_PACKAGE_MAJOR@
+
+/* Minor version number of the swodec package. */
+#define SWODEC_VERSION_PACKAGE_MINOR @SWODEC_VERSION_PACKAGE_MINOR@
+
+/* Micro version number of the swodec package. */
+#define SWODEC_VERSION_PACKAGE_MICRO @SWODEC_VERSION_PACKAGE_MICRO@
+
+/* Version number string of the swodec package. */
+#define SWODEC_VERSION_PACKAGE_STRING "@SWODEC_VERSION_PACKAGE@"
+
+#endif /* SWODEC_VERSION_H */