From bf6a5a643f888decbd9b77900c6ce32a14903c2e Mon Sep 17 00:00:00 2001 From: Matt Penny Date: Mon, 26 Aug 2024 16:36:12 -0400 Subject: [PATCH] Support building from source code archive (#85) Save git describe output on `git archive` and fall back to saved output for version number if building outside of a git repo. --- .gitattributes | 2 ++ Makefile | 11 ++++++++--- version.txt | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .gitattributes create mode 100644 version.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5f0b44a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Save version on export to support building outside of git repo +version.txt export-subst diff --git a/Makefile b/Makefile index 704c4f6..8bbca3c 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,12 @@ $(SKELATOOL64): @$(MAKE) -C skelatool64 -# Use tag name if a tag exists, otherwise use commit hash -GAME_VERSION := $(shell git describe --tags --exact-match HEAD 2>/dev/null || git rev-parse --short HEAD) +# Use tag name if the current commit is tagged, otherwise use commit hash +# If not in a git repo, fall back to exported version +GAME_VERSION := $(shell \ + (git describe --tags HEAD 2>/dev/null || cat version.txt) | \ + awk -F '-' '{print (NF >= 3 ? substr($$3, 2) : $$1)}' \ +) OPTIMIZER := -Os LCDEFS := -DDEBUG -DGAME_VERSION=\"$(GAME_VERSION)\" -g -Werror -Wall @@ -142,7 +146,8 @@ buildgame: $(BASE_TARGET_NAME).z64 .PHONY: gameversion build/version.txt: gameversion ifneq ($(shell cat build/version.txt 2>/dev/null), $(GAME_VERSION)) - echo -n $(GAME_VERSION) > build/version.txt + @mkdir -p $(@D) + @echo -n $(GAME_VERSION) > $@ endif include $(COMMONRULES) diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..be0bb0a --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +$Format:%(describe:tags)$ \ No newline at end of file