From 2804353ac3520742bcc04f6644b2965101de3768 Mon Sep 17 00:00:00 2001 From: Oleg Derevenetz Date: Sun, 8 Dec 2024 16:26:36 +0300 Subject: [PATCH] Use a separate directory for binaries when building using GNU Make (#9328) --- .github/workflows/make.yml | 53 +++--- .github/workflows/translation_update.yml | 2 +- Makefile | 42 ++--- Makefile.switch | 17 +- Makefile.vita | 33 ++-- docs/INSTALL.md | 7 +- docs/Makefile | 6 +- docs/TRANSLATION.md | 8 +- files/lang/Makefile | 2 +- src/Makefile | 176 ------------------ src/dist/Makefile | 164 +++++++++++++--- src/{ => dist}/Makefile.all | 2 +- src/{ => dist}/Makefile.bsd | 2 +- src/{ => dist}/Makefile.osx | 2 +- src/{ => dist}/Makefile.switch | 2 +- src/{ => dist}/Makefile.vita | 2 +- src/{ => dist}/engine/Makefile | 16 +- src/dist/fheroes2/Makefile | 54 ++++++ src/{ => dist}/thirdparty/libsmacker/Makefile | 13 +- src/{ => dist}/tools/Makefile | 21 ++- src/fheroes2/CMakeLists.txt | 9 +- 21 files changed, 313 insertions(+), 320 deletions(-) delete mode 100644 src/Makefile rename src/{ => dist}/Makefile.all (95%) rename src/{ => dist}/Makefile.bsd (95%) rename src/{ => dist}/Makefile.osx (96%) rename src/{ => dist}/Makefile.switch (96%) rename src/{ => dist}/Makefile.vita (97%) rename src/{ => dist}/engine/Makefile (85%) create mode 100644 src/dist/fheroes2/Makefile rename src/{ => dist}/thirdparty/libsmacker/Makefile (86%) rename src/{ => dist}/tools/Makefile (80%) diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 3db4330c271..287d504bf7f 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -34,14 +34,14 @@ jobs: LICENSE ./docs/GRAPHICAL_ASSETS.md ./script/agg/extract_agg.sh - ./src/tools/82m2wav - ./src/tools/bin2txt - ./src/tools/extractor - ./src/tools/h2dmgr - ./src/tools/icn2img - ./src/tools/pal2img - ./src/tools/til2img - ./src/tools/xmi2midi + ./src/dist/tools/82m2wav + ./src/dist/tools/bin2txt + ./src/dist/tools/extractor + ./src/dist/tools/h2dmgr + ./src/dist/tools/icn2img + ./src/dist/tools/pal2img + ./src/dist/tools/til2img + ./src/dist/tools/xmi2midi release_name: Ubuntu x86-64 (Linux) build with SDL2 (latest commit) release_tag: fheroes2-linux-sdl2_dev - name: Linux x86-64 SDL2 Debug @@ -79,14 +79,14 @@ jobs: LICENSE ./docs/GRAPHICAL_ASSETS.md ./script/agg/extract_agg.sh - ./src/tools/82m2wav - ./src/tools/bin2txt - ./src/tools/extractor - ./src/tools/h2dmgr - ./src/tools/icn2img - ./src/tools/pal2img - ./src/tools/til2img - ./src/tools/xmi2midi + ./src/dist/tools/82m2wav + ./src/dist/tools/bin2txt + ./src/dist/tools/extractor + ./src/dist/tools/h2dmgr + ./src/dist/tools/icn2img + ./src/dist/tools/pal2img + ./src/dist/tools/til2img + ./src/dist/tools/xmi2midi release_name: Ubuntu ARM64 (Linux) build with SDL2 (latest commit) release_tag: fheroes2-linux-arm-sdl2_dev - name: Linux ARM64 SDL2 Debug @@ -124,14 +124,14 @@ jobs: LICENSE ./docs/GRAPHICAL_ASSETS.md ./script/agg/extract_agg.sh - ./src/tools/82m2wav - ./src/tools/bin2txt - ./src/tools/extractor - ./src/tools/h2dmgr - ./src/tools/icn2img - ./src/tools/pal2img - ./src/tools/til2img - ./src/tools/xmi2midi + ./src/dist/tools/82m2wav + ./src/dist/tools/bin2txt + ./src/dist/tools/extractor + ./src/dist/tools/h2dmgr + ./src/dist/tools/icn2img + ./src/dist/tools/pal2img + ./src/dist/tools/til2img + ./src/dist/tools/xmi2midi release_name: macOS x86-64 build with SDL2 (latest commit) release_tag: fheroes2-osx-sdl2_dev - name: macOS SDL2 App Bundle @@ -175,11 +175,6 @@ jobs: run: | make -j 2 env: ${{ matrix.config.env }} - - name: Create app bundle - if: ${{ startsWith( matrix.config.os, 'macos-' ) }} - run: | - make -j 2 bundle - env: ${{ matrix.config.env }} - name: Create package if: ${{ matrix.config.package_name != '' && matrix.config.package_files != '' }} run: | diff --git a/.github/workflows/translation_update.yml b/.github/workflows/translation_update.yml index 7370bcb0229..95e871874e6 100644 --- a/.github/workflows/translation_update.yml +++ b/.github/workflows/translation_update.yml @@ -33,7 +33,7 @@ jobs: echo "PR_BRANCH=$PR_BRANCH" >> "$GITHUB_ENV" - name: Generate POT run: | - make -C src/dist -j 2 pot + make -C src/dist/fheroes2 -j 2 pot - name: Merge PO with POT run: | make -C files/lang -j 2 merge diff --git a/Makefile b/Makefile index 758e01ac208..5ea7e2f4372 100644 --- a/Makefile +++ b/Makefile @@ -30,34 +30,34 @@ # FHEROES2_MACOS_APP_BUNDLE: create a Mac app bundle (only valid when building on macOS) # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) -TARGET := fheroes2 +PROJECT_NAME := fheroes2 PROJECT_VERSION := $(file < version.txt) -.PHONY: all bundle clean +.PHONY: all clean all: - $(MAKE) -C src + $(MAKE) -C src/dist $(MAKE) -C files/lang -ifndef FHEROES2_MACOS_APP_BUNDLE - @cp src/dist/$(TARGET) . -endif - -bundle: ifdef FHEROES2_MACOS_APP_BUNDLE - @mkdir -p "src/dist/$(TARGET).app/Contents/Resources/translations" - @mkdir -p "src/dist/$(TARGET).app/Contents/Resources/h2d" - @mkdir -p "src/dist/$(TARGET).app/Contents/MacOS" - @cp ./src/resources/fheroes2.icns "src/dist/$(TARGET).app/Contents/Resources" - @cp ./files/lang/*.mo "src/dist/$(TARGET).app/Contents/Resources/translations" - @cp ./files/data/*.h2d "src/dist/$(TARGET).app/Contents/Resources/h2d" - @sed -e "s/\$${MACOSX_BUNDLE_EXECUTABLE_NAME}/$(TARGET)/" -e "s/\$${MACOSX_BUNDLE_ICON_FILE}/fheroes2.icns/" -e "s/\$${MACOSX_BUNDLE_GUI_IDENTIFIER}/com.fheroes2.$(TARGET)/" -e "s/\$${MACOSX_BUNDLE_BUNDLE_NAME}/$(TARGET)/" -e "s/\$${MACOSX_BUNDLE_BUNDLE_VERSION}/$(PROJECT_VERSION)/" -e "s/\$${MACOSX_BUNDLE_SHORT_VERSION_STRING}/$(PROJECT_VERSION)/" ./src/resources/Info.plist.in > "src/dist/$(TARGET).app/Contents/Info.plist" - @mv "src/dist/$(TARGET)" "src/dist/$(TARGET).app/Contents/MacOS" - @dylibbundler -od -b -x "src/dist/$(TARGET).app/Contents/MacOS/$(TARGET)" -d "src/dist/$(TARGET).app/Contents/libs" - @cp -R "src/dist/$(TARGET).app" . + mkdir -p fheroes2.app/Contents/Resources/translations + mkdir -p fheroes2.app/Contents/Resources/h2d + mkdir -p fheroes2.app/Contents/MacOS + cp src/resources/fheroes2.icns fheroes2.app/Contents/Resources + cp files/lang/*.mo fheroes2.app/Contents/Resources/translations + cp files/data/*.h2d fheroes2.app/Contents/Resources/h2d + sed -e "s/\$${MACOSX_BUNDLE_BUNDLE_NAME}/$(PROJECT_NAME)/" \ + -e "s/\$${MACOSX_BUNDLE_BUNDLE_VERSION}/$(PROJECT_VERSION)/" \ + -e "s/\$${MACOSX_BUNDLE_EXECUTABLE_NAME}/fheroes2/" \ + -e "s/\$${MACOSX_BUNDLE_GUI_IDENTIFIER}/org.fheroes2.$(PROJECT_NAME)/" \ + -e "s/\$${MACOSX_BUNDLE_ICON_FILE}/fheroes2.icns/" \ + -e "s/\$${MACOSX_BUNDLE_SHORT_VERSION_STRING}/$(PROJECT_VERSION)/" src/resources/Info.plist.in > fheroes2.app/Contents/Info.plist + cp src/dist/fheroes2/fheroes2 fheroes2.app/Contents/MacOS + dylibbundler -od -b -x fheroes2.app/Contents/MacOS/fheroes2 -d fheroes2.app/Contents/libs +else + cp src/dist/fheroes2/fheroes2 . endif clean: - $(MAKE) -C src clean + $(MAKE) -C src/dist clean $(MAKE) -C files/lang clean - @rm -f ./$(TARGET) - @rm -rf ./$(TARGET).app + rm -rf fheroes2 fheroes2.app diff --git a/Makefile.switch b/Makefile.switch index 1dcf96ca34e..86293484ddf 100644 --- a/Makefile.switch +++ b/Makefile.switch @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2023 # +# Copyright (C) 2021 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -24,9 +24,6 @@ # FHEROES2_WITH_DEBUG: build in debug mode # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) -TARGET := fheroes2 -MAKE := make - PROJECT_TITLE := fheroes2 PROJECT_AUTHOR := fheroes2 resurrection team PROJECT_VERSION := $(file < version.txt) @@ -36,11 +33,11 @@ PATH := $(PATH):/opt/devkitpro/portlibs/switch/bin/:/opt/devkitpro/tools/bin/ .PHONY: all clean all: - $(MAKE) -f Makefile -C src PLATFORM=switch - @cp src/dist/$(TARGET) $(TARGET).elf - nacptool --create "$(PROJECT_TITLE)" "$(PROJECT_AUTHOR)" "$(PROJECT_VERSION)" $(TARGET).nacp - elf2nro $(TARGET).elf $(TARGET).nro --icon=files/images/platform/switch/icon.jpg --nacp=$(TARGET).nacp + $(MAKE) -C src/dist PLATFORM=switch + cp src/dist/fheroes2/fheroes2 fheroes2.elf + nacptool --create "$(PROJECT_TITLE)" "$(PROJECT_AUTHOR)" "$(PROJECT_VERSION)" fheroes2.nacp + elf2nro fheroes2.elf fheroes2.nro --icon=files/images/platform/switch/icon.jpg --nacp=fheroes2.nacp clean: - $(MAKE) -f Makefile -C src clean - @rm -rf $(TARGET).elf $(TARGET).nacp $(TARGET).nro + $(MAKE) -C src/dist clean + rm -f fheroes2.elf fheroes2.nacp fheroes2.nro diff --git a/Makefile.vita b/Makefile.vita index 6b2be96c063..18a547c6b23 100644 --- a/Makefile.vita +++ b/Makefile.vita @@ -24,20 +24,15 @@ # FHEROES2_WITH_DEBUG: build in debug mode # FHEROES2_DATA: set the built-in path to the fheroes2 data directory (e.g. /usr/share/fheroes2) -TARGET := fheroes2 -MAKE := make - PROJECT_TITLE := fheroes2 PROJECT_TITLEID := FHOMM0002 PROJECT_VERSION := $(file < version.txt) -.PHONY: all clean $(TARGET).vpk param.sfo $(TARGET).elf translations - -all: package +.PHONY: all clean fheroes2.vpk param.sfo fheroes2.elf translations -package: $(TARGET).vpk +all: fheroes2.vpk -$(TARGET).vpk: eboot.bin param.sfo translations +fheroes2.vpk: eboot.bin param.sfo translations vita-pack-vpk -s param.sfo -b eboot.bin \ --add files/images/platform/psv/sce_sys/icon0.png=sce_sys/icon0.png \ --add files/images/platform/psv/sce_sys/livearea/contents/bg.png=sce_sys/livearea/contents/bg.png \ @@ -45,29 +40,29 @@ $(TARGET).vpk: eboot.bin param.sfo translations --add files/images/platform/psv/sce_sys/livearea/contents/template.xml=sce_sys/livearea/contents/template.xml \ --add files/data=files/data \ --add files/lang/vita_temp=files/lang \ - $(TARGET).vpk - @rm -r files/lang/vita_temp + fheroes2.vpk + rm -r files/lang/vita_temp -translations: $(TARGET).elf +translations: fheroes2.elf $(MAKE) -C files/lang mkdir -p files/lang/vita_temp cp files/lang/*.mo files/lang/vita_temp -eboot.bin: $(TARGET).velf - vita-make-fself $(TARGET).velf eboot.bin +eboot.bin: fheroes2.velf + vita-make-fself fheroes2.velf eboot.bin param.sfo: vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" -s APP_VER="$(PROJECT_VERSION)" "$(PROJECT_TITLE)" param.sfo -$(TARGET).velf: $(TARGET).elf +fheroes2.velf: fheroes2.elf arm-vita-eabi-strip -g $< vita-elf-create $< $@ -$(TARGET).elf: - $(MAKE) -f Makefile -C src PLATFORM=vita - @cp src/dist/$(TARGET) $(TARGET).elf +fheroes2.elf: + $(MAKE) -C src/dist PLATFORM=vita + cp src/dist/fheroes2/fheroes2 fheroes2.elf clean: - $(MAKE) -f Makefile -C src clean + $(MAKE) -C src/dist clean $(MAKE) -C files/lang clean - @rm -rf $(TARGET).velf $(TARGET).elf $(TARGET).vpk eboot.bin param.sfo + rm -f fheroes2.velf fheroes2.elf fheroes2.vpk eboot.bin param.sfo diff --git a/docs/INSTALL.md b/docs/INSTALL.md index a53c18eb2d4..537a59ff063 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -126,11 +126,10 @@ Follow the [**instructions below**](#macos-resources) to gather resources necess ### macOS native app -* Download the source and compile with the `-DMACOS_APP_BUNDLE=ON` option (if using CMake) or using the following commands (with make): +* Download the source and compile with the `-DMACOS_APP_BUNDLE=ON` option (if using CMake) or using the following command (with make): ```sh make FHEROES2_MACOS_APP_BUNDLE=ON -make FHEROES2_MACOS_APP_BUNDLE=ON bundle ``` Follow the [**instructions below**](#macos-resources) to gather resources necessary for fheroes2 to function as expected. @@ -159,8 +158,8 @@ Once you obtain the fheroes2 executable using any of the options above, you shou * If you don't have a legally purchased copy of the original game, you can download and install the demo version of the original game by running the download demo script. The script can be run from the following paths depending on how you installed fheroes2: * `fheroes2-install-demo` if you used a package manager (MacPorts or Homebrew); - * `script/homm2/download_demo_version_for_app_bundles.sh` if you built from source using the [**macOS native app**](#macos-native-app) method; - * `script/homm2/download_demo_version.sh` for all other cases. + * `script/demo/download_demo_version_for_app_bundle.sh` if you built from source using the [**macOS native app**](#macos-native-app) method; + * `script/demo/download_demo_version.sh` for all other cases. ## Linux diff --git a/docs/Makefile b/docs/Makefile index f758764e5ac..18761f24d8c 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -37,7 +37,7 @@ endif .PHONY: all clean all: - @sed -e '$(SEDEX)' fheroes2.6.in > fheroes2.6 + sed -e '$(SEDEX)' fheroes2.6.in > fheroes2.6 clean: - @rm -f fheroes2.6 + rm -f fheroes2.6 diff --git a/docs/TRANSLATION.md b/docs/TRANSLATION.md index c6b98639f7f..d802e14e147 100644 --- a/docs/TRANSLATION.md +++ b/docs/TRANSLATION.md @@ -144,10 +144,10 @@ example creature names or castle buildings. ## Updating PO templates and translatable strings in PO files -Currently all PO files are automatically updated with new strings after each commit that brings changes to the ingame text. If for whatever -reason you still need to update strings locally, this can be achieved by running the command below in `src/dist` to generate a new portable -object template (POT) file. Windows users will need to set up an environment that lets them run `make`, like Windows Subsystem for Linux (WSL) -or [**Cygwin**](https://www.cygwin.com/)/[**MSYS2**](https://www.msys2.org/). +Currently all PO files are automatically updated with new strings after each commit that brings changes to the ingame text. If for whatever reason +you still need to update strings locally, this can be achieved by running the command below in `src/dist/fheroes2` to generate a new portable object +template (POT) file. Windows users will need to set up an environment that lets them run `make`, like Windows Subsystem for Linux (WSL) or +[**Cygwin**](https://www.cygwin.com/)/[**MSYS2**](https://www.msys2.org/). ```bash make pot diff --git a/files/lang/Makefile b/files/lang/Makefile index af73ba3e4ac..6c731317eef 100644 --- a/files/lang/Makefile +++ b/files/lang/Makefile @@ -26,7 +26,7 @@ MSGFMT = sed -e '1,20 s/UTF-8/$(1)/' $< | $(ICONV) -f utf-8 -t $(1) | if msgfmt all: $(patsubst %.po, %.mo, $(wildcard *.po)) -merge: ../../src/dist/fheroes2.pot +merge: ../../src/dist/fheroes2/fheroes2.pot for i in $(wildcard *.po); do msgmerge -U --no-location $$i $<; done # Czech, Hungarian, Polish and Slovak versions use CP1250 diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 97f7b38d1a9..00000000000 --- a/src/Makefile +++ /dev/null @@ -1,176 +0,0 @@ -########################################################################### -# fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2024 # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program; if not, write to the # -# Free Software Foundation, Inc., # -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -########################################################################### - -TARGET := fheroes2 - -# -# Common build options for fheroes2 and third-party libraries -# - -# Common flags for both C and C++ compilers -CCFLAGS := -fsigned-char -pthread -# Flags for the C compiler -CFLAGS := $(CFLAGS) -# Flags for the C++ compiler -CXXFLAGS := $(CXXFLAGS) -# Flags for the preprocessor -CPPFLAGS := $(CPPFLAGS) -# Flags for the linker -LDFLAGS := $(LDFLAGS) -pthread -# Flags for additional libraries -LDLIBS := $(LDLIBS) - -ifdef FHEROES2_WITH_DEBUG -CCFLAGS := $(CCFLAGS) -O0 -g -else -CCFLAGS := $(CCFLAGS) -O3 -endif - -ifneq ($(or $(FHEROES2_WITH_ASAN),$(FHEROES2_WITH_TSAN)),) -SANITIZERS := undefined - -ifdef FHEROES2_WITH_ASAN -SANITIZERS := $(SANITIZERS),address -endif -ifdef FHEROES2_WITH_TSAN -SANITIZERS := $(SANITIZERS),thread -endif - -CCFLAGS := $(CCFLAGS) -fsanitize=$(SANITIZERS) -LDFLAGS := $(LDFLAGS) -fsanitize=$(SANITIZERS) -endif - -# -# Platform-specific build options -# - -ifndef PLATFORM -ifndef OS -OS := $(shell uname) -endif - -ifeq ($(OS),FreeBSD) -PLATFORM := bsd -endif -ifeq ($(OS),Darwin) -PLATFORM := osx -endif -ifeq ($(OS),Linux) -PLATFORM := all -endif -ifeq ($(OS),Haiku) -PLATFORM := all -endif -endif - -include Makefile.$(PLATFORM) - -# -# Build options for third-party libraries -# - -CCFLAGS_TP := $(CCFLAGS) -CFLAGS_TP := $(CFLAGS) -CXXFLAGS_TP := $(CXXFLAGS) -CPPFLAGS_TP := $(CPPFLAGS) - -# -# Build options for fheroes2 -# - -# *FLAGS_FH2 can be passed from platform-specific Makefiles -CCFLAGS := $(CCFLAGS) $(CCFLAGS_FH2) -CFLAGS := $(CFLAGS) $(CFLAGS_FH2) -CXXFLAGS := $(CXXFLAGS) $(CXXFLAGS_FH2) -std=c++17 -CPPFLAGS := $(CPPFLAGS) $(CPPFLAGS_FH2) - -ifdef FHEROES2_WITH_SYSTEM_SMACKER -LIBS := $(LIBS) -lsmacker -endif -LIBS := $(LIBS) -lz $(LDLIBS) - -ifdef FHEROES2_WITH_DEBUG -CCFLAGS := $(CCFLAGS) -DWITH_DEBUG -endif -ifdef FHEROES2_WITH_IMAGE -CCFLAGS := $(CCFLAGS) -DWITH_IMAGE -endif -ifdef FHEROES2_DATA -CCFLAGS := $(CCFLAGS) -DFHEROES2_DATA="$(FHEROES2_DATA)" -endif - -# TODO: Add -Wconversion -Wsign-conversion flags once we fix all the corresponding code smells -CCWARNOPTS := -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wdouble-promotion -Wfloat-conversion -Wfloat-equal \ - -Wredundant-decls -Wshadow -Wswitch-default -Wundef -Wunused -CFLAGS := $(CFLAGS) $(CCWARNOPTS) -CXXFLAGS := $(CXXFLAGS) $(CCWARNOPTS) -Wctor-dtor-privacy -Wextra-semi -Wmissing-declarations -Wold-style-cast \ - -Woverloaded-virtual -Wsuggest-override - -ifdef FHEROES2_STRICT_COMPILATION -CCFLAGS := $(CCFLAGS) -Werror -endif - -# -# SDL-related build options -# - -# SDL_FLAGS can already be defined in a platform-specific Makefile -ifeq ($(origin SDL_FLAGS),undefined) -SDL_FLAGS := $(shell sdl2-config --cflags) - -ifdef FHEROES2_WITH_IMAGE -SDL_FLAGS := $(SDL_FLAGS) $(shell libpng-config --cflags) -endif -endif - -# SDL_LIBS can already be defined in a platform-specific Makefile -ifeq ($(origin SDL_LIBS),undefined) -SDL_LIBS := -lSDL2_mixer $(shell sdl2-config --libs) - -ifdef FHEROES2_WITH_IMAGE -SDL_LIBS := $(SDL_LIBS) -lSDL2_image $(shell libpng-config --libs) -endif -endif - -CCFLAGS := $(CCFLAGS) $(SDL_FLAGS) -LIBS := $(SDL_LIBS) $(LIBS) - -export CC CXX AR CCFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LIBS PLATFORM - -.PHONY: all clean - -all: -ifndef FHEROES2_WITH_SYSTEM_SMACKER - $(MAKE) -C thirdparty/libsmacker CCFLAGS="$(CCFLAGS_TP)" CFLAGS="$(CFLAGS_TP)" CXXFLAGS="$(CXXFLAGS_TP)" CPPFLAGS="$(CPPFLAGS_TP)" -endif - $(MAKE) -C engine - $(MAKE) -C dist -ifdef FHEROES2_WITH_TOOLS - $(MAKE) -C tools -endif - $(MAKE) -C dist pot - -clean: -ifndef FHEROES2_WITH_SYSTEM_SMACKER - $(MAKE) -C thirdparty/libsmacker clean -endif - $(MAKE) -C tools clean - $(MAKE) -C dist clean - $(MAKE) -C engine clean diff --git a/src/dist/Makefile b/src/dist/Makefile index 7405f9f8f19..4e1c76db630 100644 --- a/src/dist/Makefile +++ b/src/dist/Makefile @@ -18,42 +18,156 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ########################################################################### -TARGET := fheroes2 +# +# Common build options for fheroes2 and third-party libraries +# -LIBENGINE := ../engine/libengine.a -CCFLAGS := $(CCFLAGS) -I../engine +# Common flags for both C and C++ compilers +CCFLAGS := -fsigned-char -pthread +# Flags for the C compiler +CFLAGS := $(CFLAGS) +# Flags for the C++ compiler +CXXFLAGS := $(CXXFLAGS) +# Flags for the preprocessor +CPPFLAGS := $(CPPFLAGS) +# Flags for the linker +LDFLAGS := $(LDFLAGS) -pthread +# Flags for additional libraries +LDLIBS := $(LDLIBS) -ifndef FHEROES2_WITH_SYSTEM_SMACKER -LIBENGINE := $(LIBENGINE) ../thirdparty/libsmacker/libsmacker.a -CCFLAGS := $(CCFLAGS) -I../thirdparty/libsmacker +ifdef FHEROES2_WITH_DEBUG +CCFLAGS := $(CCFLAGS) -O0 -g +else +CCFLAGS := $(CCFLAGS) -O3 +endif + +ifneq ($(or $(FHEROES2_WITH_ASAN),$(FHEROES2_WITH_TSAN)),) +SANITIZERS := undefined + +ifdef FHEROES2_WITH_ASAN +SANITIZERS := $(SANITIZERS),address +endif +ifdef FHEROES2_WITH_TSAN +SANITIZERS := $(SANITIZERS),thread +endif + +CCFLAGS := $(CCFLAGS) -fsanitize=$(SANITIZERS) +LDFLAGS := $(LDFLAGS) -fsanitize=$(SANITIZERS) +endif + +# +# Platform-specific build options +# + +ifndef PLATFORM +ifndef OS +OS := $(shell uname) endif -SOURCEROOT := ../fheroes2 -SOURCEDIR := $(filter %/,$(wildcard $(SOURCEROOT)/*/)) -POT := $(TARGET).pot +ifeq ($(OS),FreeBSD) +PLATFORM := bsd +endif +ifeq ($(OS),Darwin) +PLATFORM := osx +endif +ifeq ($(OS),Linux) +PLATFORM := all +endif +ifeq ($(OS),Haiku) +PLATFORM := all +endif +endif -SEARCH := $(wildcard $(SOURCEROOT)/*/*.cpp) +include Makefile.$(PLATFORM) -.PHONY: all clean pot +# +# Build options for third-party libraries +# -all: $(TARGET) +CCFLAGS_TP := $(CCFLAGS) +CFLAGS_TP := $(CFLAGS) +CXXFLAGS_TP := $(CXXFLAGS) +CPPFLAGS_TP := $(CPPFLAGS) -$(TARGET): $(notdir $(patsubst %.cpp, %.o, $(SEARCH))) $(LIBENGINE) - @echo "lnk: $@" - $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS) +# +# Build options for fheroes2 +# -pot: $(wildcard $(SEARCH)) - @echo "gen: $(POT)" - @xgettext -d $(TARGET) -C -F -k_ -k_n:1,2 -o $(POT) $(sort $(wildcard $(SEARCH))) - @sed -i~ -e 's/, c-format//' $(POT) +# *FLAGS_FH2 can be passed from platform-specific Makefiles +CCFLAGS := $(CCFLAGS) $(CCFLAGS_FH2) +CFLAGS := $(CFLAGS) $(CFLAGS_FH2) +CXXFLAGS := $(CXXFLAGS) $(CXXFLAGS_FH2) -std=c++17 +CPPFLAGS := $(CPPFLAGS) $(CPPFLAGS_FH2) -VPATH := $(SOURCEDIR) +ifdef FHEROES2_WITH_SYSTEM_SMACKER +LIBS := $(LIBS) -lsmacker +endif +LIBS := $(LIBS) -lz $(LDLIBS) -%.o: %.cpp - $(CXX) -c -MD $(addprefix -I, $(SOURCEDIR)) $< $(CCFLAGS) $(CXXFLAGS) $(CPPFLAGS) +ifdef FHEROES2_WITH_DEBUG +CCFLAGS := $(CCFLAGS) -DWITH_DEBUG +endif +ifdef FHEROES2_WITH_IMAGE +CCFLAGS := $(CCFLAGS) -DWITH_IMAGE +endif +ifdef FHEROES2_DATA +CCFLAGS := $(CCFLAGS) -DFHEROES2_DATA="$(FHEROES2_DATA)" +endif -include $(wildcard *.d) +# TODO: Add -Wconversion -Wsign-conversion flags once we fix all the corresponding code smells +CCWARNOPTS := -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wdouble-promotion -Wfloat-conversion -Wfloat-equal \ + -Wredundant-decls -Wshadow -Wswitch-default -Wundef -Wunused +CFLAGS := $(CFLAGS) $(CCWARNOPTS) +CXXFLAGS := $(CXXFLAGS) $(CCWARNOPTS) -Wctor-dtor-privacy -Wextra-semi -Wmissing-declarations -Wold-style-cast \ + -Woverloaded-virtual -Wsuggest-override + +ifdef FHEROES2_STRICT_COMPILATION +CCFLAGS := $(CCFLAGS) -Werror +endif + +# +# SDL-related build options +# + +# SDL_FLAGS can already be defined in a platform-specific Makefile +ifeq ($(origin SDL_FLAGS),undefined) +SDL_FLAGS := $(shell sdl2-config --cflags) + +ifdef FHEROES2_WITH_IMAGE +SDL_FLAGS := $(SDL_FLAGS) $(shell libpng-config --cflags) +endif +endif + +# SDL_LIBS can already be defined in a platform-specific Makefile +ifeq ($(origin SDL_LIBS),undefined) +SDL_LIBS := -lSDL2_mixer $(shell sdl2-config --libs) + +ifdef FHEROES2_WITH_IMAGE +SDL_LIBS := $(SDL_LIBS) -lSDL2_image $(shell libpng-config --libs) +endif +endif + +CCFLAGS := $(CCFLAGS) $(SDL_FLAGS) +LIBS := $(SDL_LIBS) $(LIBS) + +export CC CXX AR CCFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LIBS PLATFORM + +.PHONY: all clean + +all: +ifndef FHEROES2_WITH_SYSTEM_SMACKER + $(MAKE) -C thirdparty/libsmacker CCFLAGS="$(CCFLAGS_TP)" CFLAGS="$(CFLAGS_TP)" CXXFLAGS="$(CXXFLAGS_TP)" CPPFLAGS="$(CPPFLAGS_TP)" +endif + $(MAKE) -C engine + $(MAKE) -C fheroes2 +ifdef FHEROES2_WITH_TOOLS + $(MAKE) -C tools +endif clean: - rm -f *.pot *.pot~ *.o *.d *.exe $(TARGET) - rm -rf *.app +ifndef FHEROES2_WITH_SYSTEM_SMACKER + $(MAKE) -C thirdparty/libsmacker clean +endif + $(MAKE) -C engine clean + $(MAKE) -C fheroes2 clean + $(MAKE) -C tools clean diff --git a/src/Makefile.all b/src/dist/Makefile.all similarity index 95% rename from src/Makefile.all rename to src/dist/Makefile.all index 1d979d8c982..9dcb8b7a3f8 100644 --- a/src/Makefile.all +++ b/src/dist/Makefile.all @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # diff --git a/src/Makefile.bsd b/src/dist/Makefile.bsd similarity index 95% rename from src/Makefile.bsd rename to src/dist/Makefile.bsd index d7dcdf64690..f213320b502 100644 --- a/src/Makefile.bsd +++ b/src/dist/Makefile.bsd @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # diff --git a/src/Makefile.osx b/src/dist/Makefile.osx similarity index 96% rename from src/Makefile.osx rename to src/dist/Makefile.osx index af7f67659c5..3c0a472cb4b 100644 --- a/src/Makefile.osx +++ b/src/dist/Makefile.osx @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # diff --git a/src/Makefile.switch b/src/dist/Makefile.switch similarity index 96% rename from src/Makefile.switch rename to src/dist/Makefile.switch index 97cad378f3e..5475a5f3c25 100644 --- a/src/Makefile.switch +++ b/src/dist/Makefile.switch @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 - 2023 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # diff --git a/src/Makefile.vita b/src/dist/Makefile.vita similarity index 97% rename from src/Makefile.vita rename to src/dist/Makefile.vita index 71dd617ed42..dd8d9701f31 100644 --- a/src/Makefile.vita +++ b/src/dist/Makefile.vita @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2023 # +# Copyright (C) 2021 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # diff --git a/src/engine/Makefile b/src/dist/engine/Makefile similarity index 85% rename from src/engine/Makefile rename to src/dist/engine/Makefile index 5bd08e2c565..2914164f2ba 100644 --- a/src/engine/Makefile +++ b/src/dist/engine/Makefile @@ -18,23 +18,27 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ########################################################################### -TARGET := libengine - ifndef FHEROES2_WITH_SYSTEM_SMACKER -CCFLAGS := $(CCFLAGS) -I../thirdparty/libsmacker +CCFLAGS := $(CCFLAGS) -I../../thirdparty/libsmacker endif +SOURCEROOT := ../../engine +SOURCEDIRS := $(SOURCEROOT) +SOURCES := $(wildcard $(SOURCEDIRS)/*.cpp) + .PHONY: all clean -all: $(TARGET).a +all: libengine.a -$(TARGET).a: $(patsubst %.cpp, %.o, $(wildcard *.cpp)) +libengine.a: $(notdir $(patsubst %.cpp, %.o, $(SOURCES))) $(AR) crvs $@ $^ +VPATH := $(SOURCEDIRS) + %.o: %.cpp $(CXX) -c -MD $< $(CCFLAGS) $(CXXFLAGS) $(CPPFLAGS) include $(wildcard *.d) clean: - rm -f *.a *.so *.d *.o + rm -f *.d *.o libengine.a diff --git a/src/dist/fheroes2/Makefile b/src/dist/fheroes2/Makefile new file mode 100644 index 00000000000..19082a83023 --- /dev/null +++ b/src/dist/fheroes2/Makefile @@ -0,0 +1,54 @@ +########################################################################### +# fheroes2: https://github.com/ihhub/fheroes2 # +# Copyright (C) 2021 - 2024 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +########################################################################### + +LIBENGINE := ../engine/libengine.a +CCFLAGS := $(CCFLAGS) -I../../engine + +ifndef FHEROES2_WITH_SYSTEM_SMACKER +LIBENGINE := $(LIBENGINE) ../thirdparty/libsmacker/libsmacker.a +CCFLAGS := $(CCFLAGS) -I../../thirdparty/libsmacker +endif + +SOURCEROOT := ../../fheroes2 +SOURCEDIRS := $(filter %/,$(wildcard $(SOURCEROOT)/*/)) +SOURCES := $(wildcard $(SOURCEROOT)/*/*.cpp) + +.PHONY: all pot clean + +all: fheroes2 pot + +pot: fheroes2.pot + +fheroes2: $(notdir $(patsubst %.cpp, %.o, $(SOURCES))) $(LIBENGINE) + $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS) + +fheroes2.pot: $(SOURCES) + xgettext -d fheroes2 -C -F -k_ -k_n:1,2 -o fheroes2.pot $(sort $(SOURCES)) + sed -i~ -e 's/, c-format//' fheroes2.pot + +VPATH := $(SOURCEDIRS) + +%.o: %.cpp + $(CXX) -c -MD $(addprefix -I, $(SOURCEDIRS)) $< $(CCFLAGS) $(CXXFLAGS) $(CPPFLAGS) + +include $(wildcard *.d) + +clean: + rm -f *.d *.o fheroes2 fheroes2.pot fheroes2.pot~ diff --git a/src/thirdparty/libsmacker/Makefile b/src/dist/thirdparty/libsmacker/Makefile similarity index 86% rename from src/thirdparty/libsmacker/Makefile rename to src/dist/thirdparty/libsmacker/Makefile index 39b517543ab..3a5786b254f 100644 --- a/src/thirdparty/libsmacker/Makefile +++ b/src/dist/thirdparty/libsmacker/Makefile @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2022 # +# Copyright (C) 2022 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -18,19 +18,22 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ########################################################################### -TARGET := libsmacker +SOURCEROOT := ../../../thirdparty/libsmacker +SOURCEDIRS := $(SOURCEROOT) .PHONY: all clean -all: $(TARGET).a +all: libsmacker.a -$(TARGET).a: smacker.o +libsmacker.a: smacker.o $(AR) crvs $@ $^ +VPATH := $(SOURCEDIRS) + smacker.o: smacker.c $(CC) -c -MD $< $(CCFLAGS) $(CFLAGS) $(CPPFLAGS) include $(wildcard *.d) clean: - rm -f *.a *.so *.d *.o + rm -f *.d *.o libsmacker.a diff --git a/src/tools/Makefile b/src/dist/tools/Makefile similarity index 80% rename from src/tools/Makefile rename to src/dist/tools/Makefile index 8fb05bdc18f..403aced02c5 100644 --- a/src/tools/Makefile +++ b/src/dist/tools/Makefile @@ -1,6 +1,6 @@ ########################################################################### # fheroes2: https://github.com/ihhub/fheroes2 # -# Copyright (C) 2021 - 2023 # +# Copyright (C) 2021 - 2024 # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -21,15 +21,24 @@ TARGETS := 82m2wav bin2txt extractor h2dmgr icn2img pal2img til2img xmi2midi LIBENGINE := ../engine/libengine.a -CCFLAGS := $(CCFLAGS) -I../engine +CCFLAGS := $(CCFLAGS) -I../../engine + +SOURCEROOT := ../../tools +SOURCEDIRS := $(SOURCEROOT) .PHONY: all clean all: $(TARGETS) -$(TARGETS): $(addsuffix .cpp, $(TARGETS)) $(LIBENGINE) - $(CXX) $(CCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c $@.cpp - $(CXX) -o $@ $@.o $(LIBENGINE) $(LIBS) $(LDFLAGS) +$(TARGETS): %: %.o $(LIBENGINE) + $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS) + +VPATH := $(SOURCEDIRS) + +%.o: %.cpp + $(CXX) -c -MD $< $(CCFLAGS) $(CXXFLAGS) $(CPPFLAGS) + +include $(wildcard *.d) clean: - rm -f *.o *.exe $(TARGETS) + rm -f *.d *.o $(TARGETS) diff --git a/src/fheroes2/CMakeLists.txt b/src/fheroes2/CMakeLists.txt index 9792475ab73..91a04b6e094 100644 --- a/src/fheroes2/CMakeLists.txt +++ b/src/fheroes2/CMakeLists.txt @@ -45,13 +45,12 @@ if(MACOS_APP_BUNDLE) target_link_libraries(fheroes2 "-framework CoreFoundation") set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME ${CMAKE_PROJECT_NAME}) - set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_EXECUTABLE_NAME ${CMAKE_PROJECT_NAME}) - set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/../resources/Info.plist.in) + set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION ${CMAKE_PROJECT_VERSION}) + set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_EXECUTABLE_NAME fheroes2) + set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER org.fheroes2.${CMAKE_PROJECT_NAME}) set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_ICON_FILE fheroes2.icns) - set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER com.fheroes2.${CMAKE_PROJECT_NAME}) + set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/../resources/Info.plist.in) set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_SHORT_VERSION_STRING ${CMAKE_PROJECT_VERSION}) - set_target_properties(fheroes2 PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION ${CMAKE_PROJECT_VERSION}) - set_target_properties(fheroes2 PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME}) else(MACOS_APP_BUNDLE) cmake_path( ABSOLUTE_PATH FHEROES2_DATA