build: version stamping from git tags
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
392b5de92667d0f8053656475a10aa592d206e02- Parents
-
9c530de - Tree
7dfe5fe
392b5de
392b5de92667d0f8053656475a10aa592d206e029c530de
7dfe5fe| Status | File | + | - |
|---|---|---|---|
| M |
Makefile
|
7 | 2 |
| M |
src/gitswitch.h
|
7 | 2 |
| M |
src/main.c
|
1 | 1 |
Makefilemodified@@ -3,9 +3,13 @@ | ||
| 3 | 3 | |
| 4 | 4 | # Project configuration |
| 5 | 5 | PROJECT_NAME = gitswitch-c |
| 6 | -VERSION = 1.0.2 | |
| 7 | 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 | 13 | # Directories |
| 10 | 14 | SRCDIR = src |
| 11 | 15 | BUILDDIR = build |
@@ -24,7 +28,8 @@ CFLAGS = -std=gnu11 -Wall -Wextra -Wstrict-prototypes \ | ||
| 24 | 28 | -Wbad-function-cast -Wnested-externs -Winit-self \ |
| 25 | 29 | -Wshadow -Wwrite-strings -Wcast-align -Wstrict-aliasing=2 \ |
| 26 | 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 | 34 | # Platform-specific flags |
| 30 | 35 | ifeq ($(UNAME_S),Linux) |
src/gitswitch.hmodified@@ -7,8 +7,13 @@ | ||
| 7 | 7 | #include <stdbool.h> |
| 8 | 8 | #include <stdint.h> |
| 9 | 9 | |
| 10 | -/* Version information */ | |
| 11 | -#define GITSWITCH_VERSION "1.1.5" | |
| 10 | +/* Version information - can be overridden at build time via -D flags */ | |
| 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 | 17 | #define GITSWITCH_NAME "gitswitch-c" |
| 13 | 18 | |
| 14 | 19 | /* Configuration constants */ |
src/main.cmodified@@ -58,7 +58,7 @@ static void print_usage(const char *prog_name) { | ||
| 58 | 58 | printf("- Git configuration validation and testing\n"); |
| 59 | 59 | } |
| 60 | 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 | 62 | printf("Safe git identity switching with SSH/GPG isolation\n"); |
| 63 | 63 | printf("Built with security and reliability in mind\n\n"); |
| 64 | 64 | |