Subversion Repositories eduke32

Rev

Rev 8569 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8569 Rev 8717
1
# OS package maintainers: Please try invoking make with PACKAGE_REPOSITORY=1 to see if that meets your needs before patching out our optimizations entirely.
1
# OS package maintainers: Please try invoking make with PACKAGE_REPOSITORY=1 to see if that meets your needs before patching out our optimizations entirely.
2
PACKAGE_REPOSITORY ?= 0
2
PACKAGE_REPOSITORY ?= 0
3
3
4
# Are we running from synthesis?
4
# Are we running from synthesis?
5
SYNTHESIS := 0
5
SYNTHESIS := 0
6
6
7
7
8
##### Makefile Swiss army knife
8
##### Makefile Swiss army knife
9
9
10
override empty :=
10
override empty :=
11
override space := $(empty) $(empty)
11
override space := $(empty) $(empty)
12
override comma := ,
12
override comma := ,
13
override paren_open := (
13
override paren_open := (
14
override paren_close := )
14
override paren_close := )
15
15
16
16
17
##### Detect platform
17
##### Detect platform
18
18
19
ifndef HOSTPLATFORM
19
ifndef HOSTPLATFORM
20
    HOSTPLATFORM := UNKNOWN
20
    HOSTPLATFORM := UNKNOWN
21
    ifeq ($(findstring Windows,$(OS)),Windows)
21
    ifeq ($(findstring Windows,$(OS)),Windows)
22
        HOSTPLATFORM := WINDOWS
22
        HOSTPLATFORM := WINDOWS
23
    else
23
    else
24
        uname := $(strip $(shell uname -s))
24
        uname := $(strip $(shell uname -s))
25
        ifeq ($(findstring Linux,$(uname)),Linux)
25
        ifeq ($(findstring Linux,$(uname)),Linux)
26
            HOSTPLATFORM := LINUX
26
            HOSTPLATFORM := LINUX
27
        else ifeq ($(findstring BSD,$(uname)),BSD)
27
        else ifeq ($(findstring BSD,$(uname)),BSD)
28
            HOSTPLATFORM := BSD
28
            HOSTPLATFORM := BSD
29
        else ifeq ($(findstring MINGW,$(uname)),MINGW)
29
        else ifeq ($(findstring MINGW,$(uname)),MINGW)
30
            HOSTPLATFORM := WINDOWS
30
            HOSTPLATFORM := WINDOWS
31
        else ifeq ($(findstring MSYS,$(uname)),MSYS)
31
        else ifeq ($(findstring MSYS,$(uname)),MSYS)
32
            HOSTPLATFORM := WINDOWS
32
            HOSTPLATFORM := WINDOWS
33
        else ifeq ($(findstring Darwin,$(uname)),Darwin)
33
        else ifeq ($(findstring Darwin,$(uname)),Darwin)
34
            HOSTPLATFORM := DARWIN
34
            HOSTPLATFORM := DARWIN
35
        else ifeq ($(findstring BeOS,$(uname)),BeOS)
35
        else ifeq ($(findstring BeOS,$(uname)),BeOS)
36
            HOSTPLATFORM := BEOS
36
            HOSTPLATFORM := BEOS
37
        else ifeq ($(findstring skyos,$(uname)),skyos)
37
        else ifeq ($(findstring skyos,$(uname)),skyos)
38
            HOSTPLATFORM := SKYOS
38
            HOSTPLATFORM := SKYOS
39
        else ifeq ($(findstring QNX,$(uname)),QNX)
39
        else ifeq ($(findstring QNX,$(uname)),QNX)
40
            HOSTPLATFORM := QNX
40
            HOSTPLATFORM := QNX
41
        else ifeq ($(findstring SunOS,$(uname)),SunOS)
41
        else ifeq ($(findstring SunOS,$(uname)),SunOS)
42
            HOSTPLATFORM := SUNOS
42
            HOSTPLATFORM := SUNOS
43
        else ifeq ($(findstring syllable,$(uname)),syllable)
43
        else ifeq ($(findstring syllable,$(uname)),syllable)
44
            HOSTPLATFORM := SYLLABLE
44
            HOSTPLATFORM := SYLLABLE
45
        endif
45
        endif
46
    endif
46
    endif
47
endif
47
endif
48
ifndef PLATFORM
48
ifndef PLATFORM
49
    PLATFORM := $(HOSTPLATFORM)
49
    PLATFORM := $(HOSTPLATFORM)
50
endif
50
endif
51
51
52
ifndef SUBPLATFORM
52
ifndef SUBPLATFORM
53
    SUBPLATFORM :=
53
    SUBPLATFORM :=
54
    ifeq ($(PLATFORM),$(filter $(PLATFORM),LINUX DINGOO GCW CAANOO))
54
    ifeq ($(PLATFORM),$(filter $(PLATFORM),LINUX DINGOO GCW CAANOO))
55
        SUBPLATFORM := LINUX
55
        SUBPLATFORM := LINUX
56
    endif
56
    endif
57
endif
57
endif
58
58
59
ifeq ($(HOSTPLATFORM),DARWIN)
59
ifeq ($(HOSTPLATFORM),DARWIN)
60
    DARWINVERSION := $(word 1,$(subst ., ,$(strip $(shell uname -r))))
60
    DARWINVERSION := $(word 1,$(subst ., ,$(strip $(shell uname -r))))
61
61
62
    DARWIN9 := 0
62
    DARWIN9 := 0
63
    DARWIN10 := 0
63
    DARWIN10 := 0
64
    ifneq (,$(filter 0 1 2 3 4 5 6 7 8 9 10,$(DARWINVERSION)))
64
    ifneq (,$(filter 0 1 2 3 4 5 6 7 8 9 10,$(DARWINVERSION)))
65
        DARWIN10 := 1
65
        DARWIN10 := 1
66
        ifneq (,$(filter 0 1 2 3 4 5 6 7 8 9,$(DARWINVERSION)))
66
        ifneq (,$(filter 0 1 2 3 4 5 6 7 8 9,$(DARWINVERSION)))
67
            DARWIN9 := 1
67
            DARWIN9 := 1
68
        endif
68
        endif
69
    endif
69
    endif
70
endif
70
endif
71
71
72
HOSTEXESUFFIX :=
72
HOSTEXESUFFIX :=
73
ifeq ($(HOSTPLATFORM),WINDOWS)
73
ifeq ($(HOSTPLATFORM),WINDOWS)
74
    HOSTEXESUFFIX := .exe
74
    HOSTEXESUFFIX := .exe
75
endif
75
endif
76
76
77
EXESUFFIX :=
77
EXESUFFIX :=
78
DLLSUFFIX := .so
78
DLLSUFFIX := .so
79
DOLSUFFIX := .dol
79
DOLSUFFIX := .dol
80
ifeq ($(PLATFORM),DARWIN)
80
ifeq ($(PLATFORM),DARWIN)
81
    DLLSUFFIX := .dylib
81
    DLLSUFFIX := .dylib
82
endif
82
endif
83
ifeq ($(PLATFORM),WII)
83
ifeq ($(PLATFORM),WII)
84
    EXESUFFIX := .elf
84
    EXESUFFIX := .elf
85
endif
85
endif
86
ifeq ($(PLATFORM),SKYOS)
86
ifeq ($(PLATFORM),SKYOS)
87
    EXESUFFIX := .app
87
    EXESUFFIX := .app
88
endif
88
endif
89
ifeq ($(PLATFORM),WINDOWS)
89
ifeq ($(PLATFORM),WINDOWS)
90
    EXESUFFIX := .exe
90
    EXESUFFIX := .exe
91
    DLLSUFFIX := .dll
91
    DLLSUFFIX := .dll
92
endif
92
endif
93
93
94
94
95
##### Makefile meta-settings
95
##### Makefile meta-settings
96
96
97
PRETTY_OUTPUT := 1
97
PRETTY_OUTPUT := 1
98
98
99
NULLSTREAM := /dev/null
99
NULLSTREAM := /dev/null
100
100
101
ifeq ($(HOSTPLATFORM),WINDOWS)
101
ifeq ($(HOSTPLATFORM),WINDOWS)
102
# MSYS2 lets you create files named NUL but has a /dev/null. Go figure.
102
# MSYS2 lets you create files named NUL but has a /dev/null. Go figure.
103
    ifeq (,$(wildcard /dev/null))
103
    ifeq (,$(wildcard /dev/null))
104
        NULLSTREAM := NUL
104
        NULLSTREAM := NUL
105
    endif
105
    endif
106
endif
106
endif
107
107
108
DONT_PRINT := > $(NULLSTREAM) 2>&1
108
DONT_PRINT := > $(NULLSTREAM) 2>&1
109
DONT_PRINT_STDERR := 2> $(NULLSTREAM)
109
DONT_PRINT_STDERR := 2> $(NULLSTREAM)
110
DONT_FAIL := ; exit 0
110
DONT_FAIL := ; exit 0
111
ESCAPE=\\
111
ESCAPE=\\
112
112
113
HAVE_SH := 1
113
HAVE_SH := 1
114
# when no sh.exe is found in PATH on Windows, no path is prepended to it
114
# when no sh.exe is found in PATH on Windows, no path is prepended to it
115
ifeq (sh.exe,$(SHELL))
115
ifeq (sh.exe,$(SHELL))
116
    HAVE_SH := 0
116
    HAVE_SH := 0
117
endif
117
endif
118
118
119
define LL
119
define LL
120
    ls -l $1
120
    ls -l $1
121
endef
121
endef
122
define MKDIR
122
define MKDIR
123
    mkdir -p $1
123
    mkdir -p $1
124
endef
124
endef
125
define RM
125
define RM
126
    rm -f $(filter-out / *,$1)
126
    rm -f $(filter-out / *,$1)
127
endef
127
endef
128
define RMDIR
128
define RMDIR
129
    rm -rf $(filter-out / *,$1)
129
    rm -rf $(filter-out / *,$1)
130
endef
130
endef
131
define CAT
131
define CAT
132
    cat $1
132
    cat $1
133
endef
133
endef
134
define RAW_ECHO
134
define RAW_ECHO
135
    echo '$1'
135
    echo '$1'
136
endef
136
endef
137
137
138
ifeq (0,$(HAVE_SH))
138
ifeq (0,$(HAVE_SH))
139
    DONT_FAIL := & rem
139
    DONT_FAIL := & rem
140
    ESCAPE=^
140
    ESCAPE=^
141
141
142
    define LL
142
    define LL
143
        dir $(subst /,\,$1)
143
        dir $(subst /,\,$1)
144
    endef
144
    endef
145
    define MKDIR
145
    define MKDIR
146
        if not exist $(subst /,\,$1) mkdir $(subst /,\,$1)
146
        if not exist $(subst /,\,$1) mkdir $(subst /,\,$1)
147
    endef
147
    endef
148
    define RM
148
    define RM
149
        del /f /q $(subst /,\,$(filter-out / *,$1)) $(DONT_PRINT_STDERR) $(DONT_FAIL)
149
        del /f /q $(subst /,\,$(filter-out / *,$1)) $(DONT_PRINT_STDERR) $(DONT_FAIL)
150
    endef
150
    endef
151
    define RMDIR
151
    define RMDIR
152
        rmdir /s /q $(subst /,\,$(filter-out / *,$1)) $(DONT_PRINT_STDERR) $(DONT_FAIL)
152
        rmdir /s /q $(subst /,\,$(filter-out / *,$1)) $(DONT_PRINT_STDERR) $(DONT_FAIL)
153
    endef
153
    endef
154
    define CAT
154
    define CAT
155
        type $(subst /,\,$1)
155
        type $(subst /,\,$1)
156
    endef
156
    endef
157
    define RAW_ECHO
157
    define RAW_ECHO
158
        echo $(subst ",$(ESCAPE)",$(subst $(paren_open),$(ESCAPE)$(paren_open),$(subst $(paren_close),$(ESCAPE)$(paren_close),$1)))
158
        echo $(subst ",$(ESCAPE)",$(subst $(paren_open),$(ESCAPE)$(paren_open),$(subst $(paren_close),$(ESCAPE)$(paren_close),$1)))
159
    endef
159
    endef
160
160
161
    # if, printf, exit, and ; are unavailable without sh
161
    # if, printf, exit, and ; are unavailable without sh
162
    PRETTY_OUTPUT := 0
162
    PRETTY_OUTPUT := 0
163
endif
163
endif
164
164
165
165
166
##### Toolchain setup
166
##### Toolchain setup
167
167
168
CROSS :=
168
CROSS :=
169
CROSS_SUFFIX :=
169
CROSS_SUFFIX :=
170
170
171
CCFULLPATH = $(CC)
171
CCFULLPATH = $(CC)
172
172
173
ifeq ($(PLATFORM),WII)
173
ifeq ($(PLATFORM),WII)
174
    ifeq ($(strip $(DEVKITPPC)),)
174
    ifeq ($(strip $(DEVKITPPC)),)
175
        $(error "Please set DEVKITPPC in your environment. export DEVKITPPC := <path to>devkitPPC")
175
        $(error "Please set DEVKITPPC in your environment. export DEVKITPPC := <path to>devkitPPC")
176
    endif
176
    endif
177
177
178
    ifeq ($(HOSTPLATFORM),WINDOWS)
178
    ifeq ($(HOSTPLATFORM),WINDOWS)
179
        override DEVKITPRO := $(subst /c/,C:/,$(DEVKITPRO))
179
        override DEVKITPRO := $(subst /c/,C:/,$(DEVKITPRO))
180
        override DEVKITPPC := $(subst /c/,C:/,$(DEVKITPPC))
180
        override DEVKITPPC := $(subst /c/,C:/,$(DEVKITPPC))
181
    endif
181
    endif
182
182
183
    export PATH := $(DEVKITPPC)/bin:$(PATH)
183
    export PATH := $(DEVKITPPC)/bin:$(PATH)
184
184
185
    CROSS := powerpc-eabi-
185
    CROSS := powerpc-eabi-
186
186
187
    CCFULLPATH = $(DEVKITPPC)/bin/$(CC)
187
    CCFULLPATH = $(DEVKITPPC)/bin/$(CC)
188
endif
188
endif
189
189
190
CC := $(CROSS)gcc$(CROSS_SUFFIX)
190
CC := $(CROSS)gcc$(CROSS_SUFFIX)
191
CXX := $(CROSS)g++$(CROSS_SUFFIX)
191
CXX := $(CROSS)g++$(CROSS_SUFFIX)
192
192
193
ifeq ($(PLATFORM),DARWIN)
193
ifeq ($(PLATFORM),DARWIN)
194
    CC := $(CROSS)clang$(CROSS_SUFFIX)
194
    CC := $(CROSS)clang$(CROSS_SUFFIX)
195
    CXX := $(CROSS)clang++$(CROSS_SUFFIX)
195
    CXX := $(CROSS)clang++$(CROSS_SUFFIX)
196
endif
196
endif
197
197
198
COBJC := $(CC) -x objective-c
198
COBJC := $(CC) -x objective-c
199
COBJCXX := $(CXX) -x objective-c++
199
COBJCXX := $(CXX) -x objective-c++
200
L_CC := $(CC)
200
L_CC := $(CC)
201
L_CXX := $(CXX)
201
L_CXX := $(CXX)
202
202
203
AR := $(CROSS)ar$(CROSS_SUFFIX)
203
AR := $(CROSS)ar$(CROSS_SUFFIX)
204
RC := $(CROSS)windres$(CROSS_SUFFIX)
204
RC := $(CROSS)windres$(CROSS_SUFFIX)
205
RANLIB := $(CROSS)ranlib$(CROSS_SUFFIX)
205
RANLIB := $(CROSS)ranlib$(CROSS_SUFFIX)
206
STRIP := $(CROSS)strip$(CROSS_SUFFIX)
206
STRIP := $(CROSS)strip$(CROSS_SUFFIX)
207
207
208
AS := nasm
208
AS := nasm
209
209
210
# LuaJIT standalone interpreter executable:
210
# LuaJIT standalone interpreter executable:
211
LUAJIT := luajit$(HOSTEXESUFFIX)
211
LUAJIT := luajit$(HOSTEXESUFFIX)
212
212
213
PKG_CONFIG := pkg-config
213
PKG_CONFIG := pkg-config
214
214
215
ELF2DOL := elf2dol
215
ELF2DOL := elf2dol
216
216
217
# Override defaults that absolutely will not work.
217
# Override defaults that absolutely will not work.
218
ifeq ($(CC),cc)
218
ifeq ($(CC),cc)
219
    override CC := gcc
219
    override CC := gcc
220
endif
220
endif
221
ifeq ($(AS),as)
221
ifeq ($(AS),as)
222
    override AS := nasm
222
    override AS := nasm
223
endif
223
endif
224
224
225
ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW))
225
ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW))
226
    CROSS := mipsel-linux-
226
    CROSS := mipsel-linux-
227
endif
227
endif
228
228
229
CLANG := 0
229
CLANG := 0
230
ifeq ($(findstring clang,$(CC) $(MAKECMDGOALS)),clang)
230
ifeq ($(findstring clang,$(CC) $(MAKECMDGOALS)),clang)
231
    override CLANG := 1
231
    override CLANG := 1
232
    CLANGNAME := $(CC)
232
    CLANGNAME := $(CC)
233
else
233
else
234
    CLANGNAME := clang
234
    CLANGNAME := clang
235
endif
235
endif
236
# detect clang symlinked as gcc, as in OS X
236
# detect clang symlinked as gcc, as in OS X
237
CLANG_POTENTIAL_VERSION := $(shell $(CCFULLPATH) --version)
237
CLANG_POTENTIAL_VERSION := $(shell $(CCFULLPATH) --version)
238
ifeq ($(findstring clang,$(CLANG_POTENTIAL_VERSION)),clang)
238
ifeq ($(findstring clang,$(CLANG_POTENTIAL_VERSION)),clang)
239
    override CLANG := 1
239
    override CLANG := 1
240
    ifeq ($(findstring Apple,$(CLANG_POTENTIAL_VERSION)),Apple)
240
    ifeq ($(findstring Apple,$(CLANG_POTENTIAL_VERSION)),Apple)
241
        override APPLE_CLANG := 1
241
        override APPLE_CLANG := 1
242
        APPLE_CLANG_VER := $(word 4,$(CLANG_POTENTIAL_VERSION))
242
        APPLE_CLANG_VER := $(word 4,$(CLANG_POTENTIAL_VERSION))
243
        override APPLE_CLANG_VER_SPLIT := $(subst ., ,$(APPLE_CLANG_VER))
243
        override APPLE_CLANG_VER_SPLIT := $(subst ., ,$(APPLE_CLANG_VER))
244
        APPLE_CLANG_MAJOR := $(word 1,$(APPLE_CLANG_VER_SPLIT))
244
        APPLE_CLANG_MAJOR := $(word 1,$(APPLE_CLANG_VER_SPLIT))
245
        APPLE_CLANG_MINOR := $(word 2,$(APPLE_CLANG_VER_SPLIT))
245
        APPLE_CLANG_MINOR := $(word 2,$(APPLE_CLANG_VER_SPLIT))
246
    else
246
    else
247
        CLANG_VER := $(word 3,$(CLANG_POTENTIAL_VERSION))
247
        CLANG_VER := $(word 3,$(CLANG_POTENTIAL_VERSION))
248
        override CLANG_VER_SPLIT := $(subst ., ,$(CLANG_VER))
248
        override CLANG_VER_SPLIT := $(subst ., ,$(CLANG_VER))
249
        CLANG_MAJOR := $(word 1,$(CLANG_VER_SPLIT))
249
        CLANG_MAJOR := $(word 1,$(CLANG_VER_SPLIT))
250
        CLANG_MINOR := $(word 2,$(CLANG_VER_SPLIT))
250
        CLANG_MINOR := $(word 2,$(CLANG_VER_SPLIT))
251
    endif
251
    endif
252
endif
252
endif
253
253
254
ifneq (0,$(CLANG))
254
ifneq (0,$(CLANG))
255
    CLANGXXNAME := $(subst clang,clang++,$(CLANGNAME))
255
    CLANGXXNAME := $(subst clang,clang++,$(CLANGNAME))
256
    override CC := $(CLANGNAME) -x c
256
    override CC := $(CLANGNAME) -x c
257
    override CXX := $(CLANGXXNAME) -x c++
257
    override CXX := $(CLANGXXNAME) -x c++
258
    override COBJC := $(CLANGNAME) -x objective-c
258
    override COBJC := $(CLANGNAME) -x objective-c
259
    override COBJCXX := $(CLANGXXNAME) -x objective-c++
259
    override COBJCXX := $(CLANGXXNAME) -x objective-c++
260
    override L_CC := $(CLANGNAME)
260
    override L_CC := $(CLANGNAME)
261
    override L_CXX := $(CLANGXXNAME)
261
    override L_CXX := $(CLANGXXNAME)
262
endif
262
endif
263
263
264
GCC_VER :=
264
GCC_VER :=
265
ifeq (0,$(CLANG))
265
ifeq (0,$(CLANG))
266
    GCC_VER := $(strip $(shell $(CCFULLPATH) -dumpversion 2>&1))
266
    GCC_VER := $(strip $(shell $(CCFULLPATH) -dumpversion 2>&1))
267
endif
267
endif
268
ifeq (,$(GCC_VER))
268
ifeq (,$(GCC_VER))
269
    GCC_VER := 4.9.0
269
    GCC_VER := 4.9.0
270
endif
270
endif
271
override GCC_VER_SPLIT := $(subst ., ,$(GCC_VER))
271
override GCC_VER_SPLIT := $(subst ., ,$(GCC_VER))
272
GCC_MAJOR := $(word 1,$(GCC_VER_SPLIT))
272
GCC_MAJOR := $(word 1,$(GCC_VER_SPLIT))
273
GCC_MINOR := $(word 2,$(GCC_VER_SPLIT))
273
GCC_MINOR := $(word 2,$(GCC_VER_SPLIT))
274
274
275
GCC_PREREQ_4 := 1
275
GCC_PREREQ_4 := 1
276
276
277
ifneq (,$(filter 1 2 3,$(GCC_MAJOR)))
277
ifneq (,$(filter 1 2 3,$(GCC_MAJOR)))
278
    ifeq (0,$(CLANG))
278
    ifeq (0,$(CLANG))
279
        GCC_PREREQ_4 := 0
279
        GCC_PREREQ_4 := 0
280
        $(error How do you still have an old GCC in $$(CURRENT_YEAR)?)
280
        $(error How do you still have an old GCC in $$(CURRENT_YEAR)?)
281
    endif
281
    endif
282
endif
282
endif
283
283
284
284
285
##### Detect machine architecture
285
##### Detect machine architecture
286
286
287
BITS := 32
287
BITS := 32
288
288
289
ifeq ($(PLATFORM),WINDOWS)
289
ifeq ($(PLATFORM),WINDOWS)
290
    ifndef COMPILERTARGET
290
    ifndef COMPILERTARGET
291
        COMPILERTARGET := $(strip $(shell $(CC) -dumpmachine))
291
        COMPILERTARGET := $(strip $(shell $(CC) -dumpmachine))
292
    endif
292
    endif
293
293
294
    IMPLICIT_ARCH := i386
294
    IMPLICIT_ARCH := i386
295
    ifeq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
295
    ifeq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
296
        IMPLICIT_ARCH := x86_64
296
        IMPLICIT_ARCH := x86_64
297
        BITS := 64
297
        BITS := 64
298
    endif
298
    endif
299
else ifeq ($(PLATFORM),WII)
299
else ifeq ($(PLATFORM),WII)
300
    IMPLICIT_ARCH := ppc
300
    IMPLICIT_ARCH := ppc
301
else
301
else
302
    ifneq ($(ARCH),)
302
    ifneq ($(ARCH),)
303
        override ARCH := $(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(strip $(ARCH)))))
303
        override ARCH := $(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(strip $(ARCH)))))
304
        IMPLICIT_ARCH := $(ARCH)
304
        IMPLICIT_ARCH := $(ARCH)
305
    else
305
    else
306
        IMPLICIT_ARCH := $(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(strip $(shell uname -m)))))
306
        IMPLICIT_ARCH := $(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(strip $(shell uname -m)))))
307
    endif
307
    endif
308
308
309
    ifeq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
309
    ifeq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
310
        BITS := 64
310
        BITS := 64
311
    endif
311
    endif
312
endif
312
endif
313
313
314
314
315
##### Toggles
315
##### Toggles
316
316
317
#  CPLUSPLUS - 1 := enable C++ building
317
#  CPLUSPLUS - 1 := enable C++ building
318
#  RELEASE - 1 := no debugging
318
#  RELEASE - 1 := no debugging
319
#  FORCEDEBUG:
319
#  FORCEDEBUG:
320
#    1 := Include debug symbols even when generating release code.
320
#    1 := Include debug symbols even when generating release code.
321
#    2 := Also enable sanitizers with Clang. On the C side, make 'sprite' etc. be real arrays.
321
#    2 := Also enable sanitizers with Clang. On the C side, make 'sprite' etc. be real arrays.
322
#  KRANDDEBUG - 1 := include logging of krand() calls for debugging the demo system
322
#  KRANDDEBUG - 1 := include logging of krand() calls for debugging the demo system
323
#  MEMMAP - 1 := produce .memmap file when linking
323
#  MEMMAP - 1 := produce .memmap file when linking
324
#  OPTLEVEL - 0..3 := GCC optimization strategy
324
#  OPTLEVEL - 0..3 := GCC optimization strategy
325
#  LTO - 1 := enable link-time optimization
325
#  LTO - 1 := enable link-time optimization
326
326
327
# Optional overrides for text
327
# Optional overrides for text
328
APPNAME ?=
328
APPNAME ?=
329
APPBASENAME ?=
329
APPBASENAME ?=
330
330
331
# Build toggles
331
# Build toggles
332
RELEASE := 1
332
RELEASE := 1
333
NOASM := 0
333
NOASM := 0
334
# EXPERIMENTAL, unfinished x86_64 assembly routines. DO NOT ENABLE.
334
# EXPERIMENTAL, unfinished x86_64 assembly routines. DO NOT ENABLE.
335
USE_ASM64 := 0
335
USE_ASM64 := 0
336
MEMMAP := 0
336
MEMMAP := 0
337
CPLUSPLUS := 1
337
CPLUSPLUS := 1
338
338
339
# Feature toggles
339
# Feature toggles
340
STANDALONE ?= 0
340
STANDALONE ?= 0
341
NETCODE ?= 1
341
NETCODE ?= 1
342
STARTUP_WINDOW ?= 1
342
STARTUP_WINDOW ?= 1
343
RETAIL_MENU ?= 0
343
RETAIL_MENU ?= 0
344
POLYMER ?= 1
344
POLYMER ?= 1
345
USE_OPENGL := 1
345
USE_OPENGL := 1
346
LUNATIC := 0
346
LUNATIC := 0
347
USE_LUAJIT_2_1 := 0
347
USE_LUAJIT_2_1 := 0
348
348
349
# Library toggles
349
# Library toggles
350
HAVE_GTK2 := 1
350
HAVE_GTK2 := 1
351
USE_LIBVPX ?= 1
351
USE_LIBVPX ?= 1
352
HAVE_VORBIS := 1
352
HAVE_VORBIS := 1
353
HAVE_FLAC := 1
353
HAVE_FLAC := 1
354
HAVE_XMP := 1
354
HAVE_XMP := 1
355
RENDERTYPE := SDL
355
RENDERTYPE := SDL
356
SDL_TARGET := 2
356
SDL_TARGET := 2
357
USE_PHYSFS := 0
357
USE_PHYSFS := 0
358
358
359
ifneq (0,$(USE_PHYSFS))
359
ifneq (0,$(USE_PHYSFS))
360
    # PhysFS requires this to be off
360
    # PhysFS requires this to be off
361
    override CPLUSPLUS := 0
361
    override CPLUSPLUS := 0
362
endif
362
endif
363
363
364
# Debugging/Build options
364
# Debugging/Build options
365
FORCEDEBUG := 0
365
FORCEDEBUG := 0
366
KRANDDEBUG := 0
366
KRANDDEBUG := 0
367
PROFILER := 0
367
PROFILER := 0
368
# Make allocache() a wrapper around malloc()? Useful for debugging
368
# Make allocache() a wrapper around malloc()? Useful for debugging
369
# allocache()-allocated memory accesses with e.g. Valgrind.
369
# allocache()-allocated memory accesses with e.g. Valgrind.
370
# For debugging with Valgrind + GDB, see
370
# For debugging with Valgrind + GDB, see
371
# http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver
371
# http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver
372
ALLOCACHE_AS_MALLOC := 0
372
ALLOCACHE_AS_MALLOC := 0
373
373
374
374
375
##### Settings overrides and implicit cascades
375
##### Settings overrides and implicit cascades
376
376
377
ifneq (0,$(KRANDDEBUG))
377
ifneq (0,$(KRANDDEBUG))
378
    RELEASE := 0
378
    RELEASE := 0
379
endif
379
endif
380
ifneq (100,$(RELEASE)$(PROFILER)$(ALLOCACHE_AS_MALLOC))
380
ifneq (100,$(RELEASE)$(PROFILER)$(ALLOCACHE_AS_MALLOC))
381
    # so that we have debug symbols
381
    # so that we have debug symbols
382
    FORCEDEBUG := 1
382
    FORCEDEBUG := 1
383
endif
383
endif
384
384
385
ifeq ($(PLATFORM),WINDOWS)
385
ifeq ($(PLATFORM),WINDOWS)
386
    override HAVE_GTK2 := 0
386
    override HAVE_GTK2 := 0
387
else ifeq ($(PLATFORM),DARWIN)
387
else ifeq ($(PLATFORM),DARWIN)
388
    HAVE_GTK2 := 0
388
    HAVE_GTK2 := 0
389
else ifeq ($(PLATFORM),WII)
389
else ifeq ($(PLATFORM),WII)
390
    override USE_OPENGL := 0
390
    override USE_OPENGL := 0
391
    override NETCODE := 0
391
    override NETCODE := 0
392
    override HAVE_GTK2 := 0
392
    override HAVE_GTK2 := 0
393
    override HAVE_FLAC := 0
393
    override HAVE_FLAC := 0
394
    SDL_TARGET := 1
394
    SDL_TARGET := 1
395
else ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW QNX SUNOS SYLLABLE))
395
else ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW QNX SUNOS SYLLABLE))
396
    override USE_OPENGL := 0
396
    override USE_OPENGL := 0
397
    override NOASM := 1
397
    override NOASM := 1
398
else ifeq ($(PLATFORM),$(filter $(PLATFORM),BEOS SKYOS))
398
else ifeq ($(PLATFORM),$(filter $(PLATFORM),BEOS SKYOS))
399
    override NOASM := 1
399
    override NOASM := 1
400
endif
400
endif
401
401
402
ifneq (i386,$(strip $(IMPLICIT_ARCH)))
402
ifneq (i386,$(strip $(IMPLICIT_ARCH)))
403
    override NOASM := 1
403
    override NOASM := 1
404
endif
404
endif
405
405
406
ifeq (0,$(USE_OPENGL))
406
ifeq (0,$(USE_OPENGL))
407
    override POLYMER := 0
407
    override POLYMER := 0
408
    override USE_LIBVPX := 0
408
    override USE_LIBVPX := 0
409
endif
409
endif
410
410
411
ifeq ($(RELEASE),0)
411
ifeq ($(RELEASE),0)
412
    override STRIP :=
412
    override STRIP :=
413
endif
413
endif
414
ifneq ($(FORCEDEBUG),0)
414
ifneq ($(FORCEDEBUG),0)
415
    override STRIP :=
415
    override STRIP :=
416
endif
416
endif
417
417
418
DBGLEVEL :=
418
DBGLEVEL :=
419
ifeq ($(RELEASE),0)
419
ifeq ($(RELEASE),0)
420
    OPTLEVEL := 0
420
    OPTLEVEL := 0
421
421
422
    # see if we can use -Og
422
    # see if we can use -Og
423
    ifeq (1,$(APPLE_CLANG))
423
    ifeq (1,$(APPLE_CLANG))
424
      # Apple clang >= 9.0
424
      # Apple clang >= 9.0
425
      ifeq (,$(filter 0 1 2 3 4 5 6 7 8,$(APPLE_CLANG_MAJOR)))
425
      ifeq (,$(filter 0 1 2 3 4 5 6 7 8,$(APPLE_CLANG_MAJOR)))
426
        OPTLEVEL := g
426
        OPTLEVEL := g
427
      endif
427
      endif
428
    else ifeq (1,$(CLANG))
428
    else ifeq (1,$(CLANG))
429
      # clang >= 4.0
429
      # clang >= 4.0
430
      ifeq (,$(filter 0 1 2 3,$(CLANG_MAJOR)))
430
      ifeq (,$(filter 0 1 2 3,$(CLANG_MAJOR)))
431
        OPTLEVEL := g
431
        OPTLEVEL := g
432
      endif
432
      endif
433
    else
433
    else
434
      # GCC >= 4.8
434
      # GCC >= 4.8
435
      ifeq (,$(filter 0 1 2 3 4,$(GCC_MAJOR)))
435
      ifeq (,$(filter 0 1 2 3 4,$(GCC_MAJOR)))
436
        OPTLEVEL := g
436
        OPTLEVEL := g
437
      else ifeq (4,$(GCC_MAJOR))
437
      else ifeq (4,$(GCC_MAJOR))
438
        ifeq (,$(filter 0 1 2 3 4 5 6 7,$(GCC_MINOR)))
438
        ifeq (,$(filter 0 1 2 3 4 5 6 7,$(GCC_MINOR)))
439
          OPTLEVEL := g
439
          OPTLEVEL := g
440
        endif
440
        endif
441
      endif
441
      endif
442
    endif
442
    endif
443
443
444
    LTO := 0
444
    LTO := 0
445
else
445
else
446
    OPTLEVEL := 2
446
    OPTLEVEL := 2
447
    LTO := 1
447
    LTO := 1
448
endif
448
endif
449
449
450
ifneq (0,$(CLANG))
450
ifneq (0,$(CLANG))
451
    ifeq ($(PLATFORM),WINDOWS)
451
    ifeq ($(PLATFORM),WINDOWS)
452
        LTO := 0
452
        LTO := 0
453
    endif
453
    endif
454
endif
454
endif
455
ifneq ($(LUNATIC),0)
455
ifneq ($(LUNATIC),0)
456
    # FIXME: Lunatic builds with LTO don't start up properly as the required
456
    # FIXME: Lunatic builds with LTO don't start up properly as the required
457
    # symbol names are apparently not exported.
457
    # symbol names are apparently not exported.
458
    override LTO := 0
458
    override LTO := 0
459
endif
459
endif
460
ifeq (0,$(CLANG))
460
ifeq (0,$(CLANG))
461
    ifeq (0,$(GCC_PREREQ_4))
461
    ifeq (0,$(GCC_PREREQ_4))
462
        override LTO := 0
462
        override LTO := 0
463
    endif
463
    endif
464
    ifeq (4,$(GCC_MAJOR))
464
    ifeq (4,$(GCC_MAJOR))
465
        ifeq ($(PLATFORM),WII)
465
        ifeq ($(PLATFORM),WII)
466
            ifneq (,$(filter 0 1 2 3 4 5 6 7,$(GCC_MINOR)))
466
            ifneq (,$(filter 0 1 2 3 4 5 6 7,$(GCC_MINOR)))
467
                override LTO := 0
467
                override LTO := 0
468
            endif
468
            endif
469
        else
469
        else
470
            ifneq (,$(filter 0 1 2 3 4 5,$(GCC_MINOR)))
470
            ifneq (,$(filter 0 1 2 3 4 5,$(GCC_MINOR)))
471
                override LTO := 0
471
                override LTO := 0
472
            endif
472
            endif
473
        endif
473
        endif
474
    endif
474
    endif
475
endif
475
endif
476
476
477
477
478
########## End Toggles, Begin Construction ##########
478
########## End Toggles, Begin Construction ##########
479
479
480
480
481
##### Instantiate variables
481
##### Instantiate variables
482
482
483
COMMONFLAGS :=
483
COMMONFLAGS :=
484
COMPILERFLAGS := -funsigned-char
484
COMPILERFLAGS := -funsigned-char
485
485
486
CSTD := -std=gnu99
486
CSTD := -std=gnu99
487
CXXSTD := -std=gnu++11
487
CXXSTD := -std=gnu++11
488
ifneq (0,$(CLANG))
488
ifneq (0,$(CLANG))
489
    CSTD := $(subst gnu,c,$(CSTD))
489
    CSTD := $(subst gnu,c,$(CSTD))
490
    CXXSTD := $(subst gnu,c,$(CXXSTD))
490
    CXXSTD := $(subst gnu,c,$(CXXSTD))
491
endif
491
endif
492
CONLYFLAGS := $(CSTD)
492
CONLYFLAGS := $(CSTD)
493
CXXONLYFLAGS := $(CXXSTD) -fno-exceptions -fno-rtti
493
CXXONLYFLAGS := $(CXXSTD) -fno-exceptions -fno-rtti
494
494
495
ASFLAGS := -s #-g
495
ASFLAGS := -s #-g
496
496
497
LUAJIT_BCOPTS :=
497
LUAJIT_BCOPTS :=
498
498
499
LINKERFLAGS :=
499
LINKERFLAGS :=
500
L_CXXONLYFLAGS :=
500
L_CXXONLYFLAGS :=
501
501
502
LIBS :=
502
LIBS :=
503
GUI_LIBS :=
503
GUI_LIBS :=
504
LIBDIRS :=
504
LIBDIRS :=
505
505
506
506
507
##### Mandatory platform parameters
507
##### Mandatory platform parameters
508
508
509
ASFORMAT := elf$(BITS)
509
ASFORMAT := elf$(BITS)
510
# Options to "luajit -b" for synthesis. Since it runs on Linux, we need to tell
510
# Options to "luajit -b" for synthesis. Since it runs on Linux, we need to tell
511
# the native LuaJIT to emit PE object files.
511
# the native LuaJIT to emit PE object files.
512
ifeq ($(PLATFORM),WINDOWS)
512
ifeq ($(PLATFORM),WINDOWS)
513
    LINKERFLAGS += -static-libgcc -static
513
    LINKERFLAGS += -static-libgcc -static
514
    ifeq (0,$(CLANG))
514
    ifeq (0,$(CLANG))
515
        L_CXXONLYFLAGS += -static-libstdc++
515
        L_CXXONLYFLAGS += -static-libstdc++
516
    endif
516
    endif
517
517
518
    ifeq (0,$(CLANG))
518
    ifeq (0,$(CLANG))
519
        GUI_LIBS += -mwindows
519
        GUI_LIBS += -mwindows
520
    endif
520
    endif
521
521
522
    COMPILERFLAGS += -DUNDERSCORES
522
    COMPILERFLAGS += -DUNDERSCORES
523
    ASFORMAT := win$(BITS)
523
    ASFORMAT := win$(BITS)
524
    ASFLAGS += -DUNDERSCORES
524
    ASFLAGS += -DUNDERSCORES
525
525
526
    ifneq ($(RELEASE),0)
526
    ifneq ($(RELEASE),0)
527
        ifeq ($(FORCEDEBUG),0)
527
        ifeq ($(FORCEDEBUG),0)
528
            DYNAMICBASE := ,--dynamicbase
528
            DYNAMICBASE := ,--dynamicbase
529
        endif
529
        endif
530
    endif
530
    endif
531
    LINKERFLAGS += -Wl,--enable-auto-import,--nxcompat$(DYNAMICBASE)
531
    LINKERFLAGS += -Wl,--enable-auto-import,--nxcompat$(DYNAMICBASE)
532
    ifneq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
532
    ifneq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
533
        LINKERFLAGS += -Wl,--large-address-aware
533
        LINKERFLAGS += -Wl,--large-address-aware
534
    else
534
    else
535
        LINKERFLAGS += -Wl,--high-entropy-va
535
        LINKERFLAGS += -Wl,--high-entropy-va
536
    endif
536
    endif
537
537
538
    LUAJIT_BCOPTS := -o windows
538
    LUAJIT_BCOPTS := -o windows
539
    ifeq (32,$(BITS))
539
    ifeq (32,$(BITS))
540
        LUAJIT_BCOPTS += -a x86
540
        LUAJIT_BCOPTS += -a x86
541
    endif
541
    endif
542
    ifeq (64,$(BITS))
542
    ifeq (64,$(BITS))
543
        LUAJIT_BCOPTS += -a x64
543
        LUAJIT_BCOPTS += -a x64
544
    endif
544
    endif
545
else ifeq ($(PLATFORM),DARWIN)
545
else ifeq ($(PLATFORM),DARWIN)
546
    ifneq ($(ARCH),)
546
    ifneq ($(ARCH),)
547
        ifneq ($(findstring -arch,$(ARCH)),-arch)
547
        ifneq ($(findstring -arch,$(ARCH)),-arch)
548
            override ARCH := -arch $(ARCH)
548
            override ARCH := -arch $(ARCH)
549
        endif
549
        endif
550
    endif
550
    endif
551
    COMMONFLAGS += $(ARCH)
551
    COMMONFLAGS += $(ARCH)
552
552
553
    ifneq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
553
    ifneq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
554
        LINKERFLAGS += -read_only_relocs suppress
554
        LINKERFLAGS += -read_only_relocs suppress
555
    endif
555
    endif
556
556
557
    COMPILERFLAGS += -DUNDERSCORES
557
    COMPILERFLAGS += -DUNDERSCORES
558
    ASFORMAT := macho
558
    ASFORMAT := macho
559
    ASFLAGS += -DUNDERSCORES
559
    ASFLAGS += -DUNDERSCORES
560
560
561
    ifeq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
561
    ifeq ($(findstring x86_64,$(IMPLICIT_ARCH)),x86_64)
562
        ASFORMAT += 64
562
        ASFORMAT += 64
563
    endif
563
    endif
564
else ifeq ($(PLATFORM),WII)
564
else ifeq ($(PLATFORM),WII)
565
    LIBOGC_INC := $(DEVKITPRO)/libogc/include
565
    LIBOGC_INC := $(DEVKITPRO)/libogc/include
566
    LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
566
    LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
567
567
568
    COMMONFLAGS += -mrvl -mcpu=750 -meabi -mhard-float
568
    COMMONFLAGS += -mrvl -mcpu=750 -meabi -mhard-float
569
    LINKERFLAGS += -Wl,--gc-sections
569
    LINKERFLAGS += -Wl,--gc-sections
570
    # -msdata=eabiexport
570
    # -msdata=eabiexport
571
    COMPILERFLAGS += -DGEKKO -D__POWERPC__ -I$(LIBOGC_INC)
571
    COMPILERFLAGS += -DGEKKO -D__POWERPC__ -I$(LIBOGC_INC)
572
    LIBDIRS += -L$(LIBOGC_LIB)
572
    LIBDIRS += -L$(LIBOGC_LIB)
573
else ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW))
573
else ifeq ($(PLATFORM),$(filter $(PLATFORM),DINGOO GCW))
574
    COMPILERFLAGS += -D__OPENDINGUX__
574
    COMPILERFLAGS += -D__OPENDINGUX__
575
else ifeq ($(PLATFORM),SKYOS)
575
else ifeq ($(PLATFORM),SKYOS)
576
    COMPILERFLAGS += -DUNDERSCORES
576
    COMPILERFLAGS += -DUNDERSCORES
577
else ifeq ($(SUBPLATFORM),LINUX)
577
else ifeq ($(SUBPLATFORM),LINUX)
578
    # Locate .so files
578
    # Locate .so files
579
    LINKERFLAGS += -Wl,-rpath,'$$ORIGIN' -Wl,-z,origin
579
    LINKERFLAGS += -Wl,-rpath,'$$ORIGIN' -Wl,-z,origin
580
endif
580
endif
581
ASFLAGS += -f $(ASFORMAT)
581
ASFLAGS += -f $(ASFORMAT)
582
582
583
COMPILERFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
583
COMPILERFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
584
584
585
585
586
##### Optimizations
586
##### Optimizations
587
587
588
ifndef OPTOPT
588
ifndef OPTOPT
589
    ifeq ($(findstring x86_64, $(IMPLICIT_ARCH)),x86_64)
589
    ifeq ($(findstring x86_64, $(IMPLICIT_ARCH)),x86_64)
590
        ifeq ($(findstring x86_64h, $(IMPLICIT_ARCH)),x86_64h)
590
        ifeq ($(findstring x86_64h, $(IMPLICIT_ARCH)),x86_64h)
591
            OPTOPT := -march=haswell -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mpopcnt -mpclmul -mavx -mrdrnd -mf16c -mfsgsbase -mavx2 -maes -mfma -mbmi -mbmi2
591
            OPTOPT := -march=haswell -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mpopcnt -mpclmul -mavx -mrdrnd -mf16c -mfsgsbase -mavx2 -maes -mfma -mbmi -mbmi2
592
            # -mcrc32 -mmovbe
592
            # -mcrc32 -mmovbe
593
        else
593
        else
594
            ifeq ($(PLATFORM),DARWIN)
594
            ifeq ($(PLATFORM),DARWIN)
595
                OPTOPT := -march=core2 -mmmx -msse -msse2 -msse3 -mssse3
595
                OPTOPT := -march=core2 -mmmx -msse -msse2 -msse3 -mssse3
596
            else
596
            else
597
                OPTOPT := -march=nocona
597
                OPTOPT := -march=nocona
598
            endif
598
            endif
599
        endif
599
        endif
600
    endif
600
    endif
601
    ifeq ($(findstring i386, $(IMPLICIT_ARCH)),i386)
601
    ifeq ($(findstring i386, $(IMPLICIT_ARCH)),i386)
602
        ifeq ($(PLATFORM),DARWIN)
602
        ifeq ($(PLATFORM),DARWIN)
603
            OPTOPT := -march=nocona -mmmx -msse -msse2 -msse3
603
            OPTOPT := -march=nocona -mmmx -msse -msse2 -msse3
604
        else
604
        else
605
            USE_SSE2 := 0
605
            USE_SSE2 := 0
606
            ifneq (0,$(USE_SSE2))
606
            ifneq (0,$(USE_SSE2))
607
                OPTOPT := -march=pentium-m
607
                OPTOPT := -march=pentium-m
608
            else
608
            else
609
                OPTOPT := -march=pentium3
609
                OPTOPT := -march=pentium3
610
            endif
610
            endif
611
            ifneq (0,$(GCC_PREREQ_4))
611
            ifneq (0,$(GCC_PREREQ_4))
612
                OPTOPT += -mtune=generic
612
                OPTOPT += -mtune=generic
613
                # -mstackrealign
613
                # -mstackrealign
614
            endif
614
            endif
615
            OPTOPT += -mmmx -msse -mfpmath=sse
615
            OPTOPT += -mmmx -msse -mfpmath=sse
616
            ifneq (0,$(USE_SSE2))
616
            ifneq (0,$(USE_SSE2))
617
                OPTOPT += -msse2
617
                OPTOPT += -msse2
618
            endif
618
            endif
619
        endif
619
        endif
620
    endif
620
    endif
621
    ifeq ($(PLATFORM),WII)
621
    ifeq ($(PLATFORM),WII)
622
        OPTOPT := -mtune=750
622
        OPTOPT := -mtune=750
623
    endif
623
    endif
624
endif
624
endif
625
625
626
ifeq ($(PACKAGE_REPOSITORY),0)
626
ifeq ($(PACKAGE_REPOSITORY),0)
627
    COMMONFLAGS += -O$(OPTLEVEL) $(OPTOPT)
627
    COMMONFLAGS += -O$(OPTLEVEL) $(OPTOPT)
628
endif
628
endif
629
629
630
ifneq (0,$(LTO))
630
ifneq (0,$(LTO))
631
    COMPILERFLAGS += -DUSING_LTO
631
    COMPILERFLAGS += -DUSING_LTO
632
    COMMONFLAGS += -flto
632
    COMMONFLAGS += -flto
633
endif
633
endif
634
634
635
635
636
##### Debugging
636
##### Debugging
637
637
638
ifneq ($(RELEASE)$(FORCEDEBUG),10)
638
ifneq ($(RELEASE)$(FORCEDEBUG),10)
639
    ifeq ($(PACKAGE_REPOSITORY),0)
639
    ifeq ($(PACKAGE_REPOSITORY),0)
640
        COMMONFLAGS += -g$(DBGLEVEL)
640
        COMMONFLAGS += -g$(DBGLEVEL)
641
        ifeq (0,$(CLANG))
641
        ifeq (0,$(CLANG))
642
            ifneq ($(PLATFORM),WII)
642
            ifneq ($(PLATFORM),WII)
643
                COMMONFLAGS += -fno-omit-frame-pointer
643
                COMMONFLAGS += -fno-omit-frame-pointer
644
            endif
644
            endif
645
        endif
645
        endif
646
    endif
646
    endif
647
    ifeq ($(SUBPLATFORM),LINUX)
647
    ifeq ($(SUBPLATFORM),LINUX)
648
        # This option is needed to allow obtaining backtraces from within a program.
648
        # This option is needed to allow obtaining backtraces from within a program.
649
        LIBS += -rdynamic
649
        LIBS += -rdynamic
650
    endif
650
    endif
651
endif
651
endif
652
652
653
ifneq ($(ALLOCACHE_AS_MALLOC),0)
653
ifneq ($(ALLOCACHE_AS_MALLOC),0)
654
    COMPILERFLAGS += -DDEBUG_ALLOCACHE_AS_MALLOC
654
    COMPILERFLAGS += -DDEBUG_ALLOCACHE_AS_MALLOC
655
endif
655
endif
656
656
657
# See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
657
# See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
658
# and https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
658
# and https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
659
# for a list of possible ASan and UBsan options.
659
# for a list of possible ASan and UBsan options.
660
660
661
ASAN_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow
661
ASAN_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow
662
ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow,unsigned-integer-overflow
662
ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow,unsigned-integer-overflow
663
ASAN_FLAGS := $(ASAN_FLAGS),undefined,return,null,pointer-overflow,float-divide-by-zero
663
ASAN_FLAGS := $(ASAN_FLAGS),undefined,return,null,pointer-overflow,float-divide-by-zero
664
#ASAN_FLAGS := $(ASAN_FLAGS) -fsanitize-undefined-trap-on-error
664
#ASAN_FLAGS := $(ASAN_FLAGS) -fsanitize-undefined-trap-on-error
665
665
666
ifeq (0,$(FORCEDEBUG))
666
ifeq (0,$(FORCEDEBUG))
667
    COMPILERFLAGS += -DNDEBUG
667
    COMPILERFLAGS += -DNDEBUG
668
else
668
else
669
    COMPILERFLAGS += -DDEBUGGINGAIDS=$(FORCEDEBUG)
669
    COMPILERFLAGS += -DDEBUGGINGAIDS=$(FORCEDEBUG)
670
670
671
    ifeq (2,$(FORCEDEBUG))
671
    ifeq (2,$(FORCEDEBUG))
672
        ifneq (0,$(CLANG))
672
        ifneq (0,$(CLANG))
673
            COMMONFLAGS += $(ASAN_FLAGS)
673
            COMMONFLAGS += $(ASAN_FLAGS)
674
        else ifneq (,$(filter 1 2 3 4 5 6,$(GCC_MAJOR)))
674
        else ifneq (,$(filter 1 2 3 4 5 6,$(GCC_MAJOR)))
675
            ifneq (,$(filter 0 1,$(GCC_MINOR)))
675
            ifneq (,$(filter 0 1,$(GCC_MINOR)))
676
                COMMONFLAGS += $(ASAN_FLAGS)
676
                COMMONFLAGS += $(ASAN_FLAGS)
677
            endif
677
            endif
678
        endif
678
        endif
679
    endif
679
    endif
680
endif
680
endif
681
681
682
ifneq (0,$(KRANDDEBUG))
682
ifneq (0,$(KRANDDEBUG))
683
    COMPILERFLAGS += -DKRANDDEBUG=1
683
    COMPILERFLAGS += -DKRANDDEBUG=1
684
endif
684
endif
685
685
686
ifneq (0,$(PROFILER))
686
ifneq (0,$(PROFILER))
687
    ifneq ($(PLATFORM),DARWIN)
687
    ifneq ($(PLATFORM),DARWIN)
688
        LIBS += -lprofiler
688
        LIBS += -lprofiler
689
    endif
689
    endif
690
    COMMONFLAGS += -pg
690
    COMMONFLAGS += -pg
691
endif
691
endif
692
692
693
693
694
##### -f stuff
694
##### -f stuff
695
695
696
ifneq (0,$(GCC_PREREQ_4))
696
ifneq (0,$(GCC_PREREQ_4))
697
    F_NO_STACK_PROTECTOR := -fno-stack-protector
697
    F_NO_STACK_PROTECTOR := -fno-stack-protector
698
    ifeq (0,$(CLANG))
698
    ifeq (0,$(CLANG))
699
        F_JUMP_TABLES := -fjump-tables
699
        F_JUMP_TABLES := -fjump-tables
700
    endif
700
    endif
701
endif
701
endif
702
702
703
ifeq ($(PLATFORM),DARWIN)
703
ifeq ($(PLATFORM),DARWIN)
704
    ifeq (1,$(DARWIN9))
704
    ifeq (1,$(DARWIN9))
705
        F_JUMP_TABLES :=
705
        F_JUMP_TABLES :=
706
    endif
706
    endif
707
    ifeq ($(findstring ppc,$(IMPLICIT_ARCH))$(findstring i386,$(IMPLICIT_ARCH)),)
707
    ifeq ($(findstring ppc,$(IMPLICIT_ARCH))$(findstring i386,$(IMPLICIT_ARCH)),)
708
        F_NO_STACK_PROTECTOR :=
708
        F_NO_STACK_PROTECTOR :=
709
    endif
709
    endif
710
endif
710
endif
711
711
712
ifeq (0,$(RELEASE))
712
ifeq (0,$(RELEASE))
713
    F_NO_STACK_PROTECTOR :=
713
    F_NO_STACK_PROTECTOR :=
714
else
714
else
715
    ifeq (0,$(CLANG))
715
    ifeq (0,$(CLANG))
716
        COMMONFLAGS += -funswitch-loops
716
        COMMONFLAGS += -funswitch-loops
717
    endif
717
    endif
718
718
719
    ifeq (0,$(FORCEDEBUG))
719
    ifeq (0,$(FORCEDEBUG))
720
        COMMONFLAGS += -fomit-frame-pointer
720
        COMMONFLAGS += -fomit-frame-pointer
721
    endif
721
    endif
722
endif
722
endif
723
723
724
ifneq (0,$(KRANDDEBUG))
724
ifneq (0,$(KRANDDEBUG))
725
    COMMONFLAGS += -fno-inline -fno-inline-functions -fno-inline-functions-called-once
725
    COMMONFLAGS += -fno-inline -fno-inline-functions -fno-inline-functions-called-once
726
endif
726
endif
727
727
728
COMMONFLAGS += -fno-strict-aliasing -fno-threadsafe-statics $(F_JUMP_TABLES) $(F_NO_STACK_PROTECTOR)
728
COMMONFLAGS += -fno-strict-aliasing -fno-threadsafe-statics $(F_JUMP_TABLES) $(F_NO_STACK_PROTECTOR)
729
729
730
730
731
##### Warnings
731
##### Warnings
732
732
733
W_STRICT_OVERFLOW := -Wno-strict-overflow
733
W_STRICT_OVERFLOW := -Wno-strict-overflow
734
734
735
ifeq ($(PLATFORM),DARWIN)
735
ifeq ($(PLATFORM),DARWIN)
736
    ifneq (0,$(DARWIN9))
736
    ifneq (0,$(DARWIN9))
737
        W_STRICT_OVERFLOW :=
737
        W_STRICT_OVERFLOW :=
738
    endif
738
    endif
739
endif
739
endif
740
740
741
W_UNINITIALIZED := -Wuninitialized
741
W_UNINITIALIZED := -Wuninitialized
742
W_GCC_4_1 := -Wno-attributes
742
W_GCC_4_1 := -Wno-attributes
743
W_GCC_4_2 := $(W_STRICT_OVERFLOW)
743
W_GCC_4_2 := $(W_STRICT_OVERFLOW)
744
W_GCC_4_4 := -Wno-unused-result
744
W_GCC_4_4 := -Wno-unused-result
745
W_GCC_4_5 := -Wlogical-op -Wcast-qual
745
W_GCC_4_5 := -Wlogical-op -Wcast-qual
746
W_GCC_6 := -Wduplicated-cond -Wnull-dereference
746
W_GCC_6 := -Wduplicated-cond -Wnull-dereference
747
W_GCC_7 := -Wduplicated-branches
747
W_GCC_7 := -Wduplicated-branches
748
W_GCC_8 := -Warray-bounds=2
748
W_GCC_8 := -Warray-bounds=2
749
W_GCC_9 := -Wmultistatement-macros
749
W_GCC_9 := -Wmultistatement-macros
750
W_CLANG := -Wno-unused-value -Wno-parentheses -Wno-unknown-warning-option
750
W_CLANG := -Wno-unused-value -Wno-parentheses -Wno-unknown-warning-option
751
751
752
ifeq (0,$(CLANG))
752
ifeq (0,$(CLANG))
753
    W_CLANG :=
753
    W_CLANG :=
754
754
755
    ifneq (,$(filter 4 5 6 7 8,$(GCC_MAJOR)))
755
    ifneq (,$(filter 4 5 6 7 8,$(GCC_MAJOR)))
756
        W_GCC_9 :=
756
        W_GCC_9 :=
757
        ifneq (,$(filter 4 5 6 7,$(GCC_MAJOR)))
757
        ifneq (,$(filter 4 5 6 7,$(GCC_MAJOR)))
758
            W_GCC_8 :=
758
            W_GCC_8 :=
759
            ifneq (,$(filter 4 5 6,$(GCC_MAJOR)))
759
            ifneq (,$(filter 4 5 6,$(GCC_MAJOR)))
760
                W_GCC_7 :=
760
                W_GCC_7 :=
761
                ifneq (,$(filter 4 5,$(GCC_MAJOR)))
761
                ifneq (,$(filter 4 5,$(GCC_MAJOR)))
762
                    W_GCC_6 :=
762
                    W_GCC_6 :=
763
                endif
763
                endif
764
            endif     
764
            endif     
765
        endif
765
        endif
766
    endif
766
    endif
767
767
768
    ifeq (0,$(GCC_PREREQ_4))
768
    ifeq (0,$(GCC_PREREQ_4))
769
        W_GCC_9 :=
769
        W_GCC_9 :=
770
        W_GCC_8 :=
770
        W_GCC_8 :=
771
        W_GCC_7 :=
771
        W_GCC_7 :=
772
        W_GCC_6 :=
772
        W_GCC_6 :=
773
        W_GCC_4_5 :=
773
        W_GCC_4_5 :=
774
        W_GCC_4_4 :=
774
        W_GCC_4_4 :=
775
        ifeq (0,$(OPTLEVEL))
775
        ifeq (0,$(OPTLEVEL))
776
            W_UNINITIALIZED :=
776
            W_UNINITIALIZED :=
777
        endif
777
        endif
778
        W_GCC_4_2 :=
778
        W_GCC_4_2 :=
779
        W_GCC_4_1 :=
779
        W_GCC_4_1 :=
780
    endif
780
    endif
781
781
782
    ifeq (4,$(GCC_MAJOR))
782
    ifeq (4,$(GCC_MAJOR))
783
        ifneq (,$(filter 0 1 2 3 4,$(GCC_MINOR)))
783
        ifneq (,$(filter 0 1 2 3 4,$(GCC_MINOR)))
784
            W_GCC_4_5 :=
784
            W_GCC_4_5 :=
785
            ifneq (,$(filter 0 1 2 3,$(GCC_MINOR)))
785
            ifneq (,$(filter 0 1 2 3,$(GCC_MINOR)))
786
                W_GCC_4_4 :=
786
                W_GCC_4_4 :=
787
                ifeq (0,$(OPTLEVEL))
787
                ifeq (0,$(OPTLEVEL))
788
                    W_UNINITIALIZED :=
788
                    W_UNINITIALIZED :=
789
                endif
789
                endif
790
                ifneq (,$(filter 0 1,$(GCC_MINOR)))
790
                ifneq (,$(filter 0 1,$(GCC_MINOR)))
791
                    W_GCC_4_2 :=
791
                    W_GCC_4_2 :=
792
                    ifeq (0,$(GCC_MINOR))
792
                    ifeq (0,$(GCC_MINOR))
793
                        W_GCC_4_1 :=
793
                        W_GCC_4_1 :=
794
                    endif
794
                    endif
795
                endif
795
                endif
796
            endif
796
            endif
797
        endif
797
        endif
798
    endif
798
    endif
799
endif
799
endif
800
800
801
CONLYWARNS := -Wimplicit -Werror-implicit-function-declaration
801
CONLYWARNS := -Wimplicit -Werror-implicit-function-declaration
802
802
803
CWARNS := -W -Wall \
803
CWARNS := -W -Wall \
804
    -Wextra \
804
    -Wextra \
805
    -Wpointer-arith \
805
    -Wpointer-arith \
806
    -Wno-char-subscripts \
806
    -Wno-char-subscripts \
807
    -Wno-missing-braces \
807
    -Wno-missing-braces \
808
    -Wwrite-strings \
808
    -Wwrite-strings \
809
    $(W_UNINITIALIZED) \
809
    $(W_UNINITIALIZED) \
810
    $(W_GCC_4_1) \
810
    $(W_GCC_4_1) \
811
    $(W_GCC_4_2) \
811
    $(W_GCC_4_2) \
812
    $(W_GCC_4_4) \
812
    $(W_GCC_4_4) \
813
    $(W_GCC_4_5) \
813
    $(W_GCC_4_5) \
814
    $(W_GCC_6) \
814
    $(W_GCC_6) \
815
    $(W_GCC_7) \
815
    $(W_GCC_7) \
816
    $(W_GCC_8) \
816
    $(W_GCC_8) \
817
    $(W_GCC_9) \
817
    $(W_GCC_9) \
818
    $(W_CLANG) \
818
    $(W_CLANG) \
819
    #-Wstrict-prototypes \
819
    #-Wstrict-prototypes \
820
    #-Waggregate-return \
820
    #-Waggregate-return \
821
    #-Wcast-align \
821
    #-Wcast-align \
822
    #-Waddress
822
    #-Waddress
823
823
824
824
825
##### Features
825
##### Features
826
826
827
ifneq (,$(APPNAME))
827
ifneq (,$(APPNAME))
828
    COMPILERFLAGS += "-DAPPNAME=\"$(APPNAME)\""
828
    COMPILERFLAGS += "-DAPPNAME=\"$(APPNAME)\""
829
endif
829
endif
830
ifneq (,$(APPBASENAME))
830
ifneq (,$(APPBASENAME))
831
    COMPILERFLAGS += "-DAPPBASENAME=\"$(APPBASENAME)\""
831
    COMPILERFLAGS += "-DAPPBASENAME=\"$(APPBASENAME)\""
832
endif
832
endif
833
833
834
ifneq (0,$(NOASM))
834
ifneq (0,$(NOASM))
835
    COMPILERFLAGS += -DNOASM
835
    COMPILERFLAGS += -DNOASM
836
endif
836
endif
837
ifneq (0,$(USE_ASM64))
837
ifneq (0,$(USE_ASM64))
838
    COMPILERFLAGS += -DUSE_ASM64
838
    COMPILERFLAGS += -DUSE_ASM64
839
endif
839
endif
840
ifneq (0,$(MEMMAP))
840
ifneq (0,$(MEMMAP))
841
    ifeq ($(PLATFORM),DARWIN)
841
    ifeq ($(PLATFORM),DARWIN)
842
        LINKERFLAGS += -Wl,-map -Wl,$@.memmap
842
        LINKERFLAGS += -Wl,-map -Wl,$@.memmap
843
    else
843
    else
844
        LINKERFLAGS += -Wl,-Map=$@.memmap
844
        LINKERFLAGS += -Wl,-Map=$@.memmap
845
    endif
845
    endif
846
endif
846
endif
847
847
848
COMPILERFLAGS += -DRENDERTYPE$(RENDERTYPE)=1
848
COMPILERFLAGS += -DRENDERTYPE$(RENDERTYPE)=1
849
849
850
ifeq (0,$(NETCODE))
850
ifeq (0,$(NETCODE))
851
    COMPILERFLAGS += -DNETCODE_DISABLE
851
    COMPILERFLAGS += -DNETCODE_DISABLE
852
endif
852
endif
853
ifneq (0,$(STARTUP_WINDOW))
853
ifneq (0,$(STARTUP_WINDOW))
854
    COMPILERFLAGS += -DSTARTUP_WINDOW
854
    COMPILERFLAGS += -DSTARTUP_WINDOW
855
endif
855
endif
856
ifneq (0,$(RETAIL_MENU))
856
ifneq (0,$(RETAIL_MENU))
857
    COMPILERFLAGS += -DEDUKE32_RETAIL_MENU
857
    COMPILERFLAGS += -DEDUKE32_RETAIL_MENU
858
endif
858
endif
859
ifneq (0,$(STANDALONE))
859
ifneq (0,$(STANDALONE))
860
    COMPILERFLAGS += -DEDUKE32_STANDALONE
860
    COMPILERFLAGS += -DEDUKE32_STANDALONE
861
endif
861
endif
862
ifneq (0,$(USE_OPENGL))
862
ifneq (0,$(USE_OPENGL))
863
    COMPILERFLAGS += -DUSE_OPENGL
863
    COMPILERFLAGS += -DUSE_OPENGL
864
endif
864
endif
865
ifneq (0,$(POLYMER))
865
ifneq (0,$(POLYMER))
866
    COMPILERFLAGS += -DPOLYMER
866
    COMPILERFLAGS += -DPOLYMER
867
endif
867
endif
868
868
869
869
870
##### External library paths
870
##### External library paths
871
871
872
ifeq ($(PLATFORM),WINDOWS)
872
ifeq ($(PLATFORM),WINDOWS)
873
    COMPILERFLAGS += -Iplatform/Windows/include
873
    COMPILERFLAGS += -Iplatform/Windows/include
874
    LIBDIRS += -Lplatform/Windows/lib/$(BITS)
874
    LIBDIRS += -Lplatform/Windows/lib/$(BITS)
875
else ifeq ($(PLATFORM),DARWIN)
875
else ifeq ($(PLATFORM),DARWIN)
876
    ifneq ($(shell port --version &>/dev/null; echo $$?),127)
876
    ifneq ($(shell port --version &>/dev/null; echo $$?),127)
877
        LIBDIRS += -L/opt/local/lib
877
        LIBDIRS += -L/opt/local/lib
878
        COMPILERFLAGS += -I/opt/local/include
878
        COMPILERFLAGS += -I/opt/local/include
879
    endif
879
    endif
880
    ifneq ($(shell brew --version &>/dev/null; echo $$?),127)
880
    ifneq ($(shell brew --version &>/dev/null; echo $$?),127)
881
        LIBDIRS += -L/usr/local/lib
881
        LIBDIRS += -L/usr/local/lib
882
        COMPILERFLAGS += -I/usr/local/include
882
        COMPILERFLAGS += -I/usr/local/include
883
    endif
883
    endif
884
    ifneq ($(shell fink --version &>/dev/null; echo $$?),127)
884
    ifneq ($(shell fink --version &>/dev/null; echo $$?),127)
885
        LIBDIRS += -L/sw/lib
885
        LIBDIRS += -L/sw/lib
886
        COMPILERFLAGS += -I/sw/include
886
        COMPILERFLAGS += -I/sw/include
887
    endif
887
    endif
888
else ifeq ($(PLATFORM),BSD)
888
else ifeq ($(PLATFORM),BSD)
889
    COMPILERFLAGS += -I/usr/local/include
889
    COMPILERFLAGS += -I/usr/local/include
890
else ifeq ($(PLATFORM),WII)
890
else ifeq ($(PLATFORM),WII)
891
    COMPILERFLAGS += -I$(PORTLIBS)/include -Iplatform/Wii/include
891
    COMPILERFLAGS += -I$(PORTLIBS)/include -Iplatform/Wii/include
892
    LIBDIRS += -L$(PORTLIBS)/lib -Lplatform/Wii/lib
892
    LIBDIRS += -L$(PORTLIBS)/lib -Lplatform/Wii/lib
893
endif
893
endif
894
894
895
895
896
##### External libraries
896
##### External libraries
897
897
898
ifneq ($(LUNATIC),0)
898
ifneq ($(LUNATIC),0)
899
    ifneq ($(USE_LUAJIT_2_1),0)
899
    ifneq ($(USE_LUAJIT_2_1),0)
900
        COMPILERFLAGS += -DUSE_LUAJIT_2_1
900
        COMPILERFLAGS += -DUSE_LUAJIT_2_1
901
    endif
901
    endif
902
902
903
    ifeq ($(PLATFORM),WINDOWS)
903
    ifeq ($(PLATFORM),WINDOWS)
904
        LIBS += -lluajit
904
        LIBS += -lluajit
905
    else
905
    else
906
        LIBS += -lluajit-5.1
906
        LIBS += -lluajit-5.1
907
    endif
907
    endif
908
endif
908
endif
909
909
910
ifneq (0,$(USE_LIBVPX))
910
ifneq (0,$(USE_LIBVPX))
911
    COMPILERFLAGS += -DUSE_LIBVPX
911
    COMPILERFLAGS += -DUSE_LIBVPX
912
    LIBS += -lvpx
912
    LIBS += -lvpx
913
endif
913
endif
914
914
915
ifneq (0,$(HAVE_VORBIS))
915
ifneq (0,$(HAVE_VORBIS))
916
    COMPILERFLAGS += -DHAVE_VORBIS
916
    COMPILERFLAGS += -DHAVE_VORBIS
917
endif
917
endif
918
ifneq (0,$(HAVE_FLAC))
918
ifneq (0,$(HAVE_FLAC))
919
    COMPILERFLAGS += -DHAVE_FLAC
919
    COMPILERFLAGS += -DHAVE_FLAC
920
endif
920
endif
921
ifneq (0,$(HAVE_XMP))
921
ifneq (0,$(HAVE_XMP))
922
    COMPILERFLAGS += -DHAVE_XMP
922
    COMPILERFLAGS += -DHAVE_XMP
923
endif
923
endif
924
924
925
ifeq ($(RENDERTYPE),SDL)
925
ifeq ($(RENDERTYPE),SDL)
926
    ifeq ($(SDL_TARGET),2)
926
    ifeq ($(SDL_TARGET),2)
927
        SDLCONFIG := sdl2-config
927
        SDLCONFIG := sdl2-config
928
        SDLNAME := SDL2
928
        SDLNAME := SDL2
929
    else ifeq ($(SDL_TARGET),1)
929
    else ifeq ($(SDL_TARGET),1)
930
        SDLCONFIG := sdl-config
930
        SDLCONFIG := sdl-config
931
        SDLNAME := SDL
931
        SDLNAME := SDL
932
        ifeq (0,$(RELEASE))
932
        ifeq (0,$(RELEASE))
933
            COMPILERFLAGS += -DNOSDLPARACHUTE
933
            COMPILERFLAGS += -DNOSDLPARACHUTE
934
        endif
934
        endif
935
    endif
935
    endif
936
936
937
    ifeq ($(PLATFORM), WINDOWS)
937
    ifeq ($(PLATFORM), WINDOWS)
938
        SDLCONFIG :=
938
        SDLCONFIG :=
939
    endif
939
    endif
940
940
941
    ifeq ($(PLATFORM),WII)
941
    ifeq ($(PLATFORM),WII)
942
        SDLCONFIG :=
942
        SDLCONFIG :=
943
    else ifeq ($(PLATFORM),SKYOS)
943
    else ifeq ($(PLATFORM),SKYOS)
944
        COMPILERFLAGS += -I/boot/programs/sdk/include/sdl
944
        COMPILERFLAGS += -I/boot/programs/sdk/include/sdl
945
        SDLCONFIG :=
945
        SDLCONFIG :=
946
    endif
946
    endif
947
947
948
    ifneq ($(strip $(SDLCONFIG)),)
948
    ifneq ($(strip $(SDLCONFIG)),)
949
        ifeq ($(strip $(shell $(SDLCONFIG) --version $(DONT_PRINT_STDERR))),)
949
        ifeq ($(strip $(shell $(SDLCONFIG) --version $(DONT_PRINT_STDERR))),)
950
            override SDLCONFIG :=
950
            override SDLCONFIG :=
951
        endif
951
        endif
952
    endif
952
    endif
953
953
954
    COMPILERFLAGS += -DSDL_TARGET=$(SDL_TARGET)
954
    COMPILERFLAGS += -DSDL_TARGET=$(SDL_TARGET)
955
955
956
    SDL_FRAMEWORK := 0
956
    SDL_FRAMEWORK := 0
957
    ifneq ($(SDL_FRAMEWORK),0)
957
    ifneq ($(SDL_FRAMEWORK),0)
958
        ifeq ($(PLATFORM),DARWIN)
958
        ifeq ($(PLATFORM),DARWIN)
959
            APPLE_FRAMEWORKS := /Library/Frameworks
959
            APPLE_FRAMEWORKS := /Library/Frameworks
960
            LIBDIRS += -F$(APPLE_FRAMEWORKS)
960
            LIBDIRS += -F$(APPLE_FRAMEWORKS)
961
            COMPILERFLAGS += -I$(APPLE_FRAMEWORKS)/$(SDLNAME).framework/Headers
961
            COMPILERFLAGS += -I$(APPLE_FRAMEWORKS)/$(SDLNAME).framework/Headers
962
            LIBS += -Wl,-framework,$(SDLNAME) -Wl,-rpath -Wl,"@loader_path/../Frameworks"
962
            LIBS += -Wl,-framework,$(SDLNAME) -Wl,-rpath -Wl,"@loader_path/../Frameworks"
963
        endif
963
        endif
964
    else
964
    else
965
        ifneq ($(SDLCONFIG),)
965
        ifneq ($(SDLCONFIG),)
966
            SDLCONFIG_CFLAGS := $(strip $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags)))
966
            SDLCONFIG_CFLAGS := $(strip $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags)))
967
            SDLCONFIG_LIBS := $(strip $(subst -mwindows,,$(shell $(SDLCONFIG) --libs)))
967
            SDLCONFIG_LIBS := $(strip $(subst -mwindows,,$(shell $(SDLCONFIG) --libs)))
968
968
969
            COMPILERFLAGS += $(SDLCONFIG_CFLAGS)
969
            COMPILERFLAGS += $(SDLCONFIG_CFLAGS)
970
            LIBS += $(SDLCONFIG_LIBS)
970
            LIBS += $(SDLCONFIG_LIBS)
971
        else
971
        else
972
            ifeq ($(SDL_TARGET),1)
972
            ifeq ($(SDL_TARGET),1)
973
                COMPILERFLAGS += -D_GNU_SOURCE=1
973
                COMPILERFLAGS += -D_GNU_SOURCE=1
974
            endif
974
            endif
975
            COMPILERFLAGS += -D_REENTRANT -DSDL_USEFOLDER
975
            COMPILERFLAGS += -D_REENTRANT -DSDL_USEFOLDER
976
            LIBS += -l$(SDLNAME)
976
            LIBS += -l$(SDLNAME)
977
        endif
977
        endif
978
    endif
978
    endif
979
endif
979
endif
980
980
981
ifneq (0,$(HAVE_GTK2))
981
ifneq (0,$(HAVE_GTK2))
982
    ifneq (No,$(shell $(PKG_CONFIG) --exists gtk+-2.0 || echo No))
982
    ifneq (No,$(shell $(PKG_CONFIG) --exists gtk+-2.0 || echo No))
983
        COMPILERFLAGS += -DHAVE_GTK2 $(shell $(PKG_CONFIG) --cflags gtk+-2.0)
983
        COMPILERFLAGS += -DHAVE_GTK2 $(shell $(PKG_CONFIG) --cflags gtk+-2.0)
984
    else
984
    else
985
        override HAVE_GTK2 := 0
985
        override HAVE_GTK2 := 0
986
    endif
986
    endif
987
endif
987
endif
988
988
989
989
990
##### System libraries
990
##### System libraries
991
991
992
ifeq ($(PLATFORM),WINDOWS)
992
ifeq ($(PLATFORM),WINDOWS)
993
    ifneq (0,$(GCC_PREREQ_4))
993
    ifneq (0,$(GCC_PREREQ_4))
994
        L_SSP := -lssp
994
        L_SSP := -lssp
995
    endif
995
    endif
996
    LIBS += -lmingwex -lgdi32 -lpthread
996
    LIBS += -lmingwex -lgdi32 -lpthread
997
    ifeq ($(RENDERTYPE),WIN)
997
    ifeq ($(RENDERTYPE),WIN)
998
        LIBS += -ldxguid
998
        LIBS += -ldxguid
999
    else ifeq ($(SDL_TARGET),1)
999
    else ifeq ($(SDL_TARGET),1)
1000
        LIBS += -ldxguid -lmingw32 -limm32 -lole32 -loleaut32 -lversion
1000
        LIBS += -ldxguid -lmingw32 -limm32 -lole32 -loleaut32 -lversion
1001
    else
1001
    else
1002
        LIBS += -ldxguid_sdl -lmingw32 -limm32 -lole32 -loleaut32 -lversion -lsetupapi
1002
        LIBS += -ldxguid_sdl -lmingw32 -limm32 -lole32 -loleaut32 -lversion -lsetupapi
1003
    endif
1003
    endif
1004
    LIBS += -lcomctl32 -lwinmm $(L_SSP) -lwsock32 -lws2_32 -lshlwapi
1004
    LIBS += -lcomctl32 -lwinmm $(L_SSP) -lwsock32 -lws2_32 -lshlwapi -luuid
1005
    # -lshfolder
1005
    # -lshfolder
1006
else ifeq ($(PLATFORM),SKYOS)
1006
else ifeq ($(PLATFORM),SKYOS)
1007
    LIBS += -lnet
1007
    LIBS += -lnet
1008
else ifeq ($(PLATFORM),QNX)
1008
else ifeq ($(PLATFORM),QNX)
1009
    LIBS += -lsocket
1009
    LIBS += -lsocket
1010
else ifeq ($(PLATFORM),SUNOS)
1010
else ifeq ($(PLATFORM),SUNOS)
1011
    LIBS += -lsocket -lnsl
1011
    LIBS += -lsocket -lnsl
1012
else ifeq ($(PLATFORM),WII)
1012
else ifeq ($(PLATFORM),WII)
1013
    LIBS += -laesnd_tueidj -lfat -lwiiuse -lbte -lwiikeyboard -logc
1013
    LIBS += -laesnd_tueidj -lfat -lwiiuse -lbte -lwiikeyboard -logc
1014
else ifeq ($(SUBPLATFORM),LINUX)
1014
else ifeq ($(SUBPLATFORM),LINUX)
1015
    LIBS += -lrt
1015
    LIBS += -lrt
1016
endif
1016
endif
1017
1017
1018
ifeq (,$(filter $(PLATFORM),WINDOWS WII))
1018
ifeq (,$(filter $(PLATFORM),WINDOWS WII))
1019
    ifneq ($(PLATFORM),BSD)
1019
    ifneq ($(PLATFORM),BSD)
1020
        LIBS += -ldl
1020
        LIBS += -ldl
1021
    endif
1021
    endif
1022
    ifneq ($(PLATFORM),DARWIN)
1022
    ifneq ($(PLATFORM),DARWIN)
1023
        LIBS += -pthread
1023
        LIBS += -pthread
1024
    endif
1024
    endif
1025
endif
1025
endif
1026
1026
1027
LIBS += -lm
1027
LIBS += -lm
1028
1028
1029
1029
1030
##### Detect version control revision, if applicable
1030
##### Detect version control revision, if applicable
1031
1031
1032
VC_REV :=
1032
VC_REV :=
1033
-include EDUKE32_REVISION.mak
1033
-include EDUKE32_REVISION.mak
1034
ifeq (,$(VC_REV))
1034
ifeq (,$(VC_REV))
1035
    VC_REV := $(word 2,$(subst :, ,$(filter Revision:%,$(subst : ,:,$(strip $(shell svn info 2>&1))))))
1035
    VC_REV := $(word 2,$(subst :, ,$(filter Revision:%,$(subst : ,:,$(strip $(shell svn info 2>&1))))))
1036
endif
1036
endif
1037
ifeq (,$(VC_REV))
1037
ifeq (,$(VC_REV))
1038
    GIT_SVN_URL := $(strip $(shell git config --local svn-remote.svn.url))
1038
    GIT_SVN_URL := $(strip $(shell git config --local svn-remote.svn.url))
1039
    GIT_SVN_FETCH := $(strip $(shell git config --local svn-remote.svn.fetch))
1039
    GIT_SVN_FETCH := $(strip $(shell git config --local svn-remote.svn.fetch))
1040
    VC_REV := $(word 2,$(subst @, ,$(filter git-svn-id:$(GIT_SVN_URL)@%,$(subst : ,:,$(shell git log -1 $(GIT_SVN_FETCH::%=%))))))
1040
    VC_REV := $(word 2,$(subst @, ,$(filter git-svn-id:$(GIT_SVN_URL)@%,$(subst : ,:,$(shell git log -1 $(GIT_SVN_FETCH::%=%))))))
1041
endif
1041
endif
1042
ifneq (,$(VC_REV)$(VC_REV_CUSTOM))
1042
ifneq (,$(VC_REV)$(VC_REV_CUSTOM))
1043
    REVFLAG := -DREV="r$(VC_REV)$(VC_REV_CUSTOM)"
1043
    REVFLAG := -DREV="r$(VC_REV)$(VC_REV_CUSTOM)"
1044
endif
1044
endif
1045
1045
1046
1046
1047
##### Allow standard environment variables to take precedence, to help package maintainers.
1047
##### Allow standard environment variables to take precedence, to help package maintainers.
1048
1048
1049
ifneq (,$(CFLAGS))
1049
ifneq (,$(CFLAGS))
1050
    COMMONFLAGS += $(CFLAGS)
1050
    COMMONFLAGS += $(CFLAGS)
1051
endif
1051
endif
1052
ifneq (,$(CXXFLAGS))
1052
ifneq (,$(CXXFLAGS))
1053
    CXXONLYFLAGS += $(CXXFLAGS)
1053
    CXXONLYFLAGS += $(CXXFLAGS)
1054
endif
1054
endif
1055
ifneq (,$(LDFLAGS))
1055
ifneq (,$(LDFLAGS))
1056
    LINKERFLAGS += $(LDFLAGS)
1056
    LINKERFLAGS += $(LDFLAGS)
1057
endif
1057
endif
1058
1058
1059
1059
1060
##### Final assembly of commands
1060
##### Final assembly of commands
1061
1061
1062
COMPILER_C=$(CC) $(CONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(CONLYWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1062
COMPILER_C=$(CC) $(CONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(CONLYWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1063
COMPILER_CXX=$(CXX) $(CXXONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1063
COMPILER_CXX=$(CXX) $(CXXONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1064
COMPILER_OBJC=$(COBJC) $(CONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(CONLYWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1064
COMPILER_OBJC=$(COBJC) $(CONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(CONLYWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1065
COMPILER_OBJCXX=$(COBJCXX) $(CXXONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1065
COMPILER_OBJCXX=$(COBJCXX) $(CXXONLYFLAGS) $(COMMONFLAGS) $(CWARNS) $(COMPILERFLAGS) $(CUSTOMOPT)
1066
LINKER=$(L_CXX) $(CXXONLYFLAGS) $(L_CXXONLYFLAGS) $(COMMONFLAGS) $(LINKERFLAGS) $(CUSTOMOPT)
1066
LINKER=$(L_CXX) $(CXXONLYFLAGS) $(L_CXXONLYFLAGS) $(COMMONFLAGS) $(LINKERFLAGS) $(CUSTOMOPT)
1067
ifneq ($(CPLUSPLUS),0)
1067
ifneq ($(CPLUSPLUS),0)
1068
    COMPILER_C=$(COMPILER_CXX)
1068
    COMPILER_C=$(COMPILER_CXX)
1069
    COMPILER_OBJC=$(COMPILER_OBJCXX)
1069
    COMPILER_OBJC=$(COMPILER_OBJCXX)
1070
endif
1070
endif
1071
1071
1072
1072
1073
##### Pretty-printing
1073
##### Pretty-printing
1074
1074
1075
ifeq ($(PRETTY_OUTPUT),1)
1075
ifeq ($(PRETTY_OUTPUT),1)
1076
RECIPE_IF = if
1076
RECIPE_IF = if
1077
BUILD_STARTED = printf "\033[K\033[1;36mBuilding: \033[0;36m$(MAKE) $(MAKECMDGOALS) -$(MAKEFLAGS)\033[0m\n"
1077
BUILD_STARTED = printf "\033[K\033[1;36mBuilding: \033[0;36m$(MAKE) $(MAKECMDGOALS) -$(MAKEFLAGS)\033[0m\n"
1078
COMPILE_STATUS = printf "\033[K\033[0mBuilding object \033[1m$@\033[0m...\033[0m\r"
1078
COMPILE_STATUS = printf "\033[K\033[0mBuilding object \033[1m$@\033[0m...\033[0m\r"
1079
COMPILE_OK = printf "\033[K\033[0;32mBuilt object \033[1;32m$@\033[0;32m \033[0m\n"
1079
COMPILE_OK = printf "\033[K\033[0;32mBuilt object \033[1;32m$@\033[0;32m \033[0m\n"
1080
COMPILE_FAILED = printf "\033[K\033[0;31mFailed building \033[1;31m$@\033[0;31m from\033[0m \033[1;31m$<\033[0;31m!\033[0m\n"; exit 1
1080
COMPILE_FAILED = printf "\033[K\033[0;31mFailed building \033[1;31m$@\033[0;31m from\033[0m \033[1;31m$<\033[0;31m!\033[0m\n"; exit 1
1081
RECIPE_RESULT_COMPILE = ; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
1081
RECIPE_RESULT_COMPILE = ; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
1082
ONESTEP_STATUS = printf "\033[K\033[0mBuilding \033[1m$@\033[0m...\033[0m\r"
1082
ONESTEP_STATUS = printf "\033[K\033[0mBuilding \033[1m$@\033[0m...\033[0m\r"
1083
ONESTEP_OK = printf "\033[K\033[0;32mBuilt \033[1;32m$@\033[0;32m \033[0m\n"
1083
ONESTEP_OK = printf "\033[K\033[0;32mBuilt \033[1;32m$@\033[0;32m \033[0m\n"
1084
ONESTEP_FAILED = printf "\033[K\033[0;31mFailed building \033[1;31m$@\033[0;31m!\033[0m\n"; exit 1
1084
ONESTEP_FAILED = printf "\033[K\033[0;31mFailed building \033[1;31m$@\033[0;31m!\033[0m\n"; exit 1
1085
RECIPE_RESULT_ONESTEP = ; then $(ONESTEP_OK); else $(ONESTEP_FAILED); fi
1085
RECIPE_RESULT_ONESTEP = ; then $(ONESTEP_OK); else $(ONESTEP_FAILED); fi
1086
ARCHIVE_STATUS = printf "\033[K\033[0mCreating library archive \033[1m$@\033[0m...\033[0m\r"
1086
ARCHIVE_STATUS = printf "\033[K\033[0mCreating library archive \033[1m$@\033[0m...\033[0m\r"
1087
ARCHIVE_OK = printf "\033[K\033[0;32mCreated library archive \033[1;32m$@\033[0;32m \033[0m\n"
1087
ARCHIVE_OK = printf "\033[K\033[0;32mCreated library archive \033[1;32m$@\033[0;32m \033[0m\n"
1088
ARCHIVE_FAILED = printf "\033[K\033[0;31mFailed creating library archive \033[1;31m$@\033[0;31m from\033[0m \033[1;31m$<\033[0;31m!\033[0m\n"; exit 1
1088
ARCHIVE_FAILED = printf "\033[K\033[0;31mFailed creating library archive \033[1;31m$@\033[0;31m from\033[0m \033[1;31m$<\033[0;31m!\033[0m\n"; exit 1
1089
RECIPE_RESULT_ARCHIVE = ; then $(ARCHIVE_OK); else $(ARCHIVE_FAILED); fi
1089
RECIPE_RESULT_ARCHIVE = ; then $(ARCHIVE_OK); else $(ARCHIVE_FAILED); fi
1090
LINK_STATUS = printf "\033[K\033[0;0mLinking \033[1m$@\033[0;0m...\033[0m\r"
1090
LINK_STATUS = printf "\033[K\033[0;0mLinking \033[1m$@\033[0;0m...\033[0m\r"
1091
LINK_OK = printf "\033[K\033[0;32mLinked \033[1;32m$@\033[0;32m \033[0m\n"
1091
LINK_OK = printf "\033[K\033[0;32mLinked \033[1;32m$@\033[0;32m \033[0m\n"
1092
LINK_FAILED = printf "\033[K\033[0;31mFailed linking \033[1;31m$@\033[0;31m!\nIf the build options, environment, or system packages have changed, run \'\033[1;31mmake clean\033[0;31m\' and try again.\033[0m\n"; exit 1
1092
LINK_FAILED = printf "\033[K\033[0;31mFailed linking \033[1;31m$@\033[0;31m!\nIf the build options, environment, or system packages have changed, run \'\033[1;31mmake clean\033[0;31m\' and try again.\033[0m\n"; exit 1
1093
RECIPE_RESULT_LINK = ; then $(LINK_OK); else $(LINK_FAILED); fi
1093
RECIPE_RESULT_LINK = ; then $(LINK_OK); else $(LINK_FAILED); fi
1094
else
1094
else
1095
RECIPE_IF =
1095
RECIPE_IF =
1096
BUILD_STARTED =
1096
BUILD_STARTED =
1097
COMPILE_STATUS =
1097
COMPILE_STATUS =
1098
COMPILE_OK = true
1098
COMPILE_OK = true
1099
COMPILE_FAILED = false; exit 1
1099
COMPILE_FAILED = false; exit 1
1100
RECIPE_RESULT_COMPILE =
1100
RECIPE_RESULT_COMPILE =
1101
ONESTEP_STATUS =
1101
ONESTEP_STATUS =
1102
ONESTEP_OK = true
1102
ONESTEP_OK = true
1103
ONESTEP_FAILED = false; exit 1
1103
ONESTEP_FAILED = false; exit 1
1104
RECIPE_RESULT_ONESTEP =
1104
RECIPE_RESULT_ONESTEP =
1105
ARCHIVE_STATUS =
1105
ARCHIVE_STATUS =
1106
ARCHIVE_OK = true
1106
ARCHIVE_OK = true
1107
ARCHIVE_FAILED = false; exit 1
1107
ARCHIVE_FAILED = false; exit 1
1108
RECIPE_RESULT_ARCHIVE =
1108
RECIPE_RESULT_ARCHIVE =
1109
LINK_STATUS =
1109
LINK_STATUS =
1110
LINK_OK = true
1110
LINK_OK = true
1111
LINK_FAILED = false; exit 1
1111
LINK_FAILED = false; exit 1
1112
RECIPE_RESULT_LINK =
1112
RECIPE_RESULT_LINK =
1113
endif
1113
endif