Subversion Repositories eduke32

Rev

Rev 4646 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1739 helixhorne 1
 
4547 hendricks2 2
PACKAGE_REPOSITORY ?= 0
3
4
 
5
PRETTY_OUTPUT ?= 1
1791 helixhorne 6
1739 helixhorne 7
 
3096 hendricks2 8
CROSS=
3972 hendricks2 9
ifneq ($(CROSS),)
4547 hendricks2 10
    undefine CC
11
    undefine CXX
12
    undefine AR
13
    undefine RC
14
    undefine RANLIB
15
    undefine STRIP
16
endif
17
3096 hendricks2 18
 
4647 hendricks2 19
CXX=$(CROSS)g++
20
AR=$(CROSS)ar
21
RC=$(CROSS)windres
22
RANLIB=$(CROSS)ranlib
23
STRIP=$(CROSS)strip
24
AS=nasm
25
PKG_CONFIG=pkg-config
26
4547 hendricks2 27
 
28
ifeq ($(CC),cc)
29
    override CC=gcc
30
endif
31
ifeq ($(AS),as)
32
    override AS=nasm
33
endif
34
35
 
4644 hendricks2 36
L_CC=$(CC)
3122 hendricks2 37
L_CXX=$(CXX)
38
39
 
4543 hendricks2 40
3278 hendricks2 41
 
42
    ifeq ($(strip $(DEVKITPPC)),)
43
        $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
44
    endif
45
46
 
47
48
 
4543 hendricks2 49
50
 
4647 hendricks2 51
    RANLIB=powerpc-eabi-ranlib
3278 hendricks2 52
    STRIP=powerpc-eabi-strip
53
endif
54
55
 
4644 hendricks2 56
57
 
58
59
 
60
    override CLANG=1
61
endif
62
# detect clang symlinked as gcc, as in OS X
63
ifeq ($(findstring clang,$(CLANG_POTENTIAL_VERSION)),clang)
64
    override CLANG=1
65
endif
66
67
 
68
    override CC=clang -x c
69
    override CXX=clang -x c++
70
    override COMPILER_OBJC=clang -x objective-c
71
    override L_CC=clang
72
    override L_CXX=clang
73
endif
74
75
 
3096 hendricks2 76
ifndef GCC_MAJOR
3278 hendricks2 77
    GCC_MAJOR    := $(shell $(CCFULLPATH) -dumpversion 2>&1 | cut -d'.' -f1)
4543 hendricks2 78
endif
3278 hendricks2 79
ifeq ($(GCC_MAJOR),)
80
    GCC_MAJOR    := 4
81
endif
82
ifndef GCC_MINOR
83
    GCC_MINOR    := $(shell $(CCFULLPATH) -dumpversion 2>&1 | cut -d'.' -f2)
4543 hendricks2 84
endif
3278 hendricks2 85
ifeq ($(GCC_MINOR),)
86
    GCC_MINOR    := 8
4543 hendricks2 87
endif
3278 hendricks2 88
3096 hendricks2 89
 
90
ifndef SYSARCH
3278 hendricks2 91
    SYSARCH:=$(strip $(shell uname -m))
92
endif
93
SYSBITS=32
4543 hendricks2 94
3096 hendricks2 95
 
96
# the outside world. This allows cross-compilation by overriding
97
# CC and giving us PLATFORM specifically.
98
#
99
ifndef PLATFORM
100
    uname:=$(strip $(shell uname -s))
3278 hendricks2 101
    PLATFORM=UNKNOWN
3096 hendricks2 102
    ifeq ($(findstring Linux,$(uname)),Linux)
103
        PLATFORM=LINUX
104
    endif
105
    ifeq ($(findstring BSD,$(uname)),BSD)
106
        PLATFORM=BSD
107
    endif
108
    ifeq ($(findstring MINGW,$(uname)),MINGW)
109
        PLATFORM=WINDOWS
110
    endif
111
    ifeq ($(findstring Darwin,$(uname)),Darwin)
112
        PLATFORM=DARWIN
113
    endif
114
    ifeq ($(findstring BeOS,$(uname)),BeOS)
115
        PLATFORM=BEOS
116
    endif
117
    ifeq ($(findstring skyos,$(uname)),skyos)
118
        PLATFORM=SKYOS
119
    endif
120
    ifeq ($(findstring QNX,$(uname)),QNX)
121
        PLATFORM=QNX
122
    endif
123
    ifeq ($(findstring SunOS,$(uname)),SunOS)
124
        PLATFORM=SUNOS
125
    endif
126
    ifeq ($(findstring syllable,$(uname)),syllable)
127
        PLATFORM=SYLLABLE
128
    endif
129
endif
130
131
 
3272 hendricks2 132
    SUBPLATFORM=
133
    ifeq ($(PLATFORM),LINUX)
134
        SUBPLATFORM=LINUX
135
    endif
136
    ifeq ($(PLATFORM),DINGOO)
137
        SUBPLATFORM=LINUX
138
        CROSS=mipsel-linux-
3972 hendricks2 139
    endif
3272 hendricks2 140
    ifeq ($(PLATFORM),GCW)
141
        SUBPLATFORM=LINUX
142
        CROSS=mipsel-linux-
3972 hendricks2 143
    endif
3272 hendricks2 144
    ifeq ($(PLATFORM),CAANOO)
145
        SUBPLATFORM=LINUX
146
    endif
147
endif
148
149
 
2476 hendricks2 150
EXESUFFIX_OVERRIDE ?=
151
152
 
4023 helixhorne 153
SYNTHESIS ?= 0
154
155
 
2398 hendricks2 156
# Like above, use absolute paths.
157
APPLE_FRAMEWORKS ?=/Library/Frameworks
158
# Without the resource files packaged in the .app bundle, the startupwindow produces errors, so give it an off switch.
3368 hendricks2 159
OSX_STARTUPWINDOW ?= 1
3278 hendricks2 160
2398 hendricks2 161
 
1739 helixhorne 162
#  USE_OPENGL     - enables basic OpenGL Polymost renderer
1820 terminx 163
#  POLYMER        - enables fancy Polymer renderer
164
#  NOASM          - disables the use of inline assembly pragmas
1739 helixhorne 165
#  LINKED_GTK     - enables compile-time linkage to GTK
166
#
167
POLYMER = 1
168
USE_OPENGL = 1
169
NOASM = 0
170
LINKED_GTK = 0
171
BUILD32_ON_64 ?= 0
1907 helixhorne 172
USE_LIBPNG ?= 1
2843 helixhorne 173
USE_LIBVPX ?= 1
2076 helixhorne 174
NETCODE ?= 1
3260 helixhorne 175
4107 helixhorne 176
 
3957 helixhorne 177
USE_LUAJIT_2_1 ?= 0
4107 helixhorne 178
1739 helixhorne 179
 
4066 helixhorne 180
USE_ASM64 ?= 0
181
182
 
1739 helixhorne 183
    POLYMER = 0
184
    USE_LIBVPX = 0
1933 helixhorne 185
endif
1739 helixhorne 186
187
 
188
#  CPLUSPLUS - 1 = enable C++ building
3116 hendricks2 189
#  RELEASE - 1 = no debugging
1739 helixhorne 190
#  DEBUGANYWAY - 1 = include debug symbols even when generating release code
191
#  DISABLEINLINING - 1 = compile inline functions as extern __fastcall instead of static inline
4247 hendricks2 192
#  FORCEWARNINGS - 1 = do not disable any compiler warnings within the source
3237 hendricks2 193
#  KRANDDEBUG - 1 = include logging of krand() calls for debugging the demo system
1739 helixhorne 194
#  MEMMAP - 1 = produce .memmap file when linking
4543 hendricks2 195
#  EFENCE  - 1 = compile with Electric Fence for malloc() debugging
1739 helixhorne 196
#  OPTLEVEL	- 0..3 = GCC optimization strategy
197
#  LTO - 1 = enable link-time optimization, for GCC 4.5 and up
1856 helixhorne 198
#
1739 helixhorne 199
CPLUSPLUS?=0
3116 hendricks2 200
RELEASE?=1
1739 helixhorne 201
DEBUGANYWAY?=0
202
KRANDDEBUG?=0
203
MEMMAP?=0
4543 hendricks2 204
DISABLEINLINING?=0
3116 hendricks2 205
FORCEWARNINGS?=0
3237 hendricks2 206
EFENCE?=0
1739 helixhorne 207
DMALLOC?=0
2254 helixhorne 208
PROFILER?=0
1739 helixhorne 209
MUDFLAP?=0
1850 terminx 210
1739 helixhorne 211
 
4298 helixhorne 212
# allocache()-allocated memory accesses with e.g. Valgrind.
213
# For debugging with Valgrind + GDB, see
214
# http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver
215
ALLOCACHE_AS_MALLOC?=0
216
217
 
3725 helixhorne 218
ifeq ($(RELEASE),0)
3728 Plagman 219
    OPTLEVEL?=0
3725 helixhorne 220
else
221
    OPTLEVEL?=2
222
endif
223
224
 
3422 helixhorne 225
    override STRIP=
3423 helixhorne 226
endif
3422 helixhorne 227
ifneq ($(DEBUGANYWAY),0)
228
    override STRIP=
3423 helixhorne 229
endif
3422 helixhorne 230
231
 
3957 helixhorne 232
    # FIXME: Lunatic builds with LTO don't start up properly as the required
233
    # symbol names are apparently not exported.
234
    override LTO=0
235
endif
236
237
 
3122 hendricks2 238
    LTO=1
239
    ifneq (0,$(CLANG))
240
        ifeq ($(PLATFORM), WINDOWS)
241
            LTO=0
242
        endif
243
    endif
244
endif
245
246
 
4547 hendricks2 247
COMPILERFLAGS=
4543 hendricks2 248
249
 
4547 hendricks2 250
    COMMONFLAGS += $(OPTIMIZATIONS)
251
endif
4543 hendricks2 252
253
 
4547 hendricks2 254
4543 hendricks2 255
 
4547 hendricks2 256
ifneq (0,$(CLANG))
257
    ifneq ($(PLATFORM),WII)
258
        DEBUGFLAG=-ggdb
259
    endif
260
endif
261
ifneq ($(RELEASE)$(DEBUGANYWAY),10)
4543 hendricks2 262
    # debug build or DEBUGANYWAY=1 --> -g flag
263
    OPTIMIZATIONS += $(DEBUGFLAG)
4547 hendricks2 264
endif
4543 hendricks2 265
266
 
4547 hendricks2 267
CPPONLYFLAGS= -fno-exceptions -fno-rtti -Wno-write-strings
268
ASFORMAT=elf$(SYSBITS)
4543 hendricks2 269
ASFLAGS=-s -f $(ASFORMAT) #-g
270
LINKERFLAGS=
271
LIBS=-lm
272
LIBDIRS=
273
274
 
3278 hendricks2 275
    F_NO_STACK_PROTECTOR := -fno-stack-protector
3096 hendricks2 276
    # there are some link-time issues with stack protectors, so make it possible to override
277
    F_STACK_PROTECTOR_ALL ?= -fstack-protector-all
278
    ifeq (0,$(CLANG))
279
        F_JUMP_TABLES := -fjump-tables
280
    endif
281
    M_TUNE_GENERIC := -mtune=generic
282
    M_STACKREALIGN := -mstackrealign
283
    W_STRICT_OVERFLOW := -Wno-strict-overflow
3963 helixhorne 284
endif
3096 hendricks2 285
286
 
3278 hendricks2 287
    ifndef COMPILERTARGET
288
        COMPILERTARGET:=$(strip $(shell $(CC) -dumpmachine))
289
    endif
290
291
 
292
        SYSARCH:=x86_64
293
        SYSBITS=64
4552 hendricks2 294
    endif
3278 hendricks2 295
296
 
4543 hendricks2 297
else
4552 hendricks2 298
ifneq (1,$(BUILD32_ON_64))
299
    ifeq ($(findstring x86_64,$(ARCH)),x86_64)
300
        SYSBITS=64
301
    endif
302
    ifeq ($(ARCH),)
303
        ifeq ($(findstring x86_64,$(SYSARCH)),x86_64)
304
            SYSBITS=64
305
        endif
306
    endif
307
endif
3278 hendricks2 308
endif
4552 hendricks2 309
3278 hendricks2 310
 
3096 hendricks2 311
    ifndef DARWINVERSION
3278 hendricks2 312
        DARWINVERSION:=$(strip $(shell uname -r | cut -d . -f 1))
313
    endif
314
4644 hendricks2 315
 
316
	DARWIN10 ?= 0
317
    ifeq (1,$(strip $(shell expr $(DARWINVERSION) \< 10)))
3096 hendricks2 318
        override DARWIN9 := 1
4644 hendricks2 319
    endif
3096 hendricks2 320
    ifeq (1,$(strip $(shell expr $(DARWINVERSION) \< 11)))
4644 hendricks2 321
        override DARWIN10 := 1
322
    endif
323
3096 hendricks2 324
 
4543 hendricks2 325
3096 hendricks2 326
 
327
        F_JUMP_TABLES :=
328
        W_STRICT_OVERFLOW :=
329
    endif
330
331
 
332
        COMMONFLAGS += $(F_NO_STACK_PROTECTOR)
4543 hendricks2 333
    else
3096 hendricks2 334
        ifeq ($(findstring ppc,$(ARCH)),ppc)
335
            COMMONFLAGS += $(F_NO_STACK_PROTECTOR)
4543 hendricks2 336
        endif
3096 hendricks2 337
    endif
338
    ifneq (0,$(OSX_STARTUPWINDOW))
3334 hendricks2 339
        COMPILERFLAGS+= -DOSX_STARTUPWINDOW
4543 hendricks2 340
    endif
3334 hendricks2 341
endif
3096 hendricks2 342
343
 
4543 hendricks2 344
 
4555 hendricks2 345
    # Debugging disabled
346
    COMMONFLAGS += $(F_NO_STACK_PROTECTOR)
347
else
348
    # Debugging enabled
349
    ifneq (0,$(KRANDDEBUG))
350
        COMMONFLAGS += -fno-inline -fno-inline-functions -fno-inline-functions-called-once
351
    endif
352
    ifeq (1,$(SDL_TARGET))
353
        COMPILERFLAGS += -DNOSDLPARACHUTE
354
    endif
355
endif
356
357
 
3096 hendricks2 358
    ifeq ($(PLATFORM), WII)
359
        OPTOPT=
360
    else
361
        OPTOPTARCH=$(ARCH)
362
        ifeq (,$(OPTOPTARCH))
363
            OPTOPTARCH=$(SYSARCH)
364
        endif
365
366
 
367
            OPTOPT=-march=pentium3 $(M_TUNE_GENERIC) -mmmx
368
            # -msse2 -mfpmath=sse,387 -malign-double $(M_STACKREALIGN)
369
        else
370
            OPTOPT=
371
        endif
372
    endif
373
endif
374
375
 
1739 helixhorne 376
    RELEASE=0
377
endif
378
ifneq (0,$(PROFILER))
379
    DEBUGANYWAY=1
380
endif
381
382
 
383
 
384
 
2520 hendricks2 385
 
3278 hendricks2 386
    ifeq (1,$(strip $(shell expr $(GCC_MINOR) \>= 1)))
387
        COMPILERFLAGS+= -Wno-attributes
4543 hendricks2 388
    endif
3278 hendricks2 389
endif
390
391
 
3691 helixhorne 392
ifeq (1,$(strip $(shell expr $(GCC_MAJOR) \>= 4)))
393
    ifeq (1,$(strip $(shell expr $(GCC_MINOR) \>= 3)))
394
        CPPONLYFLAGS+= -Wno-narrowing
4547 hendricks2 395
    endif
3691 helixhorne 396
endif
397
398
 
2685 hendricks2 399
    override USE_LIBVPX = 0
400
    override NETCODE = 0
4390 terminx 401
endif
2685 hendricks2 402
ifeq ($(PLATFORM),GCW)
3972 hendricks2 403
    override USE_LIBVPX = 0
404
endif
405
ifeq ($(PLATFORM),DINGOO)
406
    override USE_LIBVPX = 0
407
endif
408
2685 hendricks2 409
 
1933 helixhorne 410
    # On Windows, we link statically to libvpx
2038 helixhorne 411
    LIBS+= -lvpx
4543 hendricks2 412
endif
1933 helixhorne 413
1852 helixhorne 414
 
2292 helixhorne 415
 
4298 helixhorne 416
    COMPILERFLAGS += -DDEBUG_ALLOCACHE_AS_MALLOC
4543 hendricks2 417
endif
4298 helixhorne 418
419
 
4020 helixhorne 420
# for a list of possible UBSan options.
421
# Clang 3.2 does only supports -fsanitize=address for the AddressSanitizer
422
#    CLANG_DEBUG_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow,object-size -fsanitize-undefined-trap-on-error
4644 hendricks2 423
#    CLANG_DEBUG_FLAGS := $(CLANG_DEBUG_FLAGS),signed-integer-overflow
4451 helixhorne 424
#    CLANG_DEBUG_FLAGS := $(CLANG_DEBUG_FLAGS),unsigned-integer-overflow
425
4020 helixhorne 426
 
1739 helixhorne 427
    # Debugging disabled
428
    ifeq (0,$(CLANG))
2672 helixhorne 429
        COMMONFLAGS += -funswitch-loops
4543 hendricks2 430
        ifeq (1,$(strip $(shell expr $(GCC_MAJOR) \< 4)))
3278 hendricks2 431
            LTO=0
432
        endif
433
        ifeq (1,$(strip $(shell expr $(GCC_MAJOR) = 4)))
434
            ifeq (1,$(strip $(shell expr $(GCC_MINOR) \< 6)))
435
                LTO=0
436
            endif
437
        endif
438
    endif
2182 helixhorne 439
    ifeq (0,$(DEBUGANYWAY))
2040 helixhorne 440
        COMMONFLAGS += -fomit-frame-pointer
4543 hendricks2 441
        COMPILERFLAGS += -DNDEBUG
442
    else
3138 Plagman 443
        COMPILERFLAGS += -DDEBUGGINGAIDS
4543 hendricks2 444
#        ifneq (0,$(CLANG))
4644 hendricks2 445
#            COMMONFLAGS += $(CLANG_DEBUG_FLAGS)
446
#        endif
447
    endif
2040 helixhorne 448
    ifneq (0,$(LTO))
1856 helixhorne 449
        COMPILERFLAGS += -DUSING_LTO
4543 hendricks2 450
        COMMONFLAGS += -flto
451
        # We don't need the following since we don't make intermediate .a files any more.
452
#        ifeq (1,$(strip $(shell expr $(GCC_MAJOR) \>= 4)))
453
#            ifeq (1,$(strip $(shell expr $(GCC_MINOR) \>= 9)))
454
#                COMMONFLAGS += -ffat-lto-objects
455
#            endif
456
#        endif
457
    endif
1856 helixhorne 458
else
1739 helixhorne 459
    # Debugging enabled
460
    ifeq (0,$(DEBUGANYWAY))
2270 helixhorne 461
        COMPILERFLAGS += -DDEBUGGINGAIDS
4543 hendricks2 462
    else
2270 helixhorne 463
        COMPILERFLAGS += -DDEBUGGINGAIDS=2
4543 hendricks2 464
    endif
2270 helixhorne 465
466
 
4644 hendricks2 467
#        COMMONFLAGS += $(CLANG_DEBUG_FLAGS)
468
#    endif
469
    ifeq ($(SUBPLATFORM),LINUX)
3272 hendricks2 470
        LIBS+=-rdynamic
4543 hendricks2 471
    endif
1770 plagman 472
    ifneq (0,$(MUDFLAP))
1850 terminx 473
        LIBS+= -lmudflapth
4543 hendricks2 474
        COMMONFLAGS += -fmudflapth
475
    endif
1850 terminx 476
    ifneq (0,$(PROFILER))
1739 helixhorne 477
        ifneq ($(PLATFORM),DARWIN)
3278 hendricks2 478
            LIBS+= -lprofiler
4543 hendricks2 479
        endif
3278 hendricks2 480
        COMMONFLAGS += -pg
4543 hendricks2 481
    endif
1739 helixhorne 482
    ifneq (0,$(KRANDDEBUG))
483
        COMPILERFLAGS += -DKRANDDEBUG=1
4543 hendricks2 484
    endif
1739 helixhorne 485
endif
486
487
 
3278 hendricks2 488
ifeq (0,$(CLANG))
2672 helixhorne 489
#    W_NO_UNUSED_RESULT := $(shell echo '' | $(CC) -E -Wno-unused-result - 2>/dev/null && echo -Wno-unused-result)
2972 hendricks2 490
#    W_NO_UNUSED_RESULT := $(findstring -Wno-unused-result,$(W_NO_UNUSED_RESULT))
491
    ifeq (1,$(strip $(shell expr $(GCC_MAJOR) \>= 4)))
3278 hendricks2 492
        ifeq (1,$(strip $(shell expr $(GCC_MINOR) \>= 4)))
493
            W_NO_UNUSED_RESULT := -Wno-unused-result
494
        endif
495
    endif
496
endif
2159 helixhorne 497
1791 helixhorne 498
 
3097 hendricks2 499
    -Wpointer-arith \
2797 helixhorne 500
    -Wextra \
501
    -Wno-char-subscripts \
4543 hendricks2 502
    #-Wstrict-prototypes \
2797 helixhorne 503
    #-Waggregate-return \
504
    #-Wwrite-strings \
505
    #-Wcast-qual -Wcast-align \
506
    #-Waddress -Wlogical-op
507
508
 
2672 helixhorne 509
    CWARNS+= -Wno-unused-value -Wno-parentheses
4543 hendricks2 510
endif
2159 helixhorne 511
512
 
4543 hendricks2 513
514
 
515
516
 
3260 helixhorne 517
    COMPILERFLAGS+= -DNETCODE_DISABLE
4543 hendricks2 518
endif
3260 helixhorne 519
3148 helixhorne 520
 
3260 helixhorne 521
 
3957 helixhorne 522
# LuaJIT standalone interpreter executable:
523
LUAJIT:=luajit
4000 helixhorne 524
# Options to "luajit -b" for synthesis. Since it runs on Linux, we need to tell
4023 helixhorne 525
# the native LuaJIT to emit PE object files.
526
ifeq ($(PLATFORM),WINDOWS)
4319 hendricks2 527
    LUAJIT_BCOPTS := -o windows
528
    ifeq (32,$(SYSBITS))
4543 hendricks2 529
        LUAJIT_BCOPTS += -a x86
4319 hendricks2 530
    endif
531
    ifeq (64,$(SYSBITS))
4543 hendricks2 532
        LUAJIT_BCOPTS += -a x64
4319 hendricks2 533
    endif
534
endif
4023 helixhorne 535
3148 helixhorne 536
 
537
    # FIXME: Lunatic doesn't build with inlining because of wacky include
538
    # chains!
539
    override DISABLEINLINING=1
540
541
 
4286 helixhorne 542
        # FIXME: Lunatic C++ doesn't build because otherwise it doesn't find
543
        # INT32_MIN and the like.
544
        COMPILERFLAGS+= -D__STDC_LIMIT_MACROS
4543 hendricks2 545
    endif
4286 helixhorne 546
547
 
4543 hendricks2 548
    ifneq ($(USE_LUAJIT_2_1),0)
4107 helixhorne 549
        COMPILERFLAGS+= -DUSE_LUAJIT_2_1
4543 hendricks2 550
    endif
4107 helixhorne 551
3148 helixhorne 552
 
3785 helixhorne 553
    ifndef DEFS_BC_SIZE
554
        DEFS_BC_SIZE := $(shell $(LUAJIT) -bg -t h source/lunatic/defs.ilua -)
4543 hendricks2 555
        DEFS_BC_SIZE := $(word 3, $(DEFS_BC_SIZE))
3785 helixhorne 556
        # Pass it to the sub-makes, too.
4238 helixhorne 557
        export DEFS_BC_SIZE
3785 helixhorne 558
    endif
559
    # Determine size of defs_m32.ilua bytecode once.
4238 helixhorne 560
    ifndef DEFS_M32_BC_SIZE
561
        DEFS_M32_BC_SIZE := $(shell $(LUAJIT) -bg -t h source/lunatic/defs_m32.ilua -)
4543 hendricks2 562
        DEFS_M32_BC_SIZE := $(word 3, $(DEFS_M32_BC_SIZE))
4238 helixhorne 563
        export DEFS_M32_BC_SIZE
564
    endif
565
    COMPILERFLAGS+= -DLUNATIC_DEFS_BC_SIZE=$(DEFS_BC_SIZE) -DLUNATIC_DEFS_M32_BC_SIZE=$(DEFS_M32_BC_SIZE)
4543 hendricks2 566
3517 helixhorne 567
 
3148 helixhorne 568
        LIBS+= -lluajit
4543 hendricks2 569
    else
3148 helixhorne 570
        LIBS+= -lluajit-5.1
4543 hendricks2 571
    endif
3148 helixhorne 572
endif
573
574
 
575
576
 
3116 hendricks2 577
    COMPILERFLAGS+= -DDISABLE_INLINING
4543 hendricks2 578
endif
3116 hendricks2 579
ifneq (0,$(FORCEWARNINGS))
3237 hendricks2 580
    COMPILERFLAGS+= -DFORCE_WARNINGS
4543 hendricks2 581
endif
3237 hendricks2 582
3116 hendricks2 583
 
2718 helixhorne 584
ifdef EDUKE32_MY_DEVELOPER_ID
585
    COMPILERFLAGS+= -DMY_DEVELOPER_ID=$(EDUKE32_MY_DEVELOPER_ID)
4543 hendricks2 586
endif
2718 helixhorne 587
588
 
1852 helixhorne 589
    COMPILERFLAGS+= -DUSE_LIBPNG
4543 hendricks2 590
endif
1852 helixhorne 591
ifneq (0,$(USE_LIBVPX))
1933 helixhorne 592
    COMPILERFLAGS+= -DUSE_LIBVPX
4543 hendricks2 593
endif
1933 helixhorne 594
1739 helixhorne 595
 
2059 hendricks2 596
    LIBS+= -lefence
4543 hendricks2 597
    COMPILERFLAGS+= -DEFENCE
598
endif
2059 hendricks2 599
ifneq (0,$(DMALLOC))
2254 helixhorne 600
    LIBS+= -ldmalloc
4543 hendricks2 601
    COMPILERFLAGS+= -DDMALLOC
602
endif
2254 helixhorne 603
2059 hendricks2 604
 
4543 hendricks2 605
EXESUFFIX=
1739 helixhorne 606
DLLSUFFIX=.so
4543 hendricks2 607
4513 hendricks2 608
 
609
 
4543 hendricks2 610
SDL_FRAMEWORK ?= 0
4644 hendricks2 611
4543 hendricks2 612
 
613
    L_SSP := -lssp
614
endif
615
616
 
617
# Search for STDCPPLIB below and change it to -lsupc++.
618
619
 
620
SDL_LIB=-l$(SDLNAME)
621
SDL_MIXER_LIB=-l$(SDLNAME)_mixer
622
623
 
624
    RENDERTYPE=SDL
625
    MIXERTYPE=SDL
626
    COMPILERFLAGS+= -DHAVE_INTTYPES
627
    GTKCOMPAT32=0
628
    SDL_FRAMEWORK=0
629
630
 
631
    # presumably take care for us.
632
    STDCPPLIB:=
633
634
 
635
        override USE_OPENGL=0
636
        override NOASM=1
637
    endif
638
    ifeq ($(PLATFORM),DINGOO)
639
        override USE_OPENGL=0
640
        override NOASM=1
641
    endif
642
643
 
644
        ifeq (1,$(BUILD32_ON_64))
645
            # On my 64bit Gentoo these are the 32bit emulation libs
646
            LIBS+= -m32
647
            LIBDIRS+= -L/emul/linux/x86/usr/lib
648
            COMMONFLAGS+= -m32
649
            # Override WITHOUT_GTK=0
650
            GTKCOMPAT32=1
651
        else
652
            override NOASM=1
653
        endif
654
    endif
655
4555 hendricks2 656
 
657
    ifeq (0,$(CLANG))
658
        COMMONFLAGS	+= -fno-pic
659
    endif
660
endif
4543 hendricks2 661
ifeq ($(PLATFORM),DARWIN)
662
    COMPILERFLAGS+= -DUNDERSCORES
663
    ASFORMAT=macho$(SYSBITS)
664
    ASFLAGS+= -DUNDERSCORES
665
666
 
4646 hendricks2 667
    # COMPILERFLAGS+= -Iplatform/Apple/include
668
4543 hendricks2 669
 
4644 hendricks2 670
        LIBDIRS+= -L/opt/local/lib
671
        COMPILERFLAGS+= -I/opt/local/include
672
    endif
673
    ifneq ($(shell brew --version &>/dev/null; echo $$?),127)
674
        LIBDIRS+= -L/usr/local/lib
675
        COMPILERFLAGS+= -I/usr/local/include
676
    endif
677
    ifneq ($(shell fink --version &>/dev/null; echo $$?),127)
678
        LIBDIRS+= -L/sw/lib
679
        COMPILERFLAGS+= -I/sw/include
680
    endif
681
682
 
4543 hendricks2 683
    MIXERTYPE     = SDL
684
    STDCPPLIB:=-lstdc++
685
    COMPILERFLAGS    += -DHAVE_INTTYPES
686
    DLLSUFFIX=.dylib
4644 hendricks2 687
    GTKCOMPAT32    = 0
4543 hendricks2 688
    WITHOUT_GTK   ?= 1
4548 hendricks2 689
4543 hendricks2 690
 
691
        SDL_INCLUDES=-I$(APPLE_FRAMEWORKS)/SDL.framework/Headers -I$(APPLE_FRAMEWORKS)/SDL_mixer.framework/Headers
692
        SDL_LIB=-l$(SDLNAME)main -Wl,-framework,SDL -Wl,-rpath -Wl,"@loader_path/../Frameworks"
693
        SDL_MIXER_LIB=-Wl,-framework,SDL_mixer
694
    endif
695
696
 
697
        COMPILERFLAGS += -DDARWIN9
698
    endif
699
700
 
701
        ARCH=-arch i386
702
    else
703
        # ASM won't work on PowerPC or x86_64
704
        override NOASM=1
705
    endif
706
707
 
708
        ifeq (,$(ARCH))
709
            ifneq ($(findstring x86_64,$(SYSARCH)),x86_64)
710
                LINKERFLAGS += -read_only_relocs suppress
711
            endif
712
        else
713
            LINKERFLAGS += -read_only_relocs suppress
714
        endif
715
    endif
716
4555 hendricks2 717
 
718
endif
4543 hendricks2 719
ifeq ($(PLATFORM),WINDOWS)
720
    COMPILERFLAGS+= -DUNDERSCORES -DHAVE_INTTYPES -Iplatform/Windows/include
721
    LINKERFLAGS+= -static-libgcc
722
    ASFORMAT=win$(SYSBITS)
723
    ASFLAGS+= -DUNDERSCORES
724
725
 
726
    RENDERTYPE?=SDL
727
    MIXERTYPE?=WIN
728
    ifneq ($(RENDERTYPE),SDL)
729
        ifeq ($(MIXERTYPE),SDL)
730
            MIXERTYPE:=WIN
731
        endif
732
    endif
733
734
 
735
    ifeq ($(SDL_TARGET),1)
736
        SDL_MIXER_LIB=platform/Windows/lib$(WINLIB)/SDL_mixer.lib
737
    endif
738
739
 
740
    SDLCONFIG=
741
    SDL_FRAMEWORK=1
742
    EXESUFFIX=.exe
743
    DLLSUFFIX=.dll
744
    LIBDIRS+= -Lplatform/Windows/lib$(WINLIB)
4553 hendricks2 745
    LIBS+= -Wl,--enable-auto-import -lmingwex -lgdi32 -lcomctl32 -lwinmm $(L_SSP) -lwsock32 -lws2_32 -lshlwapi
4543 hendricks2 746
    ifeq (0,$(CLANG))
747
        LIBS+= -mwindows
748
    endif
749
    #-lshfolder
750
    STDCPPLIB:=-lstdc++
751
    ifeq ($(findstring x86_64,$(SYSARCH)),x86_64)
752
        ifneq (1,$(BUILD32_ON_64))
753
            override NOASM=1
754
        endif
755
    endif
756
4555 hendricks2 757
 
758
endif
4543 hendricks2 759
ifeq ($(PLATFORM),BSD)
760
    COMPILERFLAGS+= -I/usr/X11R6/include
761
762
 
763
    MIXERTYPE=SDL
764
    COMPILERFLAGS+= -DHAVE_INTTYPES
765
    ifneq ($(findstring i386,$(SYSARCH)),i386)
766
        override NOASM=1
767
    endif
768
    STDCPPLIB:=-lstdc++
769
endif
770
ifeq ($(PLATFORM),BEOS)
771
    override NOASM=1
772
773
 
774
    MIXERTYPE=SDL
775
    STDCPPLIB:=-lstdc++
776
endif
777
ifeq ($(PLATFORM),SKYOS)
778
    RENDERTYPE=SDL
779
    MIXERTYPE=SDL
780
    EXESUFFIX=.app
781
    override NOASM=1
782
    COMPILERFLAGS+= -DUNDERSCORES -I/boot/programs/sdk/include/sdl
783
    SDLCONFIG=
784
    LIBS+= -lSDL -lnet
785
endif
786
ifeq ($(PLATFORM),WII)
787
    RENDERTYPE=SDL
788
    MIXERTYPE=SDL
789
    SDL_INCLUDES=
790
    EXESUFFIX=.elf
791
    override USE_OPENGL=0
792
    override POLYMER=0
793
    override NOASM=1
794
    override WITHOUT_GTK=1
795
    # -msdata=eabi
796
    COMMONFLAGS+= -g -mtune=750 -meabi -mhard-float
797
    COMPILERFLAGS+= -DGEKKO -DHAVE_INTTYPES -D__POWERPC__ -I$(LIBOGC_INC) -I$(PORTLIBS)/include -Iplatform/Wii/include
798
    SDLCONFIG=
799
    SDL_TARGET=1
800
    SDL_FRAMEWORK=1
801
    LIBDIRS += -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib -Lplatform/Wii/lib
4553 hendricks2 802
endif
4543 hendricks2 803
ifeq ($(PLATFORM),QNX)
804
    RENDERTYPE=SDL
805
    MIXERTYPE=SDL
806
    override USE_OPENGL=0
807
    override NOASM=1
808
    STDCPPLIB:=-lstdc++
809
    LIBS+= -lsocket
810
endif
811
ifeq ($(PLATFORM),SUNOS)
812
    RENDERTYPE=SDL
813
    MIXERTYPE=SDL
814
    override USE_OPENGL=0
815
    override NOASM=1
816
    STDCPPLIB:=-lstdc++
817
    LIBS+= -lsocket -lnsl
818
endif
819
ifeq ($(PLATFORM),SYLLABLE)
820
    RENDERTYPE=SDL
821
    MIXERTYPE=SDL
822
    override USE_OPENGL=0
823
    override NOASM=1
824
endif
825
ifeq ($(PLATFORM),GCW)
826
    COMPILERFLAGS += -D__OPENDINGUX__
827
endif
828
ifeq ($(PLATFORM),DINGOO)
829
    COMPILERFLAGS += -D__OPENDINGUX__
830
endif
831
832
 
833
    EXESUFFIX=$(EXESUFFIX_OVERRIDE)
834
endif
835
836
 
837
    ifneq (,$(STDCPPLIB))
838
        STDCPPLIB:=-Xlinker $(STDCPPLIB)
839
    endif
840
endif
841
842
 
843
    SDLCONFIG ?= sdl2-config
844
    SDLNAME ?= SDL2
845
endif
846
ifeq ($(SDL_TARGET),1)
847
    SDLCONFIG ?= sdl-config
848
    SDLNAME ?= SDL
849
endif
850
851
 
852
    SDLVERSION:=$(strip $(shell $(SDLCONFIG) --version))
853
    ifneq ($(SDLVERSION),)
854
        SDLROOT:=$(strip $(shell $(SDLCONFIG) --prefix))
855
    endif
856
endif
857
858
 
859
860
 
861
    COMPILERFLAGS += -DSDL_TARGET=$(SDL_TARGET)
862
863
 
864
        COMPILERFLAGS += -DSDL_FRAMEWORK
865
    endif
866
867
 
868
        ifeq ($(SDL_FRAMEWORK),1)
869
            ifeq ($(PLATFORM),DARWIN)
870
                LIBS        += -Wl,-framework,SDL
871
                COMPILERFLAGS+= -I$(APPLE_FRAMEWORKS)/SDL.framework/Headers \
872
                                -I$(APPLE_FRAMEWORKS)/SDL_mixer.framework/Headers
873
            endif
874
        else
875
            ifneq ($(SDLCONFIG),)
876
                SDLCONFIG_COMMONFLAGS:=$(subst -Dmain=SDL_main,,$(strip $(shell $(SDLCONFIG) --cflags)))
877
                SDLCONFIG_LIBS:=$(strip $(shell $(SDLCONFIG) --libs))
878
879
 
880
                COMMONFLAGS+= $(SDLCONFIG_COMMONFLAGS)
881
            endif
882
        endif
883
    else
884
        COMPILERFLAGS += -D_GNU_SOURCE=1
885
        ifneq ($(SDL_STATIC),0)
886
            ifneq ($(SDL_TARGET),1) # Since SDL2 is under the zlib license, link statically if possible.
887
                LIBS+= -static
888
            endif
889
        endif
890
        LIBS+= -l$(SDLNAME)main -l$(SDLNAME) -lmingw32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lversion
891
    endif
892
893
 
894
        HAVE_GTK2=0
895
    else
896
        ifneq (No,$(shell $(PKG_CONFIG) --exists gtk+-2.0 || echo No))
4547 hendricks2 897
            HAVE_GTK2=1
4543 hendricks2 898
            # On my 64bit Gentoo box I have Cairo enabled which means the libs list includes
899
            # -lpangocairo-1.0 and -lcairo, however the 32bit compatibility libraries don't
900
            # include cairo, so we need to filter out those -l switches in order to link
901
            ifneq ($(LINKED_GTK),0)
902
                ifeq ($(GTKCOMPAT32),1)
903
                    LIBS+= $(shell $(PKG_CONFIG) --libs gtk+-2.0 | sed 's/\s-l\(pango\)\{0,1\}cairo\S*\s/ /g')
4547 hendricks2 904
                else
4543 hendricks2 905
                    LIBS+= $(shell $(PKG_CONFIG) --libs gtk+-2.0)
4547 hendricks2 906
                endif
4543 hendricks2 907
            endif
908
            COMPILERFLAGS += -DHAVE_GTK2 $(shell $(PKG_CONFIG) --cflags gtk+-2.0)
4547 hendricks2 909
        else
4543 hendricks2 910
            HAVE_GTK2=0
911
        endif
912
    endif
913
914
 
915
    ifneq ($(MIXERTYPE),WIN)
916
        LIBS += $(SDL_MIXER_LIB)
917
    endif
918
    LIBS += $(SDL_LIB)
919
endif
920
ifeq ($(RENDERTYPE),WIN)
921
    LIBS+= -ldxguid
922
endif
923
924
 
925
ifeq ($(PLATFORM),WINDOWS)
926
    ifeq ($(RENDERTYPE),SDL)
927
    SDL_LIB:=-l$(SDLNAME)main $(SDL_LIB)
928
        ifeq ($(MIXERTYPE),WIN)
929
            LIBS+= -ldxguid_sdl
930
        endif
931
    endif
932
endif
933
ifeq ($(PLATFORM),WII)
934
    LIBS+= -laesnd_tueidj -lpng -lfat -lwiiuse -lbte -logc -lm -lwiikeyboard
935
endif
936
937
 
938
939
 
940
    COMPILERFLAGS+= -DUSE_OPENGL
941
endif
942
ifneq (0,$(NOASM))
943
    COMPILERFLAGS+= -DNOASM
944
endif
945
ifneq (0,$(USE_ASM64))
946
    COMPILERFLAGS+= -DUSE_ASM64
947
endif
948
ifneq (0,$(LINKED_GTK))
949
    COMPILERFLAGS+= -DLINKED_GTK
950
endif
951
952
 
953
 ifneq (0,$(USE_OPENGL))
954
  COMPILERFLAGS+= -DPOLYMER
955
 endif
956
endif
957
958
 
959
ifeq (1,$(STATICSTDCPP))
960
    STATICSTDCPP= -static
961
endif
962
ifeq (0,$(STATICSTDCPP))
963
    STATICSTDCPP= -shared
964
endif
965
966
 
967
 
968
    ifneq ($(PLATFORM),WII)
969
        LIBS+= -ldl
970
    endif
971
    ifneq ($(PLATFORM),DARWIN)
4644 hendricks2 972
        LIBS+= -pthread
973
    endif
974
endif
4543 hendricks2 975
976
 
977
    ifneq ($(USE_LIBPNG),0)
978
        LIBS+= -lpng_mini -lz_mini
979
    endif
980
else
981
    ifeq ($(PLATFORM),DARWIN)
982
        ifneq ($(USE_LIBPNG),0)
983
            LIBS+= -lpng # -lz
984
        endif
985
    else
986
        ifneq ($(USE_LIBPNG),0)
987
            LIBS+= -lpng -lz
988
        endif
989
    endif
990
endif
991
992
 
993
 
994
    ifneq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
995
        LINKERFLAGS+= -Wl,--large-address-aware
996
    endif
997
endif
998
999
 
1000
ifeq ($(PLATFORM),DARWIN)
1001
    LINKERFLAGS+=-Wl,-map -Wl,$@.memmap
1002
else
1003
    LINKERFLAGS+=-Wl,-Map=$@.memmap
1004
endif
1005
endif
1006
1007
 
1008
    LINKERFLAGS+=-pg
1009
endif
1010
ifeq ($(PLATFORM),WII)
1011
    LINKERFLAGS+= -mrvl -meabi -mhard-float -Wl,--gc-sections
1012
    # -msdata=eabi
1013
endif
1014
1015
 
4565 hendricks2 1016
ifeq (,$(VC_REV))
1017
    ifneq (,$(wildcard EDUKE32_REVISION))
1018
        VC_REV    := $(shell cat EDUKE32_REVISION)
1019
    endif
1020
endif
1021
ifeq (,$(VC_REV))
1022
    VC_REV    := $(shell svn info 2>&1 | grep Revision | cut -d' ' -f2)
1023
endif
1024
ifeq (,$(VC_REV))
1025
    VC_REV    := $(shell git svn info 2>&1 | grep Revision | cut -d' ' -f2)
1026
endif
1027
ifneq (,$(VC_REV)$(VC_REV_CUSTOM))
1028
    REVFLAG += -DREV="\"r$(VC_REV)$(VC_REV_CUSTOM)\""
1029
endif
1030
1031
 
4543 hendricks2 1032
LINKER=$(L_CC)
1033
ifneq ($(CPLUSPLUS),0)
1034
    COMPILER=$(CXX) $(CPPONLYFLAGS)
4547 hendricks2 1035
    LINKER=$(L_CXX)
4543 hendricks2 1036
endif
1037
1038
 
4513 hendricks2 1039
    COMMONFLAGS+= $(CUSTOMOPT)
4543 hendricks2 1040
endif
4513 hendricks2 1041
ifneq (,$(CFLAGS))
4543 hendricks2 1042
    COMMONFLAGS+= $(CFLAGS)
1043
endif
1044
ifneq (,$(CXXFLAGS))
4547 hendricks2 1045
    CPPONLYFLAGS+= $(CXXFLAGS)
1046
endif
1047
ifneq (,$(LDFLAGS))
1048
    LINKERFLAGS+= $(LDFLAGS)
1049
endif
1050
4543 hendricks2 1051
 
1052
RECIPE_IF = if
1053
BUILD_SETTINGS_COMPILER = \033[1;36mcompiler: \033[0;36m\"$(COMPILER) $(COMMONFLAGS) $(COMPILERFLAGS)\"
1054
BUILD_SETTINGS_ASSEMBLER = \033[1;36massembler: \033[0;36m\"$(AS) $(ASFLAGS)\"
1055
BUILD_SETTINGS_LINKER = \033[1;36mlinker: \033[0;36m\"$(LINKER) $(COMMONFLAGS) $(LINKERFLAGS) $(LIBDIRS) $(LIBS) $(STATICSTDCPP) $(STDCPPLIB)\"
1056
ifeq (0,$(NOASM))
1057
    BUILD_SETTINGS = printf "$(BUILD_SETTINGS_COMPILER)\n$(BUILD_SETTINGS_ASSEMBLER)\n$(BUILD_SETTINGS_LINKER)\033[0m\n"
1058
else
1059
    BUILD_SETTINGS = printf "$(BUILD_SETTINGS_COMPILER)\n$(BUILD_SETTINGS_LINKER)\033[0m\n"
1060
endif
1061
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using:\033[0m\n"; $(BUILD_SETTINGS)
1062
BUILD_ECHOFLAGS = printf "\033[K\033[1;36mEnded compilation in this directory using:\n$(BUILD_SETTINGS_COMPILER)\033[0m\n"
1063
BUILD_FINISHED = printf "\033[K\033[1;36mBuild successful:\033[0m\n"
1064
COMPILE_STATUS = printf "\033[K\033[0mBuilding object \033[1m$@\033[0m...\033[0m\r"
1065
COMPILE_OK = printf "\033[K\033[0;32mBuilt object \033[1;32m$@\033[0;32m \033[0m\n"
1066
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
1067
RECIPE_RESULT_COMPILE = ; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
1068
ONESTEP_STATUS = printf "\033[K\033[0mBuilding executable \033[1m$@\033[0m...\033[0m\r"
1069
ONESTEP_OK = printf "\033[K\033[0;32mBuilt executable \033[1;32m$@\033[0;32m \033[0m\n"
1070
ONESTEP_FAILED = printf "\033[K\033[0;31mFailed building executable \033[1;31m$@\033[0;31m!\033[0m\n"; exit 1
1071
RECIPE_RESULT_ONESTEP = ; then $(ONESTEP_OK); else $(ONESTEP_FAILED); fi
1072
ARCHIVE_STATUS = printf "\033[K\033[0mCreating library archive \033[1m$@\033[0m...\033[0m\r"
1073
ARCHIVE_OK = printf "\033[K\033[0;32mCreated library archive \033[1;32m$@\033[0;32m \033[0m\n"
1074
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
1075
RECIPE_RESULT_ARCHIVE = ; then $(ARCHIVE_OK); else $(ARCHIVE_FAILED); fi
1076
LINK_STATUS = printf "\033[K\033[0;0mLinking executable \033[1m$@\033[0;0m...\033[0m\r"
1077
LINK_OK = printf "\033[K\033[0;32mLinked executable \033[1;32m$@\033[0;32m \033[0m\n"
1078
LINK_FAILED = printf "\033[K\033[0;31mFailed linking executable \033[1;31m$@\033[0;31m!\033[0m\n"; exit 1
1079
RECIPE_RESULT_LINK = ; then $(LINK_OK); else $(LINK_FAILED); fi
1080
else
1081
RECIPE_IF =
1082
BUILD_STARTED =
1083
BUILD_ECHOFLAGS =
1084
BUILD_FINISHED =
1085
COMPILE_STATUS =
1086
COMPILE_OK = true
1087
COMPILE_FAILED = false; exit 1
1088
RECIPE_RESULT_COMPILE =
1089
ONESTEP_STATUS =
1090
ONESTEP_OK = true
1091
ONESTEP_FAILED = false; exit 1
1092
RECIPE_RESULT_ONESTEP =
1093
ARCHIVE_STATUS =
1094
ARCHIVE_OK = true
1095
ARCHIVE_FAILED = false; exit 1
1096
RECIPE_RESULT_ARCHIVE =
1097
LINK_STATUS =
1098
LINK_OK = true
1099
LINK_FAILED = false; exit 1
1100
RECIPE_RESULT_LINK =
1101
endif
1102