/
Makefile
572 lines (482 loc) · 14.1 KB
/
Makefile
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
##
# MegaZeux Build System (GNU Make)
#
# NOTE: This build system is designed to not use recursive Makefiles.
# The rationale for this is documented here:
#
# https://web.archive.org/web/20200128044903/http://aegis.sourceforge.net/auug97.pdf
##
#
# Remove all built-in rules.
#
.SUFFIXES:
ifeq ($(filter -r,$(MAKEFLAGS)),)
MAKEFLAGS += -r
endif
.PHONY: all clean help_check mzx mzx.debug build build_clean source
.PHONY: test unittest test_clean unit_clean
#
# Define this first so arch-specific rules don't hijack the default target.
#
all:
-include platform.inc
include version.inc
#
# ${build_root}: base location where builds are copied to be archived for release.
# ${build}: location where the MegaZeux executable and data files should be placed.
# Defaults to ${build_root}, but the architecture Makefile may override this to
# use a subdirectory instead. This is useful when a platform expects a particular
# path hierarchy within the archive (e.g. MacOS .app bundles).
#
build_root := build/${SUBPLATFORM}
build := ${build_root}
-include arch/${PLATFORM}/Makefile.in
CC ?= gcc
CXX ?= g++
AR ?= ar
AS ?= as
STRIP ?= strip --strip-unneeded
OBJCOPY ?= objcopy
PEFIX ?= true
CHMOD ?= chmod
CP ?= cp
HOST_CC ?= gcc
LN ?= ln
MKDIR ?= mkdir
MV ?= mv
RM ?= rm
include arch/compat.inc
#
# Set up CFLAGS/LDFLAGS for all MegaZeux external dependencies.
#
ifeq (${BUILD_SDL},1)
#
# SDL 2
#
ifneq (${BUILD_LIBSDL2},)
# Check PREFIX for sdl2-config.
ifneq ($(and ${SDL_PREFIX},$(wildcard ${SDL_PREFIX}/bin/sdl2-config)),)
SDL_CONFIG := ${SDL_PREFIX}/bin/sdl2-config
else ifneq ($(wildcard ${PREFIX}/bin/sdl2-config),)
SDL_CONFIG := ${PREFIX}/bin/sdl2-config
else
SDL_CONFIG := sdl2-config
endif
SDL_PREFIX ?= $(shell ${SDL_CONFIG} --prefix)
SDL_CFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --cflags | sed 's,-I,-isystem ,g')
SDL_LDFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --libs)
endif
#
# SDL 1.2
#
ifeq (${BUILD_LIBSDL2},)
# Check PREFIX for sdl-config.
ifneq ($(and ${SDL_PREFIX},$(wildcard ${SDL_PREFIX}/bin/sdl-config)),)
SDL_CONFIG := ${SDL_PREFIX}/bin/sdl-config
else ifneq ($(wildcard ${PREFIX}/bin/sdl-config),)
SDL_CONFIG := ${PREFIX}/bin/sdl-config
else
SDL_CONFIG := sdl-config
endif
SDL_PREFIX ?= $(shell ${SDL_CONFIG} --prefix)
SDL_CFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --cflags)
SDL_LDFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --libs)
endif
# Make these immediate so the scripts run only once.
SDL_PREFIX := $(SDL_PREFIX)
SDL_CFLAGS := $(SDL_CFLAGS)
SDL_LDFLAGS := $(LINK_DYNAMIC_IF_MIXED) $(SDL_LDFLAGS)
endif
#
# libvorbis/tremor
#
VORBIS_CFLAGS ?= -I${PREFIX}/include -DOV_EXCLUDE_STATIC_CALLBACKS
ifeq (${VORBIS},vorbis)
VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisfile -lvorbis -logg
else ifeq (${VORBIS},tremor)
VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisidec -logg
else ifeq (${VORBIS},tremor-lowmem)
VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisidec
endif
#
# MikMod (optional mod engine)
#
MIKMOD_CFLAGS ?= -I${PREFIX}/include
MIKMOD_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lmikmod
#
# libopenmpt (optional mod engine)
#
OPENMPT_CFLAGS ?= -I${PREFIX}/include
OPENMPT_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lopenmpt
#
# zlib
#
ZLIB_CFLAGS ?= -I${PREFIX}/include \
-D_FILE_OFFSET_BITS=32 -U_LARGEFILE64_SOURCE
ZLIB_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lz
#
# libpng
#
ifeq (${LIBPNG},1)
# Check PREFIX for libpng-config.
ifneq ($(wildcard ${PREFIX}/bin/libpng-config),)
LIBPNG_CONFIG := ${PREFIX}/bin/libpng-config
else
LIBPNG_CONFIG := libpng-config
endif
LIBPNG_CFLAGS ?= $(shell ${LIBPNG_CONFIG} --cflags)
LIBPNG_LDFLAGS ?= $(shell ${LIBPNG_CONFIG} --ldflags)
# Make these immediate so the scripts run only once.
LIBPNG_CFLAGS := $(LIBPNG_CFLAGS)
LIBPNG_LDFLAGS := $(LINK_STATIC_IF_MIXED) $(LIBPNG_LDFLAGS)
endif
#
# X11
#
ifneq (${X11DIR},)
X11_CFLAGS ?= -I${X11DIR}/../include
X11_LDFLAGS ?= -L${X11DIR}/../lib -lX11
# Make these immediate
X11_CFLAGS := $(X11_CFLAGS)
X11_LDFLAGS := $(X11_LDFLAGS)
endif
#
# pthread
#
PTHREAD_LDFLAGS ?= -lpthread
#
# Set up general CFLAGS/LDFLAGS
#
OPTIMIZE_CFLAGS ?= -O3
ifeq (${DEBUG},1)
#
# Usually, just disable the optimizer for "true" debug builds and
# define "DEBUG" to enable optional code at compile time.
#
# Sanitizer builds turn on some optimizations for the sake of being usable.
#
ifeq (${SANITIZER},address)
DEBUG_CFLAGS := -fsanitize=address -O1 -fno-omit-frame-pointer
else ifeq (${SANITIZER},undefined)
DEBUG_CFLAGS := -fsanitize=undefined -O0 -fno-omit-frame-pointer
else ifeq (${SANITIZER},thread)
DEBUG_CFLAGS := -fsanitize=thread -O2 -fno-omit-frame-pointer -fPIE
ARCH_EXE_LDFLAGS += -pie
else ifeq (${SANITIZER},memory)
# FIXME I don't think there's a way to make this one work properly right now.
# SDL_Init generates an error immediately and if sanitize-recover is used it
# seems to get stuck printing endless errors.
DEBUG_CFLAGS := -fsanitize=memory -O1 -fno-omit-frame-pointer -fPIE \
-fsanitize-recover=memory -fsanitize-memory-track-origins
ARCH_EXE_LDFLAGS += -pie
else
DEBUG_CFLAGS ?= -O0
endif
CFLAGS = ${DEBUG_CFLAGS} -DDEBUG
CXXFLAGS = ${DEBUG_CFLAGS} -DDEBUG
LDFLAGS += ${DEBUG_CFLAGS}
else
#
# Optimized builds have assert() compiled out
#
CFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
CXXFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
endif
CFLAGS += -Wundef -Wunused-macros
CXXFLAGS += -Wundef -Wunused-macros
#
# Enable C++11 for compilers that support it.
# Anything actually using C++11 should be optional or platform-specific,
# as features using C++11 reduce portability.
#
ifeq (${HAS_CXX_11},1)
CXX_STD = -std=gnu++11
else
CXX_STD = -std=gnu++98
endif
#
# Always generate debug information; this may end up being
# stripped (on embedded platforms) or objcopy'ed out.
#
CFLAGS += -g -W -Wall -Wno-unused-parameter -std=gnu99
CFLAGS += -Wdeclaration-after-statement ${ARCH_CFLAGS}
CXXFLAGS += -g -W -Wall -Wno-unused-parameter ${CXX_STD}
CXXFLAGS += -fno-exceptions -fno-rtti ${ARCH_CXXFLAGS}
LDFLAGS += ${ARCH_LDFLAGS}
#
# Optional compile flags.
#
#
# Warn against variable-length array (VLA) usage, which is technically valid
# C99 but is in bad taste and isn't supported by MSVC.
#
ifeq (${HAS_W_VLA},1)
CFLAGS += -Wvla
CXXFLAGS += -Wvla
endif
#
# Linux GCC gives spurious format truncation warnings. The snprintf
# implementation on Linux will terminate even in the case of truncation,
# making this largely useless. It does not trigger using mingw (where it
# would actually matter).
#
ifeq (${HAS_W_NO_FORMAT_TRUNCATION},1)
CFLAGS += -Wno-format-truncation
CXXFLAGS += -Wno-format-truncation
endif
#
# Old GCC versions emit false positive warnings for C++11 value initializers.
#
ifeq (${HAS_BROKEN_W_MISSING_FIELD_INITIALIZERS},1)
CXXFLAGS += -Wno-missing-field-initializers
endif
#
# We enable pedantic warnings here, but this ends up turning on some things
# we must disable by hand.
#
# Variadic macros are arguably less portable, but all the compilers we
# support have them.
#
ifeq (${HAS_PEDANTIC},1)
CFLAGS += -pedantic
CXXFLAGS += -pedantic
ifeq (${HAS_W_NO_VARIADIC_MACROS},1)
CFLAGS += -Wno-variadic-macros
CXXFLAGS += -Wno-variadic-macros
endif
endif
#
# The following flags are not applicable to mingw builds.
#
ifneq (${PLATFORM},mingw)
#
# Symbols in COFF binaries are implicitly hidden unless exported; this
# flag just confuses GCC and must be disabled.
#
ifeq (${HAS_F_VISIBILITY},1)
CFLAGS += -fvisibility=hidden
CXXFLAGS += -fvisibility=hidden
endif
endif # PLATFORM=mingw
#
# The stack protector is optional and is generally only built for Linux/BSD and
# Mac OS X. Windows and most embedded platforms currently disable this.
#
ifeq (${BUILD_STACK_PROTECTOR},1)
ifeq (${HAS_F_STACK_PROTECTOR},1)
CFLAGS += -fstack-protector-all
CXXFLAGS += -fstack-protector-all
else
$(warning stack protector not supported, ignoring.)
endif
endif
#
# Enable -fanalyzer if supported.
#
ifeq (${BUILD_F_ANALYZER},1)
ifeq (${HAS_F_ANALYZER},1)
CFLAGS += -fanalyzer
CXXFLAGS += -fanalyzer
else
$(warning GCC 10+ is required for -fanalyzer, ignoring.)
endif
endif
#
# Enable position-independent code across the board for modular builds.
#
ifeq (${BUILD_MODULAR},1)
CFLAGS += -fPIC
CXXFLAGS += -fPIC
endif
#
# We don't want these commands to be echo'ed in non-verbose mode
#
ifneq (${V},1)
override V:=
CC := @${CC}
CXX := @${CXX}
AR := @${AR}
AS := @${AS}
STRIP := @${STRIP}
OBJCOPY := @${OBJCOPY}
PEFIX := @${PEFIX}
CHMOD := @${CHMOD}
CP := @${CP}
HOST_CC := @${HOST_CC}
LN := @${LN}
MKDIR := @${MKDIR}
MV := @${MV}
RM := @${RM}
endif
build_clean:
$(if ${V},,@echo " RM " build)
${RM} -r build
source: build/${TARGET}src
#
# Build source target
# Targetting unix primarily, so turn off autocrlf if necessary
#
ifneq ($(shell which git),)
USER_AUTOCRLF=$(shell git config core.autocrlf)
endif
build/${TARGET}src:
${RM} -r build/${TARGET}
${MKDIR} -p build/dist/source
@git config core.autocrlf false
@git checkout-index -a --prefix build/${TARGET}/
@git config core.autocrlf ${USER_AUTOCRLF}
${RM} -r build/${TARGET}/scripts
${RM} build/${TARGET}/.gitignore build/${TARGET}/.gitattributes
@cd build/${TARGET} && make distclean
@tar -C build -Jcf build/dist/source/${TARGET}src.tar.xz ${TARGET}
#
# The SUPPRESS_ALL_TARGETS hack is required to allow the placebo "dist"
# Makefile to provide an 'all:' target, which allows it to print
# a message. Pulling in any other targets would confuse Make.
#
# Additionally, there are several other SUPPRESS flags that can be set to
# conditionally disable rules. This is useful for cross-compiling builds that
# have no use for host-based rules or for platforms that use meta targets.
#
# * SUPPRESS_CC_TARGETS prevents "mzx", etc from being added to "all".
# * SUPPRESS_BUILD_TARGETS suppresses "build".
# * SUPPRESS_HOST_TARGETS suppresses "assets/help.fil", "test", etc.
#
ifneq (${SUPPRESS_ALL_TARGETS},1)
mzxrun = mzxrun${BINEXT}
mzx = megazeux${BINEXT}
mzx: ${mzxrun} ${mzx}
mzx.debug: ${mzxrun}.debug ${mzx}.debug
ifeq (${BUILD_MODPLUG},1)
BUILD_GDM2S3M=1
endif
%/.build:
$(if ${V},,@echo " MKDIR " $@)
${MKDIR} $@
%.debug: %
$(if ${V},,@echo " OBJCOPY " --only-keep-debug $< $@)
${OBJCOPY} --only-keep-debug $< $@
${PEFIX} $@
${CHMOD} a-x $@
$(if ${V},,@echo " STRIP " $<)
${STRIP} $<
$(if ${V},,@echo " OBJCOPY " --add-gnu-debuglink $@ $<)
${OBJCOPY} --add-gnu-debuglink=$@ $<
${PEFIX} $<
@touch $@
include src/Makefile.in
clean: mzx_clean test_clean unit_clean
ifneq (${SUPPRESS_CC_TARGETS},1)
all: mzx
debuglink: all mzx.debug
endif
ifeq (${BUILD_UTILS},1)
include src/utils/Makefile.in
clean: utils_clean
ifneq (${SUPPRESS_CC_TARGETS},1)
debuglink: utils utils.debug
all: utils
endif
endif
ifneq (${SUPPRESS_BUILD_TARGETS},1)
ifeq (${build},)
build := ${build_root}
endif
.PHONY: ${build}
build: ${build} ${build}/assets ${build}/docs
${build}:
${RM} -r ${build_root}
${MKDIR} -p ${build}
${CP} config.txt LICENSE ${build}
@if test -f ${mzxrun}; then \
cp ${mzxrun} ${build}; \
fi
@if test -f ${mzxrun}.debug; then \
cp ${mzxrun}.debug ${build}; \
fi
ifeq (${BUILD_EDITOR},1)
@if test -f ${mzx}; then \
cp ${mzx} ${build}; \
fi
@if test -f ${mzx}.debug; then \
cp ${mzx}.debug ${build}; \
fi
endif
ifeq (${BUILD_MODULAR},1)
${CP} ${core_target} ${editor_target} ${build}
@if test -f ${core_target}.debug; then \
cp ${core_target}.debug ${build}; \
fi
@if test -f ${editor_target}.debug; then \
cp ${editor_target}.debug ${build}; \
fi
endif
ifeq (${BUILD_UTILS},1)
${MKDIR} ${build}/utils
${CP} ${checkres} ${downver} ${build}/utils
${CP} ${hlp2txt} ${txt2hlp} ${build}/utils
${CP} ${ccv} ${png2smzx} ${build}/utils
@if [ -f "${checkres}.debug" ]; then cp ${checkres}.debug ${build}/utils; fi
@if [ -f "${downver}.debug" ]; then cp ${downver}.debug ${build}/utils; fi
@if [ -f "${hlp2txt}.debug" ]; then cp ${hlp2txt}.debug ${build}/utils; fi
@if [ -f "${txt2hlp}.debug" ]; then cp ${txt2hlp}.debug ${build}/utils; fi
@if [ -f "${ccv}.debug" ]; then cp ${ccv}.debug ${build}/utils; fi
@if [ -f "${png2smzx}.debug" ]; then cp ${png2smzx}.debug ${build}/utils; fi
endif
${build}/docs: ${build}
${MKDIR} -p ${build}/docs
${CP} docs/macro.txt docs/keycodes.html docs/mzxhelp.html ${build}/docs
${CP} docs/joystick.html docs/cycles_and_commands.txt ${build}/docs
${CP} docs/fileform.html ${build}/docs
${CP} docs/changelog.txt docs/platform_matrix.html ${build}/docs
${build}/assets: ${build}
${MKDIR} -p ${build}/assets
${CP} assets/default.chr assets/edit.chr ${build}/assets
${CP} assets/smzx.pal ${build}/assets
ifeq (${BUILD_EDITOR},1)
${CP} assets/ascii.chr assets/blank.chr ${build}/assets
${CP} assets/smzx.chr assets/smzx2.chr ${build}/assets
endif
ifeq (${BUILD_HELPSYS},1)
${CP} assets/help.fil ${build}/assets
endif
ifeq (${BUILD_RENDER_GL_PROGRAM},1)
${MKDIR} -p ${build}/assets/glsl/scalers
${CP} assets/glsl/*.vert ${build}/assets/glsl
${CP} assets/glsl/*.frag ${build}/assets/glsl
${CP} assets/glsl/README.md ${build}/assets/glsl
${CP} assets/glsl/scalers/*.frag assets/glsl/scalers/*.vert \
${build}/assets/glsl/scalers
endif
ifeq (${BUILD_GAMECONTROLLERDB},1)
${CP} assets/gamecontrollerdb.txt assets/gamecontrollerdb.LICENSE \
${build}/assets
endif
endif # !SUPPRESS_BUILD_TARGETS
distclean: clean
@echo " DISTCLEAN"
@rm -f src/config.h
@echo "PLATFORM=none" > platform.inc
ifneq (${SUPPRESS_HOST_TARGETS},1)
assets/help.fil: ${txt2hlp} docs/WIPHelp.txt
$(if ${V},,@echo " txt2hlp " $@)
@src/utils/txt2hlp docs/WIPHelp.txt $@
docs/mzxhelp.html: ${hlp2html} docs/WIPHelp.txt
$(if ${V},,@echo " hlp2html" $@)
@src/utils/hlp2html docs/WIPHelp.txt docs/mzxhelp.html
help_check: ${hlp2txt} assets/help.fil
@src/utils/hlp2txt assets/help.fil help.txt
@echo @ >> help.txt
@diff --strip-trailing-cr -q docs/WIPHelp.txt help.txt
@rm -f help.txt
-include unit/Makefile.in
test: unittest
ifeq (${BUILD_MODULAR},1)
@${SHELL} testworlds/run.sh ${PLATFORM} "$(realpath ${core_target})"
else
@${SHELL} testworlds/run.sh ${PLATFORM}
endif
endif # !SUPPRESS_HOST_TARGETS
test_clean:
@rm -rf testworlds/log
endif # !SUPPRESS_ALL_TARGETS