From b53bf87730a8bd794632dffabc73776a83a61cda Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 2 Apr 2026 08:35:36 +0200 Subject: [PATCH] arreglos en makefile --- CMakeLists.txt | 12 ++- Makefile | 284 ++++++++++++++----------------------------------- 2 files changed, 90 insertions(+), 206 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b02b8cc..dcdd82e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,7 +225,17 @@ if(WIN32) elseif(APPLE) target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD) target_compile_options(${PROJECT_NAME} PRIVATE -Wno-deprecated) - set(CMAKE_OSX_ARCHITECTURES "arm64") + if(NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES "arm64") + endif() + if(MACOS_BUNDLE) + target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUNDLE) + target_link_options(${PROJECT_NAME} PRIVATE + -framework SDL3 + -F ${CMAKE_SOURCE_DIR}/release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64 + -rpath @executable_path/../Frameworks/ + ) + endif() elseif(UNIX AND NOT APPLE) target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD) endif() diff --git a/Makefile b/Makefile index 3ccca7e..5dfea33 100644 --- a/Makefile +++ b/Makefile @@ -18,24 +18,13 @@ RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME) RESOURCE_FILE := release/windows/jdd.res # ============================================================================== -# PACKING TOOL -# ============================================================================== -ifeq ($(OS),Windows_NT) - PACK_TOOL := $(DIR_TOOLS)pack_resources/pack_resources.exe - PACK_CXX := $(CXX) -else - PACK_TOOL := $(DIR_TOOLS)pack_resources/pack_resources - PACK_CXX := $(CXX) -endif -PACK_SOURCES := $(DIR_TOOLS)pack_resources/pack_resources.cpp source/core/resources/resource_pack.cpp -PACK_INCLUDES := -Isource - -# ============================================================================== -# SHADERS +# TOOLS # ============================================================================== +DIR_PACK_TOOL := $(DIR_TOOLS)pack_resources SHADER_SCRIPT := $(DIR_ROOT)tools/shaders/compile_spirv.sh -SHADER_VERT_H := $(DIR_ROOT)source/core/rendering/sdl3gpu/postfx_vert_spv.h -SHADER_FRAG_H := $(DIR_ROOT)source/core/rendering/sdl3gpu/postfx_frag_spv.h +SHADER_CMAKE := $(DIR_ROOT)tools/shaders/compile_spirv.cmake +SHADERS_DIR := $(DIR_ROOT)data/shaders +HEADERS_DIR := $(DIR_ROOT)source/core/rendering/sdl3gpu ifeq ($(OS),Windows_NT) GLSLC := $(shell where glslc 2>NUL) else @@ -79,190 +68,87 @@ MACOS_APPLE_SILICON_RELEASE := $(DIST_DIR)/$(TARGET_NAME)-$(VERSION)-macos-apple LINUX_RELEASE := $(DIST_DIR)/$(TARGET_NAME)-$(VERSION)-linux.tar.gz # ============================================================================== -# SOURCE FILES +# PLATAFORMA # ============================================================================== -APP_SOURCES := \ - source/main.cpp \ - source/core/audio/audio.cpp \ - source/core/input/global_inputs.cpp \ - source/core/input/input_types.cpp \ - source/core/input/input.cpp \ - source/core/input/mouse.cpp \ - source/core/locale/locale.cpp \ - source/core/rendering/gif.cpp \ - source/core/rendering/palette_manager.cpp \ - source/core/rendering/pixel_reveal.cpp \ - source/core/rendering/render_info.cpp \ - source/core/rendering/screen.cpp \ - source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp \ - source/core/rendering/sprite/animated_sprite.cpp \ - source/core/rendering/sprite/dissolve_sprite.cpp \ - source/core/rendering/sprite/moving_sprite.cpp \ - source/core/rendering/sprite/sprite.cpp \ - source/core/rendering/surface.cpp \ - source/core/rendering/text.cpp \ - source/core/resources/resource_cache.cpp \ - source/core/resources/resource_helper.cpp \ - source/core/resources/resource_list.cpp \ - source/core/resources/resource_loader.cpp \ - source/core/resources/resource_pack.cpp \ - source/core/system/debug.cpp \ - source/core/system/director.cpp \ - source/core/system/global_events.cpp \ - source/game/entities/enemy.cpp \ - source/game/entities/item.cpp \ - source/game/entities/player.cpp \ - source/game/gameplay/cheevos.cpp \ - source/game/gameplay/collision_map.cpp \ - source/game/gameplay/enemy_manager.cpp \ - source/game/gameplay/item_manager.cpp \ - source/game/gameplay/item_tracker.cpp \ - source/game/gameplay/room_loader.cpp \ - source/game/gameplay/room_tracker.cpp \ - source/game/gameplay/room.cpp \ - source/game/gameplay/scoreboard.cpp \ - source/game/gameplay/stats.cpp \ - source/game/gameplay/tilemap_renderer.cpp \ - source/game/options.cpp \ - source/game/scenes/credits.cpp \ - source/game/scenes/ending.cpp \ - source/game/scenes/ending2.cpp \ - source/game/scenes/game_over.cpp \ - source/game/scenes/game.cpp \ - source/game/scenes/loading_screen.cpp \ - source/game/scenes/logo.cpp \ - source/game/scenes/title.cpp \ - source/game/ui/console.cpp \ - source/game/ui/notifier.cpp \ - source/utils/delta_timer.cpp \ - source/utils/utils.cpp - -# All sources combined -ALL_SOURCES := $(APP_SOURCES) - -# ============================================================================== -# INCLUDES -# ============================================================================== -INCLUDES := -Isource - -# ============================================================================== -# COMPILER FLAGS (OS-specific) -# ============================================================================== -CPP_STANDARD := c++20 - ifeq ($(OS),Windows_NT) FixPath = $(subst /,\\,$1) - CXXFLAGS := -std=$(CPP_STANDARD) -Wall -Os -ffunction-sections -fdata-sections \ - -Wl,--gc-sections -static-libstdc++ -static-libgcc \ - -Wl,-subsystem,windows -DWINDOWS_BUILD - CXXFLAGS_DEBUG := -std=$(CPP_STANDARD) -Wall -g -D_DEBUG -DWINDOWS_BUILD - LDFLAGS := -lmingw32 -lws2_32 -lSDL3 RM := del /Q MKDIR := mkdir else FixPath = $1 - CXXFLAGS := -std=$(CPP_STANDARD) -Wall -Os -ffunction-sections -fdata-sections - CXXFLAGS_DEBUG := -std=$(CPP_STANDARD) -Wall -g -D_DEBUG - LDFLAGS := -lSDL3 RMFILE := rm -f RMDIR := rm -rdf MKDIR := mkdir -p UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - CXXFLAGS += -DLINUX_BUILD - endif - ifeq ($(UNAME_S),Darwin) - CXXFLAGS += -DMACOS_BUILD - CXXFLAGS_DEBUG += -DMACOS_BUILD - # Configurar arquitectura (por defecto arm64) - CXXFLAGS += -arch arm64 - CXXFLAGS_DEBUG += -arch arm64 - # Usar Apple Clang explícitamente para evitar LLVM de Homebrew - MACOS_CXX := /usr/bin/clang++ - endif endif # ============================================================================== -# REGLAS PARA COMPILACIÓN DE SHADERS +# COMPILACIÓN CON CMAKE +# ============================================================================== +all: + @cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + @cmake --build build + +debug: + @cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug + @cmake --build build + +# ============================================================================== +# RELEASE AUTOMÁTICO (detecta SO) +# ============================================================================== +release: +ifeq ($(OS),Windows_NT) + @"$(MAKE)" windows_release +else +ifeq ($(UNAME_S),Darwin) + @$(MAKE) macos_release +else + @$(MAKE) linux_release +endif +endif + +# ============================================================================== +# REGLAS PARA COMPILACIÓN DE SHADERS (multiplataforma via cmake) # ============================================================================== compile_shaders: ifdef GLSLC -ifeq ($(OS),Windows_NT) - @powershell -Command "if ((Test-Path '$(SHADER_VERT_H)') -and (Test-Path '$(SHADER_FRAG_H)')) { Write-Host 'Shaders SPIR-V precompilados OK' } else { Write-Host 'Compilando shaders SPIR-V...'; bash '$(SHADER_SCRIPT)'; Write-Host 'Shaders compilados' }" + @cmake -D GLSLC=$(GLSLC) -D SHADERS_DIR=$(SHADERS_DIR) -D HEADERS_DIR=$(HEADERS_DIR) -P $(SHADER_CMAKE) else - @echo "Compilando shaders SPIR-V..." - @$(SHADER_SCRIPT) - @echo "✓ Shaders compilados" -endif -else -ifeq ($(OS),Windows_NT) - @powershell -Command "if ((Test-Path '$(SHADER_VERT_H)') -and (Test-Path '$(SHADER_FRAG_H)')) { Write-Host 'glslc no encontrado - usando headers SPIR-V precompilados' } else { Write-Host 'ERROR: glslc no encontrado y headers SPIR-V no existen.'; Write-Host ' Instala glslc o ejecuta: tools/shaders/compile_spirv.sh'; exit 1 }" -else - @if [ -f "$(SHADER_VERT_H)" ] && [ -f "$(SHADER_FRAG_H)" ]; then \ - echo "⚠ glslc no encontrado - usando headers SPIR-V precompilados"; \ - else \ - echo "ERROR: glslc no encontrado y headers SPIR-V no existen."; \ - echo " Instala glslc: sudo apt install glslang-tools"; \ - echo " O ejecuta manualmente: tools/shaders/compile_spirv.sh"; \ - exit 1; \ - fi -endif + @echo "glslc no encontrado - asegurate de que los headers SPIR-V precompilados existen" endif # ============================================================================== # REGLAS PARA HERRAMIENTA DE EMPAQUETADO Y RESOURCES.PACK # ============================================================================== -$(PACK_TOOL): FORCE - @echo "Compilando herramienta de empaquetado..." - $(PACK_CXX) -std=$(CPP_STANDARD) -Wall -Os $(PACK_INCLUDES) $(PACK_SOURCES) -o $(PACK_TOOL) - @echo "✓ Herramienta de empaquetado lista: $(PACK_TOOL)" +pack_tool: + @$(MAKE) -C $(DIR_PACK_TOOL) -pack_tool: $(PACK_TOOL) - -resources.pack: $(PACK_TOOL) - @echo "Generando resources.pack desde directorio data/..." - $(PACK_TOOL) data resources.pack - @echo "✓ resources.pack generado exitosamente" +resources.pack: pack_tool + @$(MAKE) -C $(DIR_PACK_TOOL) pack # ============================================================================== -# COMPILACIÓN PARA WINDOWS +# COMPILACIÓN PARA WINDOWS (RELEASE) # ============================================================================== -windows: - @echo off - @echo Generando version.h... - @powershell -Command "$$GIT_HASH = (git rev-parse --short=7 HEAD 2>$$null); if (-not $$GIT_HASH) { $$GIT_HASH = 'unknown' }; (Get-Content source/version.h.in) -replace '@GIT_HASH@', $$GIT_HASH | Set-Content source/version.h" - @echo Compilando para Windows con nombre: "$(WIN_TARGET_FILE).exe" - windres release/windows/jdd.rc -O coff -o $(RESOURCE_FILE) - g++ $(ALL_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_TARGET_FILE).exe" - strip -s -R .comment -R .gnu.version "$(WIN_TARGET_FILE).exe" --strip-unneeded - windows_release: - @"$(MAKE)" compile_shaders - @"$(MAKE)" resources.pack @echo off @echo Creando release para Windows - Version: $(VERSION) -# Generate version.h from version.h.in - @echo "Generando version.h..." - @powershell -Command "$$GIT_HASH = (git rev-parse --short=7 HEAD 2>$$null); if (-not $$GIT_HASH) { $$GIT_HASH = 'unknown' }; (Get-Content source/version.h.in) -replace '@GIT_HASH@', $$GIT_HASH | Set-Content source/version.h" +# Compila con cmake (genera shaders, resources.pack y ejecutable) + @cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + @cmake --build build # Crea carpeta de distribución y carpeta temporal 'RELEASE_FOLDER' @powershell -Command "if (-not (Test-Path '$(DIST_DIR)')) {New-Item '$(DIST_DIR)' -ItemType Directory}" @powershell -Command "if (Test-Path '$(RELEASE_FOLDER)') {Remove-Item '$(RELEASE_FOLDER)' -Recurse -Force}" @powershell -Command "if (-not (Test-Path '$(RELEASE_FOLDER)')) {New-Item '$(RELEASE_FOLDER)' -ItemType Directory}" -# Copia el archivo 'resources.pack' +# Copia ficheros @powershell -Command "Copy-Item -Path 'resources.pack' -Destination '$(RELEASE_FOLDER)'" - -# Copia los ficheros que están en la raíz del proyecto @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)'" @powershell -Command "Copy-Item 'release\windows\dll\*.dll' -Destination '$(RELEASE_FOLDER)'" - -# Compila (con icono) - windres release/windows/jdd.rc -O coff -o $(RESOURCE_FILE) - g++ $(ALL_SOURCES) $(RESOURCE_FILE) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe" + @powershell -Command "Copy-Item -Path '$(TARGET_FILE)' -Destination '\"$(WIN_RELEASE_FILE).exe\"'" strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded # Crea el fichero .zip @@ -274,26 +160,17 @@ windows_release: @powershell -Command "if (Test-Path '$(RELEASE_FOLDER)') {Remove-Item '$(RELEASE_FOLDER)' -Recurse -Force}" # ============================================================================== -# COMPILACIÓN PARA MACOS +# COMPILACIÓN PARA MACOS (RELEASE) # ============================================================================== -macos: - @GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \ - sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h - @echo "Compilando para macOS: $(TARGET_NAME)" - $(MACOS_CXX) $(ALL_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)" - macos_release: - @$(MAKE) compile_shaders - @$(MAKE) resources.pack @echo "Creando release para macOS - Version: $(VERSION)" # Verificar e instalar create-dmg si es necesario @which create-dmg > /dev/null || (echo "Instalando create-dmg..." && brew install create-dmg) -# Generate version.h from version.h.in - @echo "Generando version.h..." - @GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \ - sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h +# Compila la versión para procesadores Intel con cmake (genera shaders y resources.pack) + @cmake -S . -B build-intel -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DMACOS_BUNDLE=ON + @cmake --build build-intel # Elimina datos de compilaciones anteriores $(RMDIR) "$(RELEASE_FOLDER)" @@ -322,8 +199,8 @@ macos_release: sed -i '' '/CFBundleShortVersionString<\/key>/{n;s|.*|'"$$RAW_VERSION"'|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist"; \ sed -i '' '/CFBundleVersion<\/key>/{n;s|.*|'"$$RAW_VERSION"'|;}' "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Info.plist" -# Compila la versión para procesadores Intel - $(MACOS_CXX) $(ALL_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD -std=$(CPP_STANDARD) -Wall -Os -framework SDL3 -F release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64 -ffunction-sections -fdata-sections -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.15 +# Copia el ejecutable Intel al bundle + cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" # Firma la aplicación codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app" @@ -345,8 +222,10 @@ macos_release: "$(RELEASE_FOLDER)" || true @echo "Release Intel creado: $(MACOS_INTEL_RELEASE)" -# Compila la versión para procesadores Apple Silicon - $(MACOS_CXX) $(ALL_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD -std=$(CPP_STANDARD) -Wall -Os -framework SDL3 -F release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64 -ffunction-sections -fdata-sections -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11 +# Compila la versión para procesadores Apple Silicon con cmake + @cmake -S . -B build-arm -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DMACOS_BUNDLE=ON + @cmake --build build-arm + cp "$(TARGET_FILE)" "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" # Firma la aplicación codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app" @@ -373,24 +252,14 @@ macos_release: $(RMFILE) "$(DIST_DIR)"/rw.* # ============================================================================== -# COMPILACIÓN PARA LINUX +# COMPILACIÓN PARA LINUX (RELEASE) # ============================================================================== -linux: - @GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \ - sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h - @echo "Compilando para Linux: $(TARGET_NAME)" - g++ $(ALL_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)" - strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded - linux_release: - @$(MAKE) compile_shaders - @$(MAKE) resources.pack @echo "Creando release para Linux - Version: $(VERSION)" -# Generate version.h from version.h.in - @echo "Generando version.h..." - @GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \ - sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h +# Compila con cmake (genera shaders, resources.pack y ejecutable) + @cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + @cmake --build build # Elimina carpeta temporal previa y la recrea (crea dist/ si no existe) $(RMDIR) "$(RELEASE_FOLDER)" @@ -401,9 +270,7 @@ linux_release: cp LICENSE "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)" - -# Compila - g++ $(ALL_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)" + cp "$(TARGET_FILE)" "$(RELEASE_FILE)" strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded # Empaqueta ficheros @@ -425,17 +292,24 @@ show_version: help: @echo "Makefile para JailDoctor's Dilemma" @echo "Comandos disponibles:" - @echo " windows - Compilar para Windows" - @echo " windows_release - Crear release completo para Windows" - @echo " linux - Compilar para Linux" - @echo " linux_release - Crear release completo para Linux" - @echo " macos - Compilar para macOS" - @echo " macos_release - Crear release completo para macOS" - @echo " pack_tool - Compilar herramienta de empaquetado" - @echo " resources.pack - Generar pack de recursos desde data/" - @echo " show_version - Mostrar version actual ($(VERSION))" - @echo " help - Mostrar esta ayuda" + @echo "" + @echo " Compilacion:" + @echo " make - Compilar con cmake (Release)" + @echo " make debug - Compilar con cmake (Debug)" + @echo "" + @echo " Release:" + @echo " make release - Crear release (detecta SO automaticamente)" + @echo " make windows_release - Crear release para Windows" + @echo " make linux_release - Crear release para Linux" + @echo " make macos_release - Crear release para macOS" + @echo "" + @echo " Herramientas:" + @echo " make compile_shaders - Compilar shaders SPIR-V" + @echo " make pack_tool - Compilar herramienta de empaquetado" + @echo " make resources.pack - Generar pack de recursos desde data/" + @echo "" + @echo " Otros:" + @echo " make show_version - Mostrar version actual ($(VERSION))" + @echo " make help - Mostrar esta ayuda" -FORCE: - -.PHONY: windows windows_release macos macos_release linux linux_release compile_shaders pack_tool resources.pack show_version help +.PHONY: all debug release windows_release macos_release linux_release compile_shaders pack_tool resources.pack show_version help