Use git description as the tinc version.
authorEtienne Dechamps <etienne@edechamps.fr>
Sun, 29 Jun 2014 14:22:10 +0000 (15:22 +0100)
committerEtienne Dechamps <etienne@edechamps.fr>
Sun, 29 Jun 2014 15:57:19 +0000 (16:57 +0100)
Instead of using a hardcoded version number in configure.ac, this makes
tinc use the live version reported by "git describe", queried on-the-fly
during the build process and regenerated for every build.

This provides several advantages:
 - Less redundancy: git is now the source of truth for version
   information, no need to store it in the repository itself.
 - Simpler release process: just creating a git tag automatically
   updates the version. No need to change files.
 - More useful version information: tinc will now display the number of
   commits since the last tag as well as the commit the binary is built
   from, following the format described in git-describe(1).

Here's an example of tincd --version output:

  tinc version release-1.1pre10-48-gc149315 (built Jun 29 2014 15:21:10, protocol 17.3)

When building directly from a release tag, this would like the following:

  tinc version release-1.1pre10 (built Jun 29 2014 15:21:10, protocol 17.3)

(Note that the format is slightly different - because of the way the
tags are named, it says "release-1.1pre10" instead of just "1.1pre10")

configure.ac
src/Makefile.am
src/process.c
src/tincctl.c
src/tincd.c
src/version.c
src/version.h

index 5efb412..172508e 100644 (file)
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.61)
-AC_INIT([tinc], [1.1pre10])
+AC_INIT([tinc], [GIT])
 AC_CONFIG_SRCDIR([src/tincd.c])
 AC_GNU_SOURCE
 AM_INIT_AUTOMAKE([check-news std-options subdir-objects -Wall])
index c48e3fd..08e56ff 100644 (file)
@@ -2,8 +2,11 @@
 
 sbin_PROGRAMS = tincd tinc sptps_test sptps_keypair
 
-## Make sure version.c is always rebuilt
-.PHONY: version.c
+## Make sure version.c is always rebuilt with the latest git information
+.PHONY: version.c version_git.h
+version_git.h:
+       echo "#define GIT_DESCRIPTION \"`cd $(@D) && git describe || echo UNKNOWN`\"" >$@
+version.c: version_git.h
 
 if LINUX
 sbin_PROGRAMS += sptps_speed
@@ -91,7 +94,7 @@ tincd_SOURCES = \
        tincd.c \
        utils.c utils.h \
        xalloc.h \
-       version.c version.h \
+       version.c version.h version_git.h \
        $(ed25519_SOURCES) \
        $(chacha_poly1305_SOURCES)
 
@@ -110,7 +113,7 @@ tinc_SOURCES = \
        tincctl.c tincctl.h \
        top.c top.h \
        utils.c utils.h \
-       version.c version.h \
+       version.c version.h version_git.h \
        $(ed25519_SOURCES) \
        $(chacha_poly1305_SOURCES)
 
index 15120ac..9f99a94 100644 (file)
@@ -224,7 +224,7 @@ bool detach(void) {
        openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
 
        logger(DEBUG_ALWAYS, LOG_NOTICE, "tincd %s (%s %s) starting, debug level %d",
-                          VERSION, BUILD_DATE, BUILD_TIME, debug_level);
+                          BUILD_VERSION, BUILD_DATE, BUILD_TIME, debug_level);
 
        return true;
 }
index fc21d42..6227750 100644 (file)
@@ -86,7 +86,7 @@ static struct option const long_options[] = {
 
 static void version(void) {
        printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
-                  VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
+                  BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
        printf("Copyright (C) 1998-2012 Ivo Timmermans, Guus Sliepen and others.\n"
                        "See the AUTHORS file for a complete list.\n\n"
                        "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
index 30a5678..9f83a3c 100644 (file)
@@ -320,7 +320,7 @@ int main(int argc, char **argv) {
 
        if(show_version) {
                printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
-                          VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
+                          BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
                printf("Copyright (C) 1998-2014 Ivo Timmermans, Guus Sliepen and others.\n"
                                "See the AUTHORS file for a complete list.\n\n"
                                "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
index fc62c8a..67a5e2c 100644 (file)
@@ -18,7 +18,9 @@
 */
 
 #include "version.h"
+#include "version_git.h"
 
 /* This file is always rebuilt (even if there are no changes) so that the following is updated */
 const char* const BUILD_DATE = __DATE__;
 const char* const BUILD_TIME = __TIME__;
+const char* const BUILD_VERSION = GIT_DESCRIPTION;
index d3e4a1f..9cbecb6 100644 (file)
@@ -22,5 +22,6 @@
 
 extern const char* const BUILD_DATE;
 extern const char* const BUILD_TIME;
+extern const char* const BUILD_VERSION;
 
 #endif /* __TINC_VERSION_H__ */