From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 14 May 2021 15:47:24 +0000 (+0100) Subject: If git exists and produces a version with 'git describe --dirty' use it. Otherwise... X-Git-Tag: 1.2~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8af76ecffaa3451405e7c78f56b7d211435217a6;p=thirdparty%2Fnqptp.git If git exists and produces a version with 'git describe --dirty' use it. Otherwise use the version from configure.ac --- diff --git a/.gitignore b/.gitignore index b67ad45..1603619 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,7 @@ Makefile # Executable nqptp + +# Version file generated from '$ git describe --dirty' +gitversion.h + diff --git a/Makefile.am b/Makefile.am index 14696c9..e7dd834 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,17 @@ nqptp_SOURCES = nqptp.c nqptp-clock-sources.c nqptp-message-handlers.c nqptp-uti AM_CFLAGS = -fno-common -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread +if USE_GIT +nqptp.c: gitversion.h +gitversion.h: FORCE + echo "// Do not edit!" > gitversion.h + echo "// This file is automatically generated by 'git describe --dirty', if available." >> gitversion.h + echo -n " char git_version_string[] = \"" >> gitversion.h + git describe --dirty | tr -d '[[:space:]]' >> gitversion.h + echo "\";" >> gitversion.h +FORCE: ; +endif + install-exec-hook: -e /lib/systemd/system || mkdir -p /lib/systemd/system - -f /lib/systemd/system/nqptp.service || cp nqptp.service /lib/systemd/system \ No newline at end of file + -f /lib/systemd/system/nqptp.service || cp nqptp.service /lib/systemd/system diff --git a/configure.ac b/configure.ac index 26fe52d..2efff05 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,13 @@ AC_PREREQ([2.68]) AC_INIT([nqptp], [1.1-dev], [4265913+mikebrady@users.noreply.github.com]) AM_INIT_AUTOMAKE + +AC_CHECK_PROGS([GIT], [git]) +if test -n "$GIT"; then + AC_DEFINE([CONFIG_USE_GIT_VERSION_STRING], 1, [Use the version string produced by running 'git describe --dirty'.]) +fi +AM_CONDITIONAL([USE_GIT], [test -n "$GIT"]) + AC_CONFIG_SRCDIR([nqptp.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/nqptp.c b/nqptp.c index 63b5592..83cd796 100644 --- a/nqptp.c +++ b/nqptp.c @@ -25,6 +25,10 @@ #include "nqptp-ptp-definitions.h" #include "nqptp-utilities.h" +#ifdef CONFIG_USE_GIT_VERSION_STRING +#include "gitversion.h" +#endif + #include #include //printf #include //malloc; @@ -131,6 +135,12 @@ int main(int argc, char **argv) { for (i = 1; i < argc; ++i) { if (argv[i][0] == '-') { if (strcmp(argv[i] + 1, "V") == 0) { +#ifdef CONFIG_USE_GIT_VERSION_STRING + if (git_version_string[0] != '\0') + fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string, + NQPTP_SHM_STRUCTURES_VERSION); + else +#endif fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION, NQPTP_SHM_STRUCTURES_VERSION); exit(EXIT_SUCCESS);