From 92efa43dccd848576aea5cd7852398732471bcae Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 19 Jan 2020 19:18:30 -0800 Subject: [PATCH] Append current git commit hash to version string. But not for distribution tarballs. --- configure.ac | 8 +++++++- src/Makefile.am | 16 +++++++++++++++- src/pwmd-dump.c | 3 ++- src/pwmd.c | 7 ++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 4dfd2a94..09a803a8 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.69) -AC_INIT([pwmd], [3.2.3-dev], [Ben Kibbey ]) +AC_INIT([pwmd], [3.2.3], [Ben Kibbey ]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR(build) AC_CANONICAL_TARGET @@ -12,6 +12,12 @@ AM_CONFIG_HEADER([config.h]) AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.19.8]) +AM_CONDITIONAL([IS_GIT_REPO], [test -f ".git/HEAD"]) +if test -f ".git/HEAD"; then + GIT_BRANCH="`cut -d / -f 3 .git/HEAD`" +fi +AC_SUBST([GIT_BRANCH]) + REQUIRE_LIBGCRYPT_VERSION="1.7.0" REQUIRE_LIBASSUAN_VERSION="2.5.0" REQUIRE_LIBGPGERROR_VERSION="1.29" diff --git a/src/Makefile.am b/src/Makefile.am index a50e70fd..19310cc8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,5 @@ DEFAULT_INCLUDES = -I. -I$(top_builddir) +DISTCLEANFILES = $(top_builddir)/src/version.h bin_PROGRAMS = pwmd pwmd-dump @@ -8,11 +9,24 @@ pwmd_dump_LDADD = @PTHREAD_LIBS@ @GPG_ERROR_LIBS@ @LIBGCRYPT_LIBS@ \ pwmd_dump_CFLAGS = @PTHREAD_CFLAGS@ @GPG_ERROR_CFLAGS@ @LIBGCRYPT_CFLAGS@ \ @LIBASSUAN_CFLAGS@ @XML_CPPFLAGS@ +dist-hook: + chmod u+w "$(top_distdir)/src/version.h" + echo '#define PWMD_GIT_HASH ""' > "$(top_distdir)/src/version.h" + +if IS_GIT_REPO +version.h: $(top_builddir)/.git/refs/heads/@GIT_BRANCH@ + echo '#define PWMD_GIT_HASH "-g'`git log -1 --format="%h"`'"' \ > "$(top_builddir)/src/version.h" +else + echo '#define PWMD_GIT_HASH ""' > "$(top_builddir)/src/version.h" +endif + + pwmd_SOURCES = pwmd.c xml.c xml.h pwmd-error.c pwmd-error.h commands.c \ commands.h common.h cache.c cache.h status.c status.h \ mutex.h rcfile.c rcfile.h util-slist.c util-slist.h \ util-string.c util-string.h util-misc.c util-misc.h gettext.h \ - crypto.c crypto.h agent.c agent.h acl.c acl.h bulk.c bulk.h + crypto.c crypto.h agent.c agent.h acl.c acl.h bulk.c bulk.h \ + version.h pwmd_LDADD = @PTHREAD_LIBS@ @GPG_ERROR_LIBS@ @LIBGCRYPT_LIBS@ \ @GPGME_PTHREAD_LIBS@ @XML_LIBS@ @LIBASSUAN_LIBS@ @LIBINTL@ pwmd_CFLAGS = -DLOCALEDIR=\"${prefix}/share/locale\" @PTHREAD_CFLAGS@ \ diff --git a/src/pwmd-dump.c b/src/pwmd-dump.c index a90beb98..37b83d77 100644 --- a/src/pwmd-dump.c +++ b/src/pwmd-dump.c @@ -65,6 +65,7 @@ #include "util-string.h" #include "mem.h" +#include "version.h" #if 0 #ifdef WITH_AGENT @@ -557,7 +558,7 @@ main(int argc, char **argv) "Copyright (C) 2015-2019\n" "%s\n" "Released under the terms of the GPL v2. Use at your own risk.\n\n"), - PACKAGE_STRING, PACKAGE_BUGREPORT); + PACKAGE_STRING PWMD_GIT_HASH, PACKAGE_BUGREPORT); exit (EXIT_SUCCESS); case 0: switch (optindex) diff --git a/src/pwmd.c b/src/pwmd.c index 0eb740c6..b63e8343 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -85,6 +85,7 @@ #include "rcfile.h" #include "crypto.h" #include "acl.h" +#include "version.h" static int quit; static int cmdline; @@ -589,7 +590,7 @@ new_connection (struct client_s *cl) goto fail; assuan_set_pointer (cl->ctx, cl); - assuan_set_hello_line (cl->ctx, PACKAGE_STRING); + assuan_set_hello_line (cl->ctx, PACKAGE_STRING PWMD_GIT_HASH); rc = register_commands (cl->ctx); if (rc) goto fail; @@ -1527,7 +1528,7 @@ server_loop (int sockfd, char **socketpath) signal (SIGSEGV, catchsig); char *p = get_username (getuid()); - log_write (_("%s started for user %s"), PACKAGE_STRING, p); + log_write (_("%s started for user %s"), PACKAGE_STRING PWMD_GIT_HASH, p); xfree (p); #ifdef WITH_GNUTLS @@ -2045,7 +2046,7 @@ main (int argc, char *argv[]) "Copyright (C) 2006-2019\n" "%s\n" "Released under the terms of the GPL v2.\n\n" - "Compile time features:\n%s"), PACKAGE_STRING, + "Compile time features:\n%s"), PACKAGE_STRING PWMD_GIT_HASH, PACKAGE_BUGREPORT, #ifdef PWMD_HOMEDIR "+PWMD_HOMEDIR=" PWMD_HOMEDIR "\n" -- 2.11.4.GIT