diff --git a/CMakeLists.txt b/CMakeLists.txt index d70c6ff..c633ffd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,11 +260,6 @@ elseif(EMSCRIPTEN) set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html") endif() -# Ejecutable en la raíz del proyecto (solo nativos). A Emscripten queda dins build/. -if(NOT EMSCRIPTEN) - set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) -endif() - # --- EINA STANDALONE: pack_resources --- # Executable auxiliar que empaqueta `data/` a `resources.pack` (format AEE1). # No es compila per defecte (EXCLUDE_FROM_ALL). Build explícit: @@ -283,7 +278,7 @@ if(NOT EMSCRIPTEN) # canviat. Evita debugar amb un pack obsolet. CONFIGURE_DEPENDS força CMake # a re-globbar a la pròxima invocació (recull fitxers nous afegits a data/). file(GLOB_RECURSE DATA_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/data/*") - set(RESOURCE_PACK "${CMAKE_SOURCE_DIR}/resources.pack") + set(RESOURCE_PACK "${CMAKE_BINARY_DIR}/resources.pack") add_custom_command( OUTPUT ${RESOURCE_PACK} @@ -298,6 +293,26 @@ if(NOT EMSCRIPTEN) add_custom_target(resource_pack ALL DEPENDS ${RESOURCE_PACK}) add_dependencies(${PROJECT_NAME} resource_pack) + + # --- CÒPIA DE gamecontrollerdb.txt AL COSTAT DEL BINARI --- + # SDL_AddGamepadMappingsFromFile només llegeix del filesystem real (no del + # pack), així que el fitxer ha de viure al directori del binari. Es copia + # només si existeix per no fallar la build d'algú que encara no ha fet + # `make controllerdb`. + if(EXISTS "${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt") + set(CONTROLLER_DB "${CMAKE_BINARY_DIR}/gamecontrollerdb.txt") + add_custom_command( + OUTPUT ${CONTROLLER_DB} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt" + "${CONTROLLER_DB}" + DEPENDS "${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt" + COMMENT "Copiant gamecontrollerdb.txt → build/" + VERBATIM + ) + add_custom_target(controller_db ALL DEPENDS ${CONTROLLER_DB}) + add_dependencies(${PROJECT_NAME} controller_db) + endif() endif() # --- STATIC ANALYSIS TARGETS --- diff --git a/Makefile b/Makefile index e62a774..3a02b8f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # DIRECTORIES # ============================================================================== DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST))) -DIR_BIN := $(addsuffix /, $(DIR_ROOT)) +BUILDDIR := build # ============================================================================== # TOOLS @@ -20,7 +20,7 @@ endif # TARGET NAMES # ============================================================================== TARGET_NAME := aee -TARGET_FILE := $(DIR_BIN)$(TARGET_NAME) +TARGET_FILE := $(BUILDDIR)/$(TARGET_NAME) APP_NAME := Aventures en Egipte DIST_DIR := dist RELEASE_FOLDER := dist/_tmp @@ -61,7 +61,7 @@ endif # WINDOWS-SPECIFIC VARIABLES # ============================================================================== ifeq ($(OS),Windows_NT) - WIN_TARGET_FILE := $(DIR_BIN)$(APP_NAME) + WIN_TARGET_FILE := $(BUILDDIR)/$(APP_NAME) WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME) # Escapa apòstrofs per a PowerShell (duplica ' → ''). Sense això, APP_NAMEs # com "JailDoctor's Dilemma" trencarien el parsing de -Destination '...'. @@ -134,10 +134,21 @@ debug: @cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) @cmake --build build +run: all + @./$(TARGET_FILE) + +run-debug: debug + @./$(TARGET_FILE) + +clean: + @rm -rf $(BUILDDIR) + +rebuild: clean all + # ============================================================================== # REGLAS PARA COMPILACIÓN DE SHADERS (multiplataforma via cmake) # ============================================================================== -compile_shaders: +compile-shaders: ifdef GLSLC @cmake -D GLSLC=$(GLSLC) -D SHADERS_DIR=$(SHADERS_DIR) -D HEADERS_DIR=$(HEADERS_DIR) -P $(SHADER_CMAKE) else @@ -148,26 +159,26 @@ endif pack: @cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH) @cmake --build build --target pack_resources - @./build/pack_resources data resources.pack + @./build/pack_resources data build/resources.pack # ============================================================================== # RELEASE AUTOMÁTICO (detecta SO) # ============================================================================== release: ifeq ($(OS),Windows_NT) - @"$(MAKE)" _windows_release + @"$(MAKE)" _windows-release else ifeq ($(UNAME_S),Darwin) - @$(MAKE) _macos_release + @$(MAKE) _macos-release else - @$(MAKE) _linux_release + @$(MAKE) _linux-release endif endif # ============================================================================== # COMPILACIÓN PARA WINDOWS (RELEASE) # ============================================================================== -_windows_release: pack +_windows-release: pack @echo off @echo Creando release para Windows - Version: $(VERSION) @@ -181,7 +192,7 @@ _windows_release: pack @powershell -Command "if (-not (Test-Path '$(RELEASE_FOLDER)')) {New-Item '$(RELEASE_FOLDER)' -ItemType Directory}" # Copia ficheros (resources.pack substitueix la carpeta data/) - @powershell -Command "Copy-Item 'resources.pack' -Destination '$(RELEASE_FOLDER)'" + @powershell -Command "Copy-Item 'build/resources.pack' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'gamecontrollerdb.txt' -Destination '$(RELEASE_FOLDER)'" @@ -200,7 +211,7 @@ _windows_release: pack # ============================================================================== # COMPILACIÓN PARA MACOS (RELEASE) # ============================================================================== -_macos_release: pack +_macos-release: pack @echo "Creando release para macOS - Version: $(VERSION)" # Verifica dependencias necesarias (create-dmg). Si falta, intenta instalarla @@ -239,7 +250,7 @@ _macos_release: pack $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" # Copia carpetas y ficheros (resources.pack substitueix la carpeta data/) - cp resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" + cp build/resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" cp -R release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks" cp release/icons/*.icns "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" @@ -352,26 +363,26 @@ wasm: ssh maverick 'cd /home/sergio/gitea/web_jailgames && ./deploy.sh' @echo "Deployed to maverick" -# Versió Debug del build wasm: build local sense deploy. Sortida a dist/wasm_debug/. -wasm_debug: +# Versió Debug del build wasm: build local sense deploy. Sortida a dist/wasm-debug/. +wasm-debug: @echo "Compilando WebAssembly Debug - Version: $(VERSION)" docker run --rm \ --user $(shell id -u):$(shell id -g) \ -v $(DIR_ROOT):/src \ -w /src \ emscripten/emsdk:latest \ - bash -c "emcmake cmake -S . -B build/wasm_debug -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) && cmake --build build/wasm_debug" - @$(MKDIR) "$(DIST_DIR)/wasm_debug" - @cp build/wasm_debug/$(TARGET_NAME).html $(DIST_DIR)/wasm_debug/ - @cp build/wasm_debug/$(TARGET_NAME).js $(DIST_DIR)/wasm_debug/ - @cp build/wasm_debug/$(TARGET_NAME).wasm $(DIST_DIR)/wasm_debug/ - @cp build/wasm_debug/$(TARGET_NAME).data $(DIST_DIR)/wasm_debug/ - @echo "Output: $(DIST_DIR)/wasm_debug/$(TARGET_NAME).html" + bash -c "emcmake cmake -S . -B build/wasm-debug -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) && cmake --build build/wasm-debug" + @$(MKDIR) "$(DIST_DIR)/wasm-debug" + @cp build/wasm-debug/$(TARGET_NAME).html $(DIST_DIR)/wasm-debug/ + @cp build/wasm-debug/$(TARGET_NAME).js $(DIST_DIR)/wasm-debug/ + @cp build/wasm-debug/$(TARGET_NAME).wasm $(DIST_DIR)/wasm-debug/ + @cp build/wasm-debug/$(TARGET_NAME).data $(DIST_DIR)/wasm-debug/ + @echo "Output: $(DIST_DIR)/wasm-debug/$(TARGET_NAME).html" # ============================================================================== # COMPILACIÓN PARA LINUX (RELEASE) # ============================================================================== -_linux_release: pack +_linux-release: pack @echo "Creando release para Linux - Version: $(VERSION)" # Compila con cmake @@ -383,7 +394,7 @@ _linux_release: pack $(MKDIR) "$(RELEASE_FOLDER)" # Copia ficheros (resources.pack substitueix la carpeta data/) - cp resources.pack "$(RELEASE_FOLDER)" + cp build/resources.pack "$(RELEASE_FOLDER)" cp LICENSE "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)" @@ -441,14 +452,18 @@ help: @echo " make - Compilar amb cmake (Release)" @echo " make debug - Compilar amb cmake (Debug)" @echo "" + @echo " Execucio:" + @echo " make run - Compilar (Release) i executar" + @echo " make run-debug - Compilar (Debug) i executar" + @echo "" @echo " Release:" @echo " make release - Crear release (detecta SO automaticament)" @echo " make wasm - Build WebAssembly (requereix Docker) + deploy a maverick" - @echo " make wasm_debug - Build WebAssembly Debug local (sense deploy)" + @echo " make wasm-debug - Build WebAssembly Debug local (sense deploy)" @echo "" @echo " Eines:" - @echo " make compile_shaders - Compilar shaders SPIR-V" - @echo " make pack - Empaquetar data/ a resources.pack (format AEE1)" + @echo " make compile-shaders - Compilar shaders SPIR-V" + @echo " make pack - Empaquetar data/ a $(BUILDDIR)/resources.pack (format AEE1)" @echo " make controllerdb - Actualitzar gamecontrollerdb.txt des de SDL_GameControllerDB" @echo "" @echo " Qualitat de codi:" @@ -459,8 +474,10 @@ help: @echo " make cppcheck - Anàlisi estàtic amb cppcheck" @echo "" @echo " Altres:" + @echo " make clean - Esborrar carpeta $(BUILDDIR)/" + @echo " make rebuild - clean + all" @echo " make help - Mostrar esta ajuda" @echo "" @echo " Versio actual: $(VERSION) ($(GIT_HASH))" -.PHONY: all debug pack release wasm wasm_debug _windows_release _linux_release _macos_release compile_shaders controllerdb format format-check tidy tidy-fix cppcheck help +.PHONY: all debug run run-debug clean rebuild pack release wasm wasm-debug _windows-release _linux-release _macos-release compile-shaders controllerdb format format-check tidy tidy-fix cppcheck help