From c0828a0569687ed38e4cf580e157a22d170c9fa8 Mon Sep 17 00:00:00 2001 From: Michael Dewberry Date: Sun, 14 Jan 2024 00:48:39 -0500 Subject: [PATCH] Update git tag/hash correctly in non-clean builds --- Makefile | 4 ++-- firmware/ansible.mk | 4 ++-- firmware/common.mk | 2 ++ firmware/earthsea.mk | 2 +- firmware/meadowphysics.mk | 3 ++- firmware/teletype.mk | 4 ++-- firmware/whitewhale.mk | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 9b308f6..53f79c4 100644 --- a/Makefile +++ b/Makefile @@ -58,14 +58,14 @@ $(ragel): firmware-build: export PATH := $(PWD)/dep/bin:$(PATH) firmware-build: export RACK_DIR := $(realpath $(RACK_DIR)) -firmware-build: firmware/*.mk firmware/**/*.c firmware/**/*.h firmware/**/**/*.rl +firmware-build: cd firmware && $(MAKE) -f whitewhale.mk TARGET_NAME=whitewhale cd firmware && $(MAKE) -f whitewhale.mk TARGET_NAME=whitewhale-kria cd firmware && $(MAKE) -f meadowphysics.mk cd firmware && $(MAKE) -f earthsea.mk + cd firmware && $(MAKE) -f ansible.mk cd firmware && $(MAKE) -f teletype.mk TARGET_NAME=teletype4 cd firmware && $(MAKE) -f teletype.mk TARGET_NAME=teletype5 - cd firmware && $(MAKE) -f ansible.mk firmware-clean: rm -fv res/firmware/*.dll diff --git a/firmware/ansible.mk b/firmware/ansible.mk index 80d28fd..9d10234 100644 --- a/firmware/ansible.mk +++ b/firmware/ansible.mk @@ -46,7 +46,7 @@ SOURCES = \ $(wildcard mock_hardware/modules/ansible/*.c) \ # Add the git commit id to a file for use when printing out the version -ansible/src/gitversion.c: ansible - echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell cd ansible; git describe --tags | cut -c 1-)) $(shell cd ansible; git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\";" > $@ +ansible/src/gitversion.c: $(shell find ../.git/modules/firmware/$(TARGET_NAME)/refs) ../.git/modules/firmware/$(TARGET_NAME)/packed-refs ../.git/modules/firmware/$(TARGET_NAME)/HEAD + echo "const char *git_version = \"$(GIT_VERSION)\";" > $@ include common.mk diff --git a/firmware/common.mk b/firmware/common.mk index 60a9536..dc2dede 100644 --- a/firmware/common.mk +++ b/firmware/common.mk @@ -4,6 +4,8 @@ RACK_DIR ?= ../../.. TARGET_DIR := ../res/firmware/ BUILD_DIR := ../build/firmware/$(TARGET_NAME) +GIT_VERSION := $(shell cut -d '-' -f 1 <<< $(shell cd $(TARGET_NAME); git describe --tags | cut -c 1-)) $(shell cd $(TARGET_NAME); git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]') + FLAGS += \ -DDEBUG \ -DNULL=0 \ diff --git a/firmware/earthsea.mk b/firmware/earthsea.mk index c9695b2..8bc618e 100644 --- a/firmware/earthsea.mk +++ b/firmware/earthsea.mk @@ -27,6 +27,6 @@ SOURCES = \ $(wildcard mock_hardware/common/*.c) \ $(wildcard mock_hardware/modules/trilogy/*.c) \ -FLAGS += -DGIT_VERSION="\"$(shell cut -d '-' -f 1 <<< $(shell cd earthsea; git describe --tags | cut -c 1-)) $(shell cd earthsea; git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\"" +FLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\"" include common.mk diff --git a/firmware/meadowphysics.mk b/firmware/meadowphysics.mk index 780eaec..a3388d5 100644 --- a/firmware/meadowphysics.mk +++ b/firmware/meadowphysics.mk @@ -22,6 +22,7 @@ SOURCES = \ $(wildcard mock_hardware/common/*.c) \ $(wildcard mock_hardware/modules/trilogy/*.c) \ -FLAGS += -DGIT_VERSION="\"$(shell cut -d '-' -f 1 <<< $(shell cd meadowphysics; git describe --tags | cut -c 1-)) $(shell cd meadowphysics; git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\"" +FLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\"" + include common.mk diff --git a/firmware/teletype.mk b/firmware/teletype.mk index 50653c3..4f1d7cd 100644 --- a/firmware/teletype.mk +++ b/firmware/teletype.mk @@ -51,7 +51,7 @@ $(TARGET_NAME)/src/scanner.c: $(TARGET_NAME)/src/scanner.rl $(RAGEL) -C -G2 $(TARGET_NAME)/src/scanner.rl -o $(TARGET_NAME)/src/scanner.c # Add the git commit id to a file for use when printing out the version -$(TARGET_NAME)/module/gitversion.c: $(TARGET_NAME) - echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell cd $(TARGET_NAME); git describe --tags | cut -c 1-)) $(shell cd $(TARGET_NAME); git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\";" > $@ +$(TARGET_NAME)/module/gitversion.c: $(shell find ../.git/modules/firmware/$(TARGET_NAME)/refs) ../.git/modules/firmware/$(TARGET_NAME)/packed-refs ../.git/modules/firmware/$(TARGET_NAME)/HEAD + echo "const char *git_version = \"$(GIT_VERSION)\";" > $@ include common.mk diff --git a/firmware/whitewhale.mk b/firmware/whitewhale.mk index 48a2cbd..8a1c1d6 100644 --- a/firmware/whitewhale.mk +++ b/firmware/whitewhale.mk @@ -20,6 +20,6 @@ SOURCES = \ $(wildcard mock_hardware/common/*.c) \ $(wildcard mock_hardware/modules/trilogy/*.c) \ -FLAGS += -DGIT_VERSION="\"$(shell cut -d '-' -f 1 <<< $(shell cd $(TARGET_NAME); git describe --tags | cut -c 1-)) $(shell cd $(TARGET_NAME); git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\"" +FLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\"" include common.mk