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.
This commit is contained in:
Lephe 2020-06-14 08:30:09 +02:00
parent 41294ec0a4
commit b2172dd88e
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -33,6 +33,13 @@ sflags := $(CONFIG.MACROS)
dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
arflags := 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 # 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 # Version symbol. ld generates a .stack section for unknown reasons; I remove
# it in the linker script. # it in the linker script.
version.o: ../.git/HEAD version.o: $(gitfile)
@ mkdir -p $(dir $@) @ mkdir -p $(dir $@)
@ echo "_GINT_VERSION = $(version_hash);" > $@.txt @ echo "_GINT_VERSION = $(version_hash);" > $@.txt
$(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@ $(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@