Makefile regenera project.h automàticament
This commit is contained in:
30
Makefile
30
Makefile
@@ -106,8 +106,34 @@ endif
|
|||||||
# Default target
|
# Default target
|
||||||
all: $(TARGET_FILE)
|
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
|
# Compile executable
|
||||||
$(TARGET_FILE): $(APP_SOURCES)
|
$(TARGET_FILE): generate_project_h $(APP_SOURCES)
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
@if not exist build $(MKDIR) build
|
@if not exist build $(MKDIR) build
|
||||||
@if not exist release\\orni.res $(WINDRES) release\\orni.rc -O coff -o release\\orni.res
|
@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)
|
@echo Compilation successful: $(TARGET_FILE)
|
||||||
|
|
||||||
# Debug build
|
# Debug build
|
||||||
debug: $(APP_SOURCES)
|
debug: generate_project_h $(APP_SOURCES)
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
@if not exist build $(MKDIR) build
|
@if not exist build $(MKDIR) build
|
||||||
$(CXX) $(CXXFLAGS_DEBUG) $(INCLUDES) $(APP_SOURCES) $(LDFLAGS) -o $(TARGET_FILE)_debug.exe
|
$(CXX) $(CXXFLAGS_DEBUG) $(INCLUDES) $(APP_SOURCES) $(LDFLAGS) -o $(TARGET_FILE)_debug.exe
|
||||||
|
|||||||
Reference in New Issue
Block a user