-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
311 lines (264 loc) · 7.34 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
##
# MegaZeux Build System (GNU Make)
#
# NOTE: This build system was recently re-designed to not use recursive
# Makefiles. The rationale for this is documented here:
# http://aegis.sourceforge.net/auug97.pdf
##
#
# Remove all built-in rules.
#
.SUFFIXES:
ifeq ($(filter -r,$(MAKEFLAGS)),)
MAKEFLAGS += -r
endif
.PHONY: clean help_check mzx mzx.debug build build_clean source
-include platform.inc
include version.inc
all: mzx
debuglink: all mzx.debug
-include arch/${PLATFORM}/Makefile.in
CC ?= gcc
CXX ?= g++
AR ?= ar
STRIP ?= strip --strip-unneeded
OBJCOPY ?= objcopy
PEFIX ?= true
CHMOD ?= chmod
CP ?= cp
HOST_CC ?= gcc
LN ?= ln
MKDIR ?= mkdir
MV ?= mv
RM ?= rm
ifeq (${BUILD_LIBSDL2},)
SDL_CFLAGS ?= $(shell sdl-config --cflags)
SDL_LDFLAGS ?= $(shell sdl-config --libs)
else
SDL_CFLAGS ?= $(shell sdl2-config --cflags | sed 's,-I,-isystem ,g')
SDL_LDFLAGS ?= $(shell sdl2-config --libs)
endif
VORBIS_CFLAGS ?= -I${PREFIX}/include -DOV_EXCLUDE_STATIC_CALLBACKS
ifneq (${TREMOR},1)
VORBIS_LDFLAGS ?= -L${PREFIX}/lib -lvorbisfile -lvorbis -logg
else
VORBIS_LDFLAGS ?= -L${PREFIX}/lib -lvorbisidec
endif
MIKMOD_CFLAGS ?= -I${PREFIX}/include
MIKMOD_LDFLAGS ?= -L${PREFIX}/lib -lmikmod
ZLIB_CFLAGS ?= -I${PREFIX}/include \
-D_FILE_OFFSET_BITS=32 -U_LARGEFILE64_SOURCE
ZLIB_LDFLAGS ?= -L${PREFIX}/lib -lz
ifeq (${LIBPNG},1)
LIBPNG_CFLAGS ?= $(shell libpng-config --cflags)
LIBPNG_LDFLAGS ?= $(shell libpng-config --ldflags)
endif
PTHREAD_LDFLAGS ?= -lpthread
OPTIMIZE_CFLAGS ?= -O2
ifeq (${DEBUG},1)
#
# Disable the optimizer for "true" debug builds
#
CFLAGS = -O0 -DDEBUG
CXXFLAGS = -O0 -DDEBUG
else
#
# Optimized builds have assert() compiled out
#
CFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
CXXFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
endif
#
# Android headers are busted and we get too many warnings..
#
ifneq (${PLATFORM},android)
CFLAGS += -Wundef -Wunused-macros
CXXFLAGS += -Wundef -Wunused-macros
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 -std=gnu++98
CXXFLAGS += -fno-exceptions -fno-rtti ${ARCH_CXXFLAGS}
LDFLAGS += ${ARCH_LDFLAGS}
ifeq (${shell ${CC} -dumpversion | cut -d. -f1},4)
ifeq (${DEBUG},1)
CFLAGS += -fbounds-check
CXXFLAGS += -fbounds-check
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.
#
# The "long long" type is only used in one platform's header files, and we
# don't use it at all in MegaZeux (even if we did it's quite portable).
#
ifneq (${PLATFORM},android)
CFLAGS += -pedantic -Wno-variadic-macros -Wno-long-long
CXXFLAGS += -pedantic -fpermissive -Wno-variadic-macros -Wno-long-long
endif
ifneq (${PLATFORM},mingw)
#
# Symbols in COFF binaries are implicitly hidden unless exported; this
# flag just confuses GCC and must be disabled.
#
CFLAGS += -fvisibility=hidden
CXXFLAGS += -fvisibility=hidden
#
# Skip the stack protector on embedded platforms; it just unnecessarily
# slows things down, and there's no easy way to write a convincing
# __stack_chk_fail function.
#
ifeq ($(or ${BUILD_GP2X},${BUILD_NDS},${BUILD_PSP},${BUILD_WII}),)
ifneq (${PLATFORM},android)
CFLAGS += -fstack-protector-all
CXXFLAGS += -fstack-protector-all
endif
endif
#
# Linux-arm needs this flag for modular builds.
#
ifeq (${SUBPLATFORM},linux-arm)
CFLAGS += -fPIC
CXXFLAGS += -fPIC
endif
endif
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}
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/${TARGET}src:
${RM} -r build/${TARGET}
${MKDIR} -p build/dist/source
@git checkout-index -a --prefix build/${TARGET}/
${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_BUILD hack is required to allow the placebo "dist"
# Makefile to provide an 'all:' target, which allows it to print
# a message. We don't want to pull in other targets, confusing Make.
#
ifneq (${SUPPRESS_BUILD},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
ifeq (${BUILD_UTILS},1)
include src/utils/Makefile.in
debuglink: utils utils.debug
clean: utils_clean
all: utils
endif
ifeq (${build},)
build := build/${SUBPLATFORM}
endif
build: ${build}
${build}:
${MKDIR} -p ${build}/docs
${MKDIR} -p ${build}/assets
${CP} config.txt ${build}
${CP} assets/default.chr assets/edit.chr ${build}/assets
${CP} assets/smzx.pal ${build}/assets
${CP} docs/COPYING.DOC docs/changelog.txt docs/port.txt ${build}/docs
${CP} docs/macro.txt docs/keycodes.html ${build}/docs
${CP} docs/platform_matrix.html ${build}/docs
${CP} ${mzxrun} ${build}
@if test -f ${mzxrun}.debug; then \
cp ${mzxrun}.debug ${build}; \
fi
ifeq (${BUILD_EDITOR},1)
${CP} assets/ascii.chr assets/blank.chr ${build}/assets
${CP} assets/smzx.chr ${build}/assets
${CP} ${mzx} ${build}
@if test -f ${mzx}.debug; then \
cp ${mzx}.debug ${build}; \
fi
endif
ifeq (${BUILD_HELPSYS},1)
${CP} assets/help.fil ${build}/assets
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} ${png2smzx} ${build}/utils
@if test -f ${checkres}.debug; then \
cp ${checkres}.debug ${downver}.debug ${build}/utils; \
cp ${hlp2txt}.debug ${txt2hlp}.debug ${build}/utils; \
cp ${png2smzx}.debug ${build}/utils; \
fi
endif
ifeq (${BUILD_RENDER_GL_PROGRAM},1)
${MKDIR} -p ${build}/assets/shaders/extra
${CP} assets/shaders/*.vert ${build}/assets/shaders
${CP} assets/shaders/*.frag ${build}/assets/shaders
${CP} assets/shaders/extra/*.frag assets/shaders/extra/README.txt \
${build}/assets/shaders/extra
endif
distclean: clean
@echo " DISTCLEAN"
@rm -f src/config.h
@echo "PLATFORM=none" > platform.inc
assets/help.fil: ${txt2hlp} docs/WIPHelp.txt
@src/utils/txt2hlp docs/WIPHelp.txt $@
help_check: ${hlp2txt} assets/help.fil
@src/utils/hlp2txt assets/help.fil help.txt
@diff -q docs/WIPHelp.txt help.txt
@rm -f help.txt
endif