Subversion Repositories eduke32

Rev

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