tenseleyflow/gitswitch / 392b5de

Browse files

build: version stamping from git tags

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
392b5de92667d0f8053656475a10aa592d206e02
Parents
9c530de
Tree
7dfe5fe

3 changed files

StatusFile+-
M Makefile 7 2
M src/gitswitch.h 7 2
M src/main.c 1 1
Makefilemodified
@@ -3,9 +3,13 @@
3
 
3
 
4
 # Project configuration
4
 # Project configuration
5
 PROJECT_NAME = gitswitch-c
5
 PROJECT_NAME = gitswitch-c
6
-VERSION = 1.0.2
7
 TARGET = gitswitch
6
 TARGET = gitswitch
8
 
7
 
8
+# Version from git (single source of truth)
9
+GIT_VERSION := $(shell git describe --tags --always 2>/dev/null | sed 's/^v//' || echo "unknown")
10
+GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
11
+VERSION_FLAGS = -DGITSWITCH_VERSION=\"$(GIT_VERSION)\" -DGITSWITCH_COMMIT=\"$(GIT_COMMIT)\"
12
+
9
 # Directories
13
 # Directories
10
 SRCDIR = src
14
 SRCDIR = src
11
 BUILDDIR = build
15
 BUILDDIR = build
@@ -24,7 +28,8 @@ CFLAGS = -std=gnu11 -Wall -Wextra -Wstrict-prototypes \
24
          -Wbad-function-cast -Wnested-externs -Winit-self \
28
          -Wbad-function-cast -Wnested-externs -Winit-self \
25
          -Wshadow -Wwrite-strings -Wcast-align -Wstrict-aliasing=2 \
29
          -Wshadow -Wwrite-strings -Wcast-align -Wstrict-aliasing=2 \
26
          -Wmissing-include-dirs -Wformat=2 -Winit-self \
30
          -Wmissing-include-dirs -Wformat=2 -Winit-self \
27
-         -Wswitch-default -Wunused -Werror-implicit-function-declaration
31
+         -Wswitch-default -Wunused -Werror-implicit-function-declaration \
32
+         $(VERSION_FLAGS)
28
 
33
 
29
 # Platform-specific flags
34
 # Platform-specific flags
30
 ifeq ($(UNAME_S),Linux)
35
 ifeq ($(UNAME_S),Linux)
src/gitswitch.hmodified
@@ -7,8 +7,13 @@
7
 #include <stdbool.h>
7
 #include <stdbool.h>
8
 #include <stdint.h>
8
 #include <stdint.h>
9
 
9
 
10
-/* Version information */
10
+/* Version information - can be overridden at build time via -D flags */
11
-#define GITSWITCH_VERSION "1.1.5"
11
+#ifndef GITSWITCH_VERSION
12
+#define GITSWITCH_VERSION "1.1.7"
13
+#endif
14
+#ifndef GITSWITCH_COMMIT
15
+#define GITSWITCH_COMMIT "unknown"
16
+#endif
12
 #define GITSWITCH_NAME "gitswitch-c"
17
 #define GITSWITCH_NAME "gitswitch-c"
13
 
18
 
14
 /* Configuration constants */
19
 /* Configuration constants */
src/main.cmodified
@@ -58,7 +58,7 @@ static void print_usage(const char *prog_name) {
58
     printf("- Git configuration validation and testing\n");
58
     printf("- Git configuration validation and testing\n");
59
 }
59
 }
60
 static void print_version(void) {
60
 static void print_version(void) {
61
-    printf("%s version %s\n", GITSWITCH_NAME, GITSWITCH_VERSION);
61
+    printf("%s version %s (%s)\n", GITSWITCH_NAME, GITSWITCH_VERSION, GITSWITCH_COMMIT);
62
     printf("Safe git identity switching with SSH/GPG isolation\n");
62
     printf("Safe git identity switching with SSH/GPG isolation\n");
63
     printf("Built with security and reliability in mind\n\n");
63
     printf("Built with security and reliability in mind\n\n");
64
     
64