]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Use check-gitversion for improved use of 'git describe' information for versioning.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 5 Aug 2024 17:20:26 +0000 (18:20 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 5 Aug 2024 17:20:26 +0000 (18:20 +0100)
.gitignore
Makefile.am
check-gitversion [new file with mode: 0755]

index b54d1dfe5116d8717b58b92932c923bfd5f7b030..436b0f98e731198c60e0a36d24554811eb048e8b 100644 (file)
@@ -53,6 +53,7 @@ Makefile
 # Executable
 nqptp
 
-# Version file generated from '$ git describe --dirty'
+# Version files generated from check-gitversion
 gitversion.h
+gitversion-stamp
 
index b25fbffa443cfe10e394d793359cfcddeea052f6..22771a7af48f63fc8806978342ac71c4f464fd8b 100644 (file)
@@ -2,20 +2,17 @@ bin_PROGRAMS = nqptp
 nqptp_SOURCES = nqptp.c nqptp-clock-sources.c nqptp-message-handlers.c nqptp-utilities.c general-utilities.c debug.c
 
 AM_CFLAGS = -fno-common -Wall -Wextra -pthread --include=config.h
-CLEANFILES =
+
 
 if USE_GIT_VERSION
-nqptp.c: gitversion.h
-gitversion.h: .git/index
-       echo "// Do not edit!" > gitversion.h
-       echo "// This file is automatically generated by 'git describe --tags --dirty --broken', if available." >> gitversion.h
-       echo -n "  char git_version_string[] = \"" >> gitversion.h
-       git describe --tags --dirty --broken | tr -d '[[:space:]]' >> gitversion.h
-       echo "\";" >> gitversion.h
-FORCE: ;
-CLEANFILES += gitversion.h
-endif
+## Check if the git version information has changed and rebuild gitversion.h if so
+.PHONY: gitversion-check
+gitversion-check: 
+       $(top_srcdir)/check-gitversion
 
+BUILT_SOURCES = gitversion-check
+CLEANFILES = gitversion-stamp gitversion.h
+endif
 
 install-exec-hook:
 if BUILD_FOR_LINUX
diff --git a/check-gitversion b/check-gitversion
new file mode 100755 (executable)
index 0000000..a1c8a9f
--- /dev/null
@@ -0,0 +1,37 @@
+#! /bin/sh
+# echo "This is the git version checker"
+test -f gitversion-stamp && BGD=`cat gitversion-stamp` || :
+# echo "existing gitversion-stamp is $BGD"
+GD=`git describe --tags --dirty --broken --always 2>/dev/null`
+if [ x"$GD" = x ] ; then
+  GD="NA"
+fi
+# echo "current git description is $GD"
+if [ x"$GD" != x"$BGD" ] ; then
+  echo "build: $GD" # optional -- displays git version if new or different
+  echo $GD > gitversion-stamp
+  echo "// Do not edit!" > gitversion.h
+       echo "// This file is automatically generated." >> gitversion.h
+       echo -n "  char git_version_string[] = \"" >> gitversion.h
+       ## the tr is because we need to remove the trailing newline
+       cat gitversion-stamp | tr -d '[[:space:]]' >> gitversion.h
+       echo "\";" >> gitversion.h
+fi
+
+# Usage. Below is what you would add to Makefile.am. When it runs, the
+# following two files are generated: 'gitversion-stamp' and 'gitversion.h'.
+
+# gitversion-stamp stores the most recently used git description.
+# gitversion.h is a C header file containing that git description as a string.
+
+# Put this script in the top level source folder and make sure it has execute permission.
+
+# These are the lines (remove the leading '#' on each) to add to the Makefile.am file:
+# ## Check if the git version information has changed and rebuild gitversion.h if so.
+# .PHONY: gitversion-check
+# gitversion-check: 
+#      $(top_srcdir)/check-gitversion
+
+# ## You may have to change from += to = below:
+# BUILT_SOURCES += gitversion-check
+# CLEANFILES += gitversion-stamp gitversion.h