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