From db87c29baa6d8688c12fd51f18e84da0455059f3 Mon Sep 17 00:00:00 2001 From: gobbledygoober Date: Mon, 10 Nov 2025 12:47:13 -0500 Subject: [PATCH] new: add t3d.version file to embed in libdragon ROMs --- .gitattributes | 3 ++- Makefile | 32 ++++++++++++++++++++++++++++++-- t3d.version | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 t3d.version diff --git a/.gitattributes b/.gitattributes index 6951cc08..2fac6b89 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ * text=auto # These are all bash scripts and should use lf -*.sh text eol=lf \ No newline at end of file +*.sh text eol=lf +t3d.version export-subst diff --git a/Makefile b/Makefile index 93049bbc..241275fd 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ OBJ = $(BUILD_DIR)/t3dmath.o $(BUILD_DIR)/t3d.o \ $(BUILD_DIR)/rsp/rsp_tiny3d.o $(BUILD_DIR)/rsp/rsp_tiny3d_clipping.o \ $(BUILD_DIR)/rsp/rsp_tinypx.o -all: $(BUILD_DIR)/libt3d.a +all: $(BUILD_DIR)/libt3d.a gen-version # Static Library $(BUILD_DIR)/libt3d.a: $(OBJ) @@ -96,16 +96,44 @@ $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c install: all mkdir -p $(INSTALLDIR)/$(N64_TARGET)/include/t3d + if [ -f "$(BUILD_DIR)/t3d.version" ]; then \ + install -Cv -m 0644 $(BUILD_DIR)/t3d.version $(INSTALLDIR)/$(N64_TARGET)/include/; \ + else \ + rm -f $(INSTALLDIR)/$(N64_TARGET)/include/t3d.version; \ + fi install -cv -m 0644 t3d-inst.mk $(INSTALLDIR)/include/t3d.mk for file in $(inc); do \ install -Cv -m 0644 $$file $(INSTALLDIR)/$(N64_TARGET)/include/t3d; \ done install -Cv -m 0644 $(BUILD_DIR)/libt3d.a $(INSTALLDIR)/$(N64_TARGET)/lib +gen-version: +# Generate a version file for tiny3d. We go through git archive so that +# the export-subst is applied to the template file. +# If .git doesn't exist, assume export-subst ran and just copy the file. +# Otherwise, use git-archive to generate the subst'd version file. +# NOTE: git can fail to access the repository via sudo for security/permissions +# reasons (for instance, it happens on Mac when using sudo on an external volume). +# We check for this via git rev-parse. In these cases, we hope the file was +# generated without sudo as part of the normal build process. + @mkdir -p $(BUILD_DIR) + if [ -e .git ]; then \ + if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then \ + git archive --format=tar HEAD t3d.version \ + | tar -xOf - t3d.version > "$(BUILD_DIR)/t3d.version"; \ + if ! git diff-index --quiet HEAD -- 2>/dev/null; then \ + sed 's/"dirty":[[:space:]]*false/"dirty": true/' "$(BUILD_DIR)/t3d.version" > "$(BUILD_DIR)/version.tmp"; \ + mv -f "$(BUILD_DIR)/version.tmp" "$(BUILD_DIR)/t3d.version"; \ + fi; \ + fi; \ + else \ + cp t3d.version "$(BUILD_DIR)/t3d.version"; \ + fi; + clean: rm -rf $(BUILD_DIR) rm -f $(SOURCE_DIR)/rsp/rsp_tiny3d.h -include $(wildcard $(BUILD_DIR)/*.d) -.PHONY: all clean +.PHONY: all clean gen-version diff --git a/t3d.version b/t3d.version new file mode 100644 index 00000000..e57e345b --- /dev/null +++ b/t3d.version @@ -0,0 +1,5 @@ +{ + "t3d-hash": "$Format:%H$", + "t3d-commit-date": "$Format:%cs$", + "t3d-dirty": false +}