Debian Codegraph @

src/dist/Makefile

raw symbols SCIP
1 ###########################################################################
2 # fheroes2: https://github.com/ihhub/fheroes2 #
3 # Copyright (C) 2021 - 2025 #
4 # #
5 # This program is free software; you can redistribute it and/or modify #
6 # it under the terms of the GNU General Public License as published by #
7 # the Free Software Foundation; either version 2 of the License, or #
8 # (at your option) any later version. #
9 # #
10 # This program is distributed in the hope that it will be useful, #
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
13 # GNU General Public License for more details. #
14 # #
15 # You should have received a copy of the GNU General Public License #
16 # along with this program; if not, write to the #
17 # Free Software Foundation, Inc., #
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
19 ###########################################################################
20
21 #
22 # Name of the main target executable file
23 #
24
25 TARGET := fheroes2
26
27 #
28 # Common build options for fheroes2 and third-party libraries
29 #
30
31 # Common flags for both C and C++ compilers
32 CCFLAGS := -fsigned-char -pthread
33 # Flags for the C compiler
34 CFLAGS := $(CFLAGS)
35 # Flags for the C++ compiler
36 CXXFLAGS := $(CXXFLAGS)
37 # Flags for the preprocessor
38 CPPFLAGS := $(CPPFLAGS)
39 # Flags for the linker
40 LDFLAGS := $(LDFLAGS) -pthread
41 # Flags for additional libraries
42 LDLIBS := $(LDLIBS)
43
44 ifdef FHEROES2_WITH_DEBUG
45 CCFLAGS := $(CCFLAGS) -O0 -g
46 else
47 CCFLAGS := $(CCFLAGS) -O3
48 endif
49
50 ifneq ($(or $(FHEROES2_WITH_ASAN),$(FHEROES2_WITH_TSAN)),)
51 SANITIZERS := undefined
52
53 ifdef FHEROES2_WITH_ASAN
54 SANITIZERS := $(SANITIZERS),address
55 endif
56 ifdef FHEROES2_WITH_TSAN
57 SANITIZERS := $(SANITIZERS),thread
58 endif
59
60 CCFLAGS := $(CCFLAGS) -fsanitize=$(SANITIZERS)
61 LDFLAGS := $(LDFLAGS) -fsanitize=$(SANITIZERS)
62 endif
63
64 #
65 # Platform-specific build options
66 #
67
68 ifndef PLATFORM
69 ifndef OS
70 OS := $(shell uname)
71 endif
72
73 ifeq ($(OS),FreeBSD)
74 PLATFORM := bsd
75 endif
76 ifeq ($(OS),Darwin)
77 PLATFORM := osx
78 endif
79 ifeq ($(OS),Linux)
80 PLATFORM := all
81 endif
82 ifeq ($(OS),Haiku)
83 PLATFORM := all
84 endif
85 endif
86
87 include Makefile.$(PLATFORM)
88
89 #
90 # Build options for third-party libraries
91 #
92
93 CCFLAGS_TP := $(CCFLAGS)
94 CFLAGS_TP := $(CFLAGS)
95 CXXFLAGS_TP := $(CXXFLAGS)
96 CPPFLAGS_TP := $(CPPFLAGS)
97
98 #
99 # Build options for fheroes2
100 #
101
102 # *FLAGS_FH2 can be passed from platform-specific Makefiles
103 CCFLAGS := $(CCFLAGS) $(CCFLAGS_FH2)
104 CFLAGS := $(CFLAGS) $(CFLAGS_FH2)
105 CXXFLAGS := $(CXXFLAGS) $(CXXFLAGS_FH2) -std=c++17
106 CPPFLAGS := $(CPPFLAGS) $(CPPFLAGS_FH2)
107
108 ifdef FHEROES2_WITH_SYSTEM_SMACKER
109 LIBS := $(LIBS) -lsmacker
110 endif
111 LIBS := $(LIBS) -lz $(LDLIBS)
112
113 ifdef FHEROES2_WITH_DEBUG
114 CCFLAGS := $(CCFLAGS) -DWITH_DEBUG
115 endif
116 ifdef FHEROES2_WITH_IMAGE
117 CCFLAGS := $(CCFLAGS) -DWITH_IMAGE
118 endif
119 ifdef FHEROES2_DATA
120 CCFLAGS := $(CCFLAGS) -DFHEROES2_DATA="$(FHEROES2_DATA)"
121 endif
122
123 # TODO: Add -Wconversion -Wsign-conversion flags once we fix all the corresponding code smells
124 CCWARNOPTS := -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wdouble-promotion -Wfloat-conversion -Wfloat-equal \
125 -Wredundant-decls -Wshadow -Wswitch-default -Wundef -Wunused
126 CFLAGS := $(CFLAGS) $(CCWARNOPTS)
127 CXXFLAGS := $(CXXFLAGS) $(CCWARNOPTS) -Wctor-dtor-privacy -Wextra-semi -Wmissing-declarations -Wold-style-cast \
128 -Woverloaded-virtual -Wsuggest-override
129
130 ifdef FHEROES2_STRICT_COMPILATION
131 CCFLAGS := $(CCFLAGS) -Werror
132 endif
133
134 #
135 # SDL-related build options
136 #
137
138 # SDL_FLAGS can already be defined in a platform-specific Makefile
139 ifeq ($(origin SDL_FLAGS),undefined)
140 SDL_FLAGS := $(shell sdl2-config --cflags)
141
142 ifdef FHEROES2_WITH_IMAGE
143 SDL_FLAGS := $(SDL_FLAGS) $(shell libpng-config --cflags)
144 endif
145 endif
146
147 # SDL_LIBS can already be defined in a platform-specific Makefile
148 ifeq ($(origin SDL_LIBS),undefined)
149 SDL_LIBS := -lSDL2_mixer $(shell sdl2-config --libs)
150
151 ifdef FHEROES2_WITH_IMAGE
152 SDL_LIBS := $(SDL_LIBS) -lSDL2_image $(shell libpng-config --libs)
153 endif
154 endif
155
156 CCFLAGS := $(CCFLAGS) $(SDL_FLAGS)
157 LIBS := $(SDL_LIBS) $(LIBS)
158
159 export CC CXX AR CCFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LIBS TARGET
160
161 .PHONY: all clean
162
163 all:
164 ifndef FHEROES2_WITH_SYSTEM_SMACKER
165 $(MAKE) -C thirdparty/libsmacker CCFLAGS="$(CCFLAGS_TP)" CFLAGS="$(CFLAGS_TP)" CXXFLAGS="$(CXXFLAGS_TP)" CPPFLAGS="$(CPPFLAGS_TP)"
166 endif
167 $(MAKE) -C engine
168 $(MAKE) -C fheroes2
169 ifdef FHEROES2_WITH_TOOLS
170 $(MAKE) -C tools
171 endif
172
173 clean:
174 $(MAKE) -C thirdparty/libsmacker clean
175 $(MAKE) -C engine clean
176 $(MAKE) -C fheroes2 clean
177 $(MAKE) -C tools clean