-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
389 lines (322 loc) · 11.3 KB
/
Makefile
File metadata and controls
389 lines (322 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
.PHONY: all install clean veryclean user winuser osxuser ubuntu \
dist tarball zipfile source-dist i686-dist win32-dist
VERSION := 6.5
DEBUG ?= NO
# Note: Submit as "YES" to enable debugging
# Note: If any flag starting with -g is found in the CXXFLAGS, DEBUG is
# switched to YES no matter whether set otherwise or not.
# The following switches can be used to fine-tune the debugging output:
# Note: DEBUG_AICORE can be used to enable both DEBUG_AIMING and DEBUG_EMOTION
# together with a single flag.
DEBUG_AICORE ?= NO
DEBUG_AIMING ?= NO
DEBUG_EMOTION ?= NO
DEBUG_FINANCE ?= NO
DEBUG_OBJECTS ?= NO
DEBUG_PHYSICS ?= NO
# If the debug output shall be written to atanks.log, set this to YES
DEBUG_LOG_TO_FILE ?= NO
# These three are mutually exclusive. If all are set to yes,
# address-sanitizing has priority, followed by leak, thread
# is last.
SANITIZE_ADDRESS ?= NO
SANITIZE_LEAK ?= NO
SANITIZE_THREAD ?= NO
# The following is only used on gcc-4.9+ and only without debugging enabled.
USE_LTO ?= NO
# ------------------------------------
# Install and target directories
# ------------------------------------
PREFIX ?= /usr
DESTDIR ?=
BINPREFIX ?= $(PREFIX)
BINDIR ?= ${BINPREFIX}/bin
INSTALLDIR ?= ${PREFIX}/share/games/atanks
# ------------------------------------
# Source files and objects
# ------------------------------------
SOURCES := $(sort $(wildcard src/*.cpp))
MODULES := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o)))
DEPENDS := $(addprefix dep/,$(notdir $(SOURCES:.cpp=.d)))
# -------------------------------------
# Platform to build for (Can be forced)
# -------------------------------------
PLATFORM ?= none
ifeq (none,$(PLATFORM))
# The easiest way is to go through our make goals
# I know this looks weird, but the following simply means:
# "If the search for "win" in MAKECMDGOALS does not return an empty string"
ifneq (,$(findstring win,$(MAKECMDGOALS)))
PLATFORM := WIN32
else ifneq (,$(findstring osx,$(MAKECMDGOALS)))
PLATFORM := MACOSX
else
PLATFORM := LINUX
endif
endif
# If this is a user make goal, the install directory is forced to be local:
ifneq (,$(findstring user,$(MAKECMDGOALS)))
INSTALLDIR := .
endif
# --------------------------------------------
# Target executable and distribution file name
# --------------------------------------------
TARGET := atanks
FILENAME := $(TARGET)-$(VERSION)
# ------------------------------------
# Tools to use
# ------------------------------------
INSTALL := $(shell which install)
RM := $(shell which rm) -f
CXX ?= g++
SED := $(shell which sed)
WINDRES :=
ifeq (,$(findstring /,$(CXX)))
CXX := $(shell which $(CXX))
endif
# if this is a Windows target, prefer mingw32-g++ over g++
# Further more the WIN32 Platform needs windres.exe to create src/atanks.res
ifeq (WIN32,$(PLATFORM))
ifneq (,$(findstring /g++,$(CXX)))
CXX := $(shell which mingw32-g++)
endif
WINDRES := $(shell which windres.exe)
MODULES := ${MODULES} obj/atanks.res
TARGET := ${TARGET}.exe
RM := del /q
endif
# Use the compiler as the linker.
LD := $(CXX)
# --------------------------------------------------------------------------
# Determine proper C++11 standard flag, and if and how stack protector works
# --------------------------------------------------------------------------
GCCVERSGTEQ47 := 0
GCCVERSGTEQ49 := 0
GCCUSESGOLD := 0
GCC_STACKPROT :=
GCC_CXXSTD := 0x
PEDANDIC_FLAG := -pedantic
# Note: It has to be evaluated which versions of clang and mingw
# start using c++11 instead of c++0x.
ifneq (,$(findstring /g++,$(CXX)))
GCCVERSGTEQ47 := $(shell expr `$(CXX) -dumpversion | cut -f1,2 -d. | tr -d '.'` \>= 47)
GCCVERSGTEQ49 := $(shell expr `$(CXX) -dumpversion | cut -f1,2 -d. | tr -d '.'` \>= 49)
endif
ifeq "$(GCCVERSGTEQ47)" "1"
GCC_CXXSTD := 11
PEDANDIC_FLAG := -Wpedantic
ifeq "$(GCCVERSGTEQ49)" "1"
GCC_STACKPROT := -fstack-protector-strong
GCCUSESGOLD := $(shell ld --version | head -n 1 | grep -c "GNU gold")
else
GCC_STACKPROT := -fstack-protector
endif
endif
# ------------------------------------
# Flags for compiler and linker
# ------------------------------------
CPPFLAGS += -DDATA_DIR=\"${INSTALLDIR}\" -D$(PLATFORM) -DVERSION=\"${VERSION}\"
CXXFLAGS += -Wall -Wextra $(PEDANDIC_FLAG) -std=c++$(GCC_CXXSTD)
LDFLAGS +=
# Depending on the platform, some values have to be appended:
ifeq (MACOSX,$(PLATFORM))
CPPFLAGS := ${CPPFLAGS} -I/usr/local/include $(shell allegro-config --cppflags)
LDFLAGS := ${LDFLAGS} $(shell allegro-config --libs)
else ifeq (WIN32,$(PLATFORM))
CPPFLAGS := ${CPPFLAGS} -I/usr/local/include
CXXFLAGS := ${CXXFLAGS} -mwindows
LDFLAGS := ${LDFLAGS} -mwindows -L. -lalleg44
else
ifneq (,$(findstring bsd,$(MAKECMDGOALS)))
C_INCLUDE_PATH := /usr/local/include
CPLUS_INCLUDE_PATH := /usr/local/include
CXXFLAGS := ${CXXFLAGS} -Wno-c99-extensions
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH
endif
CPPFLAGS := ${CPPFLAGS} -DNETWORK $(shell allegro-config --cppflags)
CXXFLAGS := ${CXXFLAGS} -pthread
LDFLAGS := ${LDFLAGS} $(shell allegro-config --libs) -lm -lpthread
endif
# If the make goal is "ubuntu", a special define is to be added:
ifeq (UBUNTU,$(MAKECMDGOALS))
CPPFLAGS := ${CPPFLAGS} -DUBUNTU
endif
# ------------------------------------
# Debug Mode settings
# ------------------------------------
HAS_DEBUG_FLAG := NO
ifneq (,$(findstring -g,$(CXXFLAGS)))
ifneq (,$(findstring -ggdb,$(CXXFLAGS)))
HAS_DEBUG_FLAG := YES
endif
DEBUG := YES
endif
ifeq (YES,$(DEBUG))
ifeq (NO,$(HAS_DEBUG_FLAG))
CXXFLAGS := -ggdb ${CXXFLAGS} -O0
endif
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG
CXXFLAGS := ${CXXFLAGS} ${GCC_STACKPROT} -Wunused
# LTO is hard blocked now:
USE_LTO := NO
# address / thread sanitizer activation
ifeq (YES,$(SANITIZE_ADDRESS))
CXXFLAGS := ${CXXFLAGS} -fsanitize=address
LDFLAGS := ${LDFLAGS} -fsanitize=address
else ifeq (YES,$(SANITIZE_LEAK))
CXXFLAGS := ${CXXFLAGS} -fsanitize=leak
LDFLAGS := ${LDFLAGS} -fsanitize=leak
else ifeq (YES,$(SANITIZE_THREAD))
CPPFLAGS := ${CPPFLAGS} -DUSE_MUTEX_INSTEAD_OF_SPINLOCK
CXXFLAGS := ${CXXFLAGS} -fsanitize=thread -fPIC -O2 -ggdb
LDFLAGS := ${LDFLAGS} -fsanitize=thread -pie -O2 -ggdb
endif
# Add specific debug message flavours
ifeq (YES,$(DEBUG_AICORE))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_AIMING -DATANKS_DEBUG_EMOTIONS
endif
ifeq (YES,$(DEBUG_AIMING))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_AIMING
endif
ifeq (YES,$(DEBUG_EMOTION))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_EMOTIONS
endif
ifeq (YES,$(DEBUG_FINANCE))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_FINANCE
endif
ifeq (YES,$(DEBUG_OBJECTS))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_OBJECTS
endif
ifeq (YES,$(DEBUG_PHYSICS))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_PHYSICS
endif
ifeq (YES,$(DEBUG_LOG_TO_FILE))
CPPFLAGS := ${CPPFLAGS} -DATANKS_DEBUG_LOGTOFILE
endif
else
CXXFLAGS := -march=native ${CXXFLAGS} -O2
endif
# Potentially enable LTO if this is gcc-4.9 and greater
ifeq (YES,$(USE_LTO))
ifeq "$(GCCVERSGTEQ49)" "1"
CXXFLAGS := ${CXXFLAGS} -flto
endif
ifeq "$(GCCUSESGOLD)" "1"
CXXFLAGS := ${CXXFLAGS} -fuse-linker-plugin
endif
endif
# ------------------------------------
# Distribution file lists
# ------------------------------------
DISTCOMMON := \
atanks/*.dat atanks/COPYING atanks/README atanks/TODO \
atanks/Changelog atanks/BUGS atanks/*.txt
INCOMMON := COPYING README TODO Changelog *.txt unicode.dat
# ------------------------------------
# Default target
# ------------------------------------
all: $(TARGET)
# ------------------------------------
# Create dependencies
# This is the standard as described
# on the GNU make info manual.
# (See Chapter 4.14)
# ------------------------------------
dep/%.d: src/%.cpp
@set -e; $(RM) $@; \
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
$(SED) 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
$(RM) $@.$$$$
# ------------------------------------
# Compile modules
# ------------------------------------
obj/%.o: src/%.cpp
@echo "Compiling $@"
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
# ------------------------------------
# Build windows res file
# ------------------------------------
obj/atanks.res:
ifeq (WIN32,$(PLATFORM))
$(WINDRES) -i src/atanks.rc --input-format=rc -o obj/atanks.res -O coff
else
@echo "This is no WIN32 platform, so why?"
endif
# ------------------------------------
# Regular targets
# ------------------------------------
install: $(TARGET)
$(INSTALL) -d $(DESTDIR)${BINDIR}
$(INSTALL) -m 755 atanks $(DESTDIR)${BINDIR}
$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/metainfo
$(INSTALL) -m 644 io.sourceforge.atanks.metainfo.xml $(DESTDIR)$(PREFIX)/share/metainfo
$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/applications
$(INSTALL) -m 644 atanks.desktop $(DESTDIR)$(PREFIX)/share/applications
$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps
$(INSTALL) -m 644 atanks.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/48x48/apps
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/button
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/misc
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/missile
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/sound
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/stock
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/tank
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/tankgun
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/title
$(INSTALL) -d $(DESTDIR)${INSTALLDIR}/text
$(INSTALL) -m 644 $(INCOMMON) $(DESTDIR)${INSTALLDIR}
$(INSTALL) -m 644 button/* $(DESTDIR)${INSTALLDIR}/button
$(INSTALL) -m 644 misc/* $(DESTDIR)${INSTALLDIR}/misc
$(INSTALL) -m 644 missile/* $(DESTDIR)${INSTALLDIR}/missile
$(INSTALL) -m 644 sound/* $(DESTDIR)${INSTALLDIR}/sound
$(INSTALL) -m 644 stock/* $(DESTDIR)${INSTALLDIR}/stock
$(INSTALL) -m 644 tank/* $(DESTDIR)${INSTALLDIR}/tank
$(INSTALL) -m 644 tankgun/* $(DESTDIR)${INSTALLDIR}/tankgun
$(INSTALL) -m 644 title/* $(DESTDIR)${INSTALLDIR}/title
$(INSTALL) -m 644 text/* $(DESTDIR)${INSTALLDIR}/text
$(TARGET): $(MODULES)
$(LD) -o $@ $(MODULES) $(CPPFLAGS) $(LDFLAGS) $(CXXFLAGS)
clean:
$(RM) obj/* atanks
veryclean: clean
ifeq (WIN32,$(PLATFORM))
$(RM) $(TARGET).exe
else
$(RM) $(TARGET)
endif
# ------------------------------------
# User (local) targets
# ------------------------------------
user: $(TARGET)
winuser: $(TARGET)
osxuser: $(TARGET)
bsduser: $(TARGET)
ubuntu: $(TARGET)
# ------------------------------------
# Distribution targets
# ------------------------------------
dist: source-dist i686-dist win32-dist
tarball: veryclean
cd .. && tar czf $(FILENAME).tar.gz $(FILENAME) --exclude=.git
zipfile: veryclean
cd .. && zip -r $(FILENAME)-source.zip $(FILENAME) -x *.git*
source-dist: $(TARGET)
cd ../; \
$(RM) $(FILENAME).tar.gz; \
tar czf $(FILENAME).tar.gz atanks/src/*.cpp atanks/src/*.h atanks/Makefile $(DISTCOMMON)
i686-dist: $(TARGET)
cd ../; \
$(RM) $(FILENAME)-i686-dist.tar.gz; \
strip atanks/atanks; \
tar czf $(FILENAME)-i686-dist.tar atanks/atanks $(DISTCOMMON)
win32-dist: $(TARGET)
cd ../; \
$(RM) $(FILENAME)-win32-dist.zip; \
zip -r $(FILENAME)-win32-dist.zip atanks/atanks.exe atanks/alleg40.dll $(DISTCOMMON)
# ------------------------------------
# Include all dependency files
# ------------------------------------
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
-include $(DEPENDS)
endif