From 566dcf18dcf793369a8b30acfce696823f8e071f Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Thu, 18 Feb 2010 12:36:10 +0100 Subject: [PATCH] Show git sha1 hash in version string (bug #393). This makes it much easier to identify development builds. The exact format may need tweaking; now it shows the previous tag (if any), followed by the first 20 digits of the sha1 hash of the most recent commit. If there's no git repository, the VERSION string defined in configure.ac is used as a fallback. CMake also uses the version string defined in the top CMakeLists.txt. --- configure.ac | 3 +++ src/gmxlib/.gitignore | 1 + src/gmxlib/Makefile.am | 19 ++++++++++++++++--- src/gmxlib/copyrite.c | 8 ++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 7dec0e9b2e..08e00c9174 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,9 @@ AC_DISABLE_SHARED # Simple options and makefile variables ####################################################################### +# This is currently not defined by CMake, because it's tricky to generate +# version.h portably (the autoconf rules for it are in src/gmxlib/Makefile.am). +AC_DEFINE(USE_VERSION_H,,[Use the version string from generated version.h]) ### Single/Double AC_ARG_ENABLE(float, diff --git a/src/gmxlib/.gitignore b/src/gmxlib/.gitignore index c8b084350e..9988bb06d1 100644 --- a/src/gmxlib/.gitignore +++ b/src/gmxlib/.gitignore @@ -1,2 +1,3 @@ .deps .libs +version.h diff --git a/src/gmxlib/Makefile.am b/src/gmxlib/Makefile.am index affd2356a8..bd24c85553 100644 --- a/src/gmxlib/Makefile.am +++ b/src/gmxlib/Makefile.am @@ -75,9 +75,22 @@ libgmx@LIBSUFFIX@_la_SOURCES = \ # clean all libtool libraries, since the target names might have changed -CLEANFILES = *.la *~ \\\#* innerc.c innerf.f mkinl - - +CLEANFILES = *.la *~ \\\#* innerc.c innerf.f mkinl version.h + +#version.h contains git version or version defined in VERSION +copyrite.o: version.h +#The empty target FORCE forces make to run the commands every time. But +#version.h is only changed if the version actually has changed, and hence +#rebuilds are only triggered when they are needed. +#Having the commands in the update_version rule does about the same thing, +#except that one needs to run make twice if the version has changed to rebuild +#copyrite.c. +version.h: FORCE + [ -f version.h ] || touch version.h + version=`git --git-dir=$(top_srcdir)/.git describe --always --long --abbrev=20 HEAD 2>/dev/null || echo @VERSION@`; \ + version="static const char ver_string[] = \"VERSION $$version\";"; \ + echo "$$version" | cmp -s version.h - || echo "$$version" > version.h +FORCE: diff --git a/src/gmxlib/copyrite.c b/src/gmxlib/copyrite.c index 35e3dce2bc..dd6bbf7647 100644 --- a/src/gmxlib/copyrite.c +++ b/src/gmxlib/copyrite.c @@ -524,9 +524,13 @@ void please_cite(FILE *fp,const char *key) */ const char *GromacsVersion() { - - /* Concatenate the version info during preprocessing */ +#ifdef USE_VERSION_H + /* Version generated at compile time. */ + #include "version.h" +#else + /* Fall back to statically defined version. */ static const char ver_string[]="VERSION " VERSION; +#endif return ver_string; } -- 2.11.4.GIT