From 832f77de802322386e002ad2301b7b784f0484fe Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 29 Nov 2025 08:50:38 +0100 Subject: [PATCH] =?UTF-8?q?Makefile=20regenera=20project.h=20autom=C3=A0ti?= =?UTF-8?q?cament?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5522d38..e3f2c9e 100644 --- a/Makefile +++ b/Makefile @@ -106,8 +106,34 @@ endif # Default target all: $(TARGET_FILE) +# Generate build/project.h from template +.PHONY: generate_project_h +generate_project_h: + @$(MKDIR) build 2>/dev/null || true + @echo "Generating build/project.h..." +ifeq ($(OS),Windows_NT) + @powershell -Command \ + "$$name = '$(TARGET_NAME)'; \ + $$long = '$(LONG_NAME)'; \ + $$ver = '$(VERSION)'.TrimStart('v'); \ + $$copy = (Get-Content CMakeLists.txt | Where-Object {$$_ -match 'PROJECT_COPYRIGHT'} | ForEach-Object {if ($$_ -match '\"(.+)\"') {$$matches[1]}}); \ + $$hash = try {git rev-parse --short=7 HEAD 2>$$null} catch {'unknown'}; \ + (Get-Content source/project.h.in) -replace '@PROJECT_NAME@', $$name -replace '@PROJECT_LONG_NAME@', $$long -replace '@PROJECT_VERSION@', $$ver -replace '@PROJECT_COPYRIGHT@', $$copy -replace '@GIT_HASH@', $$hash | Set-Content build/project.h" +else + @PROJECT_COPYRIGHT=$$(grep 'PROJECT_COPYRIGHT' CMakeLists.txt | sed 's/.*"\(.*\)".*/\1/'); \ + PROJECT_VERSION=$$(echo $(VERSION) | sed 's/^v//'); \ + GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \ + sed -e "s/@PROJECT_NAME@/$(TARGET_NAME)/g" \ + -e "s/@PROJECT_LONG_NAME@/$(LONG_NAME)/g" \ + -e "s/@PROJECT_VERSION@/$${PROJECT_VERSION}/g" \ + -e "s/@PROJECT_COPYRIGHT@/$${PROJECT_COPYRIGHT}/g" \ + -e "s/@GIT_HASH@/$${GIT_HASH}/g" \ + source/project.h.in > build/project.h +endif + @echo "build/project.h generated successfully" + # Compile executable -$(TARGET_FILE): $(APP_SOURCES) +$(TARGET_FILE): generate_project_h $(APP_SOURCES) ifeq ($(OS),Windows_NT) @if not exist build $(MKDIR) build @if not exist release\\orni.res $(WINDRES) release\\orni.rc -O coff -o release\\orni.res @@ -119,7 +145,7 @@ endif @echo Compilation successful: $(TARGET_FILE) # Debug build -debug: $(APP_SOURCES) +debug: generate_project_h $(APP_SOURCES) ifeq ($(OS),Windows_NT) @if not exist build $(MKDIR) build $(CXX) $(CXXFLAGS_DEBUG) $(INCLUDES) $(APP_SOURCES) $(LDFLAGS) -o $(TARGET_FILE)_debug.exe