]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
If git exists and produces a version with 'git describe --dirty' use it. Otherwise...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 14 May 2021 15:47:24 +0000 (16:47 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 14 May 2021 15:47:24 +0000 (16:47 +0100)
.gitignore
Makefile.am
configure.ac
nqptp.c

index b67ad4580c2beace4aecf2ed72811d611488d715..16036191a2eed9d3d07d0b6c1270f958f5611082 100644 (file)
@@ -50,3 +50,7 @@ Makefile
 
 # Executable
 nqptp
+
+# Version file generated from '$ git describe --dirty'
+gitversion.h
+
index 14696c9e841209a847e54ac45357335aeb816e0c..e7dd8349a0883b4539b4aa0691e239998e793983 100644 (file)
@@ -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
index 26fe52d8fd499936bcc718dddaf4125e9e0adf02..2efff05650bb4cf43e38a185a64c81e4060d17bf 100644 (file)
@@ -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 63b5592dbac8e74b4dc53e95be9945ca987e389d..83cd796f33c9a7b68471fd44b43fbbf900efde09 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
 #include "nqptp-ptp-definitions.h"
 #include "nqptp-utilities.h"
 
+#ifdef CONFIG_USE_GIT_VERSION_STRING
+#include "gitversion.h"
+#endif
+
 #include <arpa/inet.h>
 #include <stdio.h>  //printf
 #include <stdlib.h> //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);