summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GNUmakefile15
-rwxr-xr-xsrc/chess.h7
-rwxr-xr-xsrc/main.c2
3 files changed, 22 insertions, 2 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))
diff --git a/src/chess.h b/src/chess.h
index 15f6ca8..b6175f7 100755
--- a/src/chess.h
+++ b/src/chess.h
@@ -209,6 +209,13 @@ typedef struct _DLIST_ENTRY
#define VERSION "1.00"
#define REVISION "$Id: chess.h 354 2008-06-30 05:10:08Z scott $\n"
+// GIT_COMMIT is normally injected by GNUmakefile via -DGIT_COMMIT (short
+// hash, plus a -dirty suffix if the tree had uncommitted changes at build
+// time); this is just a fallback for any build path that doesn't set it.
+#ifndef GIT_COMMIT
+#define GIT_COMMIT "unknown"
+#endif
+
//
// Function decorators
//
diff --git a/src/main.c b/src/main.c
index b09c8f0..baafe12 100755
--- a/src/main.c
+++ b/src/main.c
@@ -47,7 +47,7 @@ Return value:
{
char *p;
- Trace("Typhoon %s (built on %s %s):\n", VERSION, __DATE__, __TIME__);
+ Trace("Typhoon %s (built on %s %s, commit %s):\n", VERSION, __DATE__, __TIME__, GIT_COMMIT);
Trace(" Copyright (C) 2000-2007, Scott Gasch ([email protected])\n");
Trace(" " REVISION);
Trace(" " COMPILER_STRING);