From b2172dd88e99e2170d637c1f3c7452d956abf1e7 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 14 Jun 2020 08:30:09 +0200 Subject: [PATCH] make: improve the Git commit approximation scheme Retrieve commit from branch reference when not in detached HEAD mode. A full rebuild is still needed after changing branch, but not at each commit. --- make/Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/make/Makefile b/make/Makefile index 747327c..e92843d 100755 --- a/make/Makefile +++ b/make/Makefile @@ -33,6 +33,13 @@ sflags := $(CONFIG.MACROS) dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP arflags := +# Git file with current hash +ifeq "$(shell git branch --show-current)" "" +gitfile := ../.git/HEAD +else +gitfile := ../.git/refs/heads/$(shell git branch --show-current) +endif + # # File listings @@ -118,7 +125,7 @@ $(call src2obj,../src/font8x9.png): ../src/font8x9.png # Version symbol. ld generates a .stack section for unknown reasons; I remove # it in the linker script. -version.o: ../.git/HEAD +version.o: $(gitfile) @ mkdir -p $(dir $@) @ echo "_GINT_VERSION = $(version_hash);" > $@.txt $(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@