summaryrefslogtreecommitdiff
path: root/src/GNUmakefile
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2026-08-29 00:35:58 -0700
committerScott Gasch <[email protected]>2026-08-29 00:35:58 -0700
commita56b15320444fcfe3aabdd3768c81c733f3d776b (patch)
treea2e42365500be22bb5c5023159c3c1dad49f4230 /src/GNUmakefile
parent917bf1260ae217bdcbdbc11c2c37cdb5d3a8eae9 (diff)
Bake the short git commit hash (plus -dirty suffix) into the binary and trace it at startup alongside the build timestamp.
A --logfile trace could previously only be tied back to a build timestamp, not the exact source state -- distinguishing same-day rebuilds during A/B testing required diffing binaries. GIT_COMMIT is injected via GNUmakefile (git rev-parse --short HEAD, kept out of the PROFILE variable itself since PROFILE gets separately stringified whole for the "Make profile used" trace line, and this value's embedded quotes broke that outer string literal when first tried folded in there). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EortUUkDVpsfrbqshBJYJg
Diffstat (limited to 'src/GNUmakefile')
-rw-r--r--src/GNUmakefile15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index bba3ee6..9b42844 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -122,7 +122,20 @@ PROFILE += -DDUMP_TREE
endif
endif # EVERYTHING
-CFLAGS = -DPROFILE="\"$(PROFILE)\"" $(PROFILE) -Wall -Wno-nan-infinity-disabled -Ifathom
+# Short commit hash (plus a -dirty suffix if the working tree has
+# uncommitted changes) baked into the binary so a --logfile trace can
+# be tied back to the exact source state, not just a build timestamp --
+# distinguishing rebuilds of the same day/commit during A/B testing was
+# previously only possible by diffing binaries. Placed here, after all
+# the PROFILE-overwriting `=` assignments above (not `+=`), so it
+# survives into CFLAGS instead of being wiped out by them.
+GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
+GIT_DIRTY := $(shell git diff --quiet 2>/dev/null || echo -dirty)
+# Kept out of PROFILE itself (not folded in via +=): PROFILE gets
+# stringified whole into -DPROFILE="..." below for the "Make profile
+# used" trace line, and this value's embedded quotes broke that outer
+# string literal when it was included there.
+CFLAGS = -DPROFILE="\"$(PROFILE)\"" -DGIT_COMMIT=\"$(GIT_COMMIT)$(GIT_DIRTY)\" $(PROFILE) -Wall -Wno-nan-infinity-disabled -Ifathom
HEADERS = chess.h compiler.h
FATHOM_CFLAGS = -std=gnu99 -O2 -Ifathom $(filter -m32 -m64,$(PROFILE))