forked from djoslin0/sm64ex-coop
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
1932 lines (1611 loc) · 65.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
# Makefile to rebuild SM64 split image
include util.mk
# Default target
default: all
# Preprocessor definitions
DEFINES :=
#==============================================================================#
# Build Options #
#==============================================================================#
# These options can either be set by building with 'make SETTING=value'.
# 'make clean' may be required first.
# Build debug version
DEBUG ?= 0
# Enable development/testing flags
DEVELOPMENT ?= 0
# Build for the N64 (turn this off for ports)
TARGET_N64 = 0
# Build and optimize for Raspberry Pi(s)
TARGET_RPI ?= 0
# Build and optimize for BeagleBone Black
TARGET_BBB ?= 0
# Disable linking to BASS and enable building Lua, coopnet and libjuice from source
TARGET_FOSS ?= 1
# Build for Android with SurfaceFlinger windowing backend
TARGET_ANDROID ?= 0
# Use OpenGL ES instead of OpenGL
USE_GLES ?= 0
# Build for BSD
TARGET_BSD ?= 0
# Makeflag to enable OSX fixes
OSX_BUILD ?= 0
# Enable -no-pie linker option
NO_PIE ?= 1
# Specify the target you are building for, TARGET_BITS=0 means native
TARGET_ARCH ?= native
TARGET_BITS ?= 0
# Enable immediate load by default
IMMEDIATELOAD ?= 1
# Enable better camera by default
BETTERCAMERA ?= 1
# Enable no drawing distance by default
NODRAWINGDISTANCE ?= 1
# Disable texture fixes by default (helps with them purists)
TEXTURE_FIX ?= 0
# Enable extended options menu by default
EXT_OPTIONS_MENU ?= 1
# Disable text-based save-files by default
TEXTSAVES ?= 0
# Load resources from external files
EXTERNAL_DATA ?= 0
# Enable Discord Game SDK (used for Discord invites)
DISCORD_SDK ?= 0
# Enable CoopNet SDK (used for CoopNet server hosting)
COOPNET ?= 1
# Enable docker build workarounds
DOCKERBUILD ?= 0
# Sets your optimization level for building.
# A choose is chosen by default for you.
OPT_LEVEL ?= -1
# Enable compiling with more debug info.
DEBUG_INFO_LEVEL ?= 2
# Enable profiling
PROFILE ?= 0
# Enable address sanitizer
ASAN ?= 0
# Compile headless
HEADLESS ?= 0
# Enable Game ICON
ICON ?= 1
# Use .app (mac only)
USE_APP ?= 1
# Enable touchscreen controls
TOUCH_CONTROLS ?= 0
# Various workarounds for weird toolchains
NO_BZERO_BCOPY ?= 0
NO_LDIV ?= 0
# Backend selection
# Renderers: GL, GL_LEGACY, D3D11, D3D12, DUMMY
RENDER_API ?= GL
# Window managers: SDL1, SDL2, DXGI (forced if D3D11 or D3D12 in RENDER_API), DUMMY (forced if RENDER_API is DUMMY)
WINDOW_API ?= SDL2
# Audio backends: SDL1, SDL2, DUMMY
AUDIO_API ?= SDL2
# Controller backends (can have multiple, space separated): SDL2, SDL1
CONTROLLER_API ?= SDL2
# Misc settings for EXTERNAL_DATA
BASEDIR ?= res
BASEPACK ?= base.zip
# Automatic settings for PC port(s)
WINDOWS_BUILD ?= 0
WINDOWS_AUTO_BUILDER ?= 0
# Setup extra cflags
EXTRA_CFLAGS ?=
EXTRA_CPP_FLAGS ?=
EXTRA_CFLAGS += -Wno-format-security -Wno-trigraphs
dev:; @$(MAKE) DEVELOPMENT=1
# COMPILER - selects the C compiler to use
# gcc - uses the GNU C Compiler
COMPILER = gcc
$(eval $(call validate-option,COMPILER,ido gcc clang))
# Attempt to detect OS
ifeq ($(OS),Windows_NT)
HOST_OS ?= Windows
else
HOST_OS ?= $(shell uname -s 2>/dev/null || echo Unknown)
# some weird MINGW/Cygwin env that doesn't define $OS
ifneq (,$(findstring MINGW,HOST_OS))
HOST_OS := Windows
endif
endif
ifeq ($(HOST_OS),Windows)
WINDOWS_BUILD := 1
endif
# Attempt to detect Termux Android build
ifneq ($(shell which termux-setup-storage),)
TARGET_ANDROID := 1
endif
# If parent folder is the gradle repository for Android,
# copy mods and lang files to assets for later gradle build
ifneq ($(shell ls ../../src/main/),)
DUMMY != mkdir -p ../../src/main/assets && \
cp -r mods ../../src/main/assets/ && \
cp -r lang ../../src/main/assets/
endif
# Attempt to detect BSD
ifneq ($(shell uname -s | grep BSD),)
TARGET_BSD := 1
endif
# Attempt to detect 32-bit
ifneq ($(shell uname -m | grep -e i386 -e i686 -e arm -e armhf -e armv6l -e armv7l -e armv8l -e armv8b),)
TARGET_BITS = 32
endif
# MXE overrides
ifeq ($(TARGET_ANDROID),1)
RENDER_API := GL
WINDOW_API := SDL2
AUDIO_API := SDL2
CONTROLLER_API := SDL2
TOUCH_CONTROLS := 1
TARGET_FOSS := 1
endif
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 32
NO_BZERO_BCOPY := 1
else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 64
NO_BZERO_BCOPY := 1
endif
endif
# Determine default windows target bits
ifeq ($(WINDOWS_BUILD), 1)
ifeq ($(TARGET_BITS), 0)
CPU_TYPE := $(firstword $(subst -, ,$(shell $(CC) -dumpmachine)))
ifeq ($(CPU_TYPE), x86_64)
TARGET_BITS := 64
else ifeq ($(CPU_TYPE), i686)
TARGET_BITS := 32
else ifeq ($(CPU_TYPE), mingw32)
TARGET_BITS := 32
endif
endif
endif
ifneq ($(TARGET_BITS),0)
BITS := -m$(TARGET_BITS)
endif
ifeq ($(WINDOWS_AUTO_BUILDER),1)
export SHELL=sh.exe
ifeq ($(TARGET_BITS),32)
EXTRA_INCLUDES := ../include/1 ../include/2 ../include/3 ../include/4
EXTRA_CPP_INCLUDES := -I../include/cpp
else
EXTRA_INCLUDES :=
EXTRA_CPP_INCLUDES :=
endif
EXTRA_CFLAGS += -Wno-expansion-to-defined
EXTRA_CPP_FLAGS := -Wno-class-conversion -Wno-packed-not-aligned
else
EXTRA_INCLUDES ?=
EXTRA_CPP_INCLUDES ?=
endif
ifeq ($(TARGET_BITS), 32)
DEFINES += BITS_32=1
endif
# VERSION - selects the version of the game to build
# jp - builds the 1996 Japanese version
# us - builds the 1996 North American version
# eu - builds the 1997 PAL version
# sh - builds the 1997 Japanese Shindou version, with rumble pak support
VERSION ?= us
$(eval $(call validate-option,VERSION,jp us eu sh))
# Graphics microcode used
GRUCODE ?= f3dex2e
ifeq ($(VERSION),jp)
DEFINES += VERSION_JP=1
#GRUCODE ?= f3d_old
VERSION_JP_US ?= true
else ifeq ($(VERSION),us)
DEFINES += VERSION_US=1
#GRUCODE ?= f3d_old
VERSION_JP_US ?= true
else ifeq ($(VERSION),eu)
DEFINES += VERSION_EU=1
#GRUCODE ?= f3d_new
VERSION_JP_US ?= false
else ifeq ($(VERSION),sh)
DEFINES += VERSION_SH=1
#GRUCODE ?= f3d_new
VERSION_JP_US ?= false
endif
# Determine our optimization level.
# Optimization Levels 0 through 5 optimize for speed,
# While optimization levels 6, and 7 optimize for size.
# If no optimization is specified, A default is chosen.
ifeq ($(OPT_LEVEL),0) # No optimization
OPT_FLAGS := -O0
else ifeq ($(OPT_LEVEL),1) # Debugging optimization
OPT_FLAGS := -Og
else ifeq ($(OPT_LEVEL),2) # Level 1 Optimization
OPT_FLAGS := -O1
else ifeq ($(OPT_LEVEL),3) # Level 2 Optimization
OPT_FLAGS := -O2
else ifeq ($(OPT_LEVEL),4) # Level 3 Optimization
OPT_FLAGS := -O3
else ifeq ($(OPT_LEVEL),5) # Fastest Optimization
OPT_FLAGS := -Ofast
else ifeq ($(OPT_LEVEL),6) # Size Optimization
OPT_FLAGS := -Os
else ifeq ($(OPT_LEVEL),7) # Aggresive Size Optimization
OPT_FLAGS := -Oz
else
ifeq ($(DEBUG),0)
# Can't use O2 or higher right now for auto-builders, coop-compiler produces strange graphical errors
# likely due to undefined behavior somewhere
#ifeq ($(WINDOWS_AUTO_BUILDER),1)
# OPT_FLAGS := -O1
#else
OPT_FLAGS := -O2
#endif
else
OPT_FLAGS := -O0
endif
endif
# Set our level of debug symbol info,
# Including an option to disable it.
# Level 0 produces no debug information at all. Thus, -g0 negates -g.
# Level 1 produces minimal information, enough for making backtraces in parts of the program that you don’t plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables.
# Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
# From https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
ifeq ($(DEBUG_INFO_LEVEL),3)
OPT_FLAGS += -g -g3
else ifeq ($(DEBUG_INFO_LEVEL),1)
OPT_FLAGS += -g -g1
else ifeq ($(DEBUG_INFO_LEVEL),0)
# If we're compiling with -0g. I don't believe this will do anything worthwhile.
OPT_FLAGS += -g0
else
# This is our default AND level 2.
OPT_FLAGS += -g
endif
ifeq ($(PROFILE),1)
PROF_FLAGS := -pg
else
PROF_FLAGS :=
endif
ifeq ($(TARGET_RPI),1)
$(info Compiling for Raspberry Pi)
DISCORD_SDK := 0
COOPNET := 0
machine = $(shell sh -c 'uname -m 2>/dev/null || echo unknown')
# Raspberry Pi B+, Zero, etc
ifneq (,$(findstring armv6l,$(machine)))
OPT_FLAGS := -march=armv6zk+fp -mfpu=vfp -Ofast
endif
# Raspberry Pi 2 and 3 in ARM 32bit mode
ifneq (,$(findstring armv7l,$(machine)))
$(info ARM 32bit mode)
model = $(shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown')
ifneq (,$(findstring 3,$(model)))
OPT_FLAGS := -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -O3
else
OPT_FLAGS := -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -O3
endif
endif
# RPi3 or RPi4, in ARM64 (aarch64) mode. NEEDS TESTING 32BIT.
# DO NOT pass -mfpu stuff here, thats for 32bit ARM only and will fail for 64bit ARM.
ifneq (,$(findstring aarch64,$(machine)))
$(info ARM64 mode)
model = $(shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown')
ifneq (,$(findstring 3,$(model)))
OPT_FLAGS := -march=armv8-a+crc -mtune=cortex-a53 -O3
else ifneq (,$(findstring 4,$(model)))
OPT_FLAGS := -march=armv8-a+crc+simd -mtune=cortex-a72 -O3
endif
endif
endif
# BeagleBone Black. Its architecture is not identical to any RPi
ifeq ($(TARGET_BBB),1)
OPT_FLAGS := -march=armv7-a -marm -mfpu=neon -mtune=cortex-a8 -O3
endif
# Set BITS (32/64) to compile for
OPT_FLAGS += $(BITS)
TARGET := sm64.$(VERSION)
# Stuff for showing the git hash in the intro on nightly builds
# From https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source
#ifeq ($(shell git rev-parse --abbrev-ref HEAD),nightly)
# GIT_HASH=`git rev-parse --short HEAD`
# COMPILE_TIME=`date -u +'%Y-%m-%d %H:%M:%S UTC'`
# DEFINES += -DNIGHTLY -DGIT_HASH="\"$(GIT_HASH)\"" -DCOMPILE_TIME="\"$(COMPILE_TIME)\""
#endif
# GRUCODE - selects which RSP microcode to use.
# f3d_old - default for JP and US versions
# f3d_new - default for EU and Shindou versions
# f3dex -
# f3dex2 -
# f3dex2e -
# f3dzex - newer, experimental microcode used in Animal Crossing
$(eval $(call validate-option,GRUCODE,f3d_old f3dex f3dex2 f3dex2e f3d_new f3dzex))
ifeq ($(GRUCODE),f3d_old)
DEFINES += F3D_OLD=1
else ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H
DEFINES += F3D_NEW=1
else ifeq ($(GRUCODE),f3dex) # Fast3DEX
DEFINES += F3DEX_GBI=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE), f3dex2) # Fast3DEX2
DEFINES += F3DEX_GBI_2=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE), f3dex2e) # Fast3DEX2 Extended (PC default)
DEFINES += F3DEX_GBI_2E=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori)
$(warning Fast3DZEX is experimental. Try at your own risk.)
DEFINES += F3DZEX_GBI_2=1 F3DEX_GBI_2=1 F3DEX_GBI_SHARED=1
endif
# Check for certain target types.
ifeq ($(TARGET_RPI),1) # Define RPi to change SDL2 title & GLES2 hints
DEFINES += USE_GLES=1
else ifeq ($(TARGET_ANDROID),1)
DEFINES += TARGET_ANDROID=1 USE_GLES=1 _LANGUAGE_C=1
else ifeq ($(TARGET_BBB),1)
DEFINES += USE_GLES=1
else ifeq ($(USE_GLES),1)
DEFINES += USE_GLES=1
endif
ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
DEFINES += OSX_BUILD=1
endif
# Check backends
ifneq (,$(filter $(RENDER_API),D3D11 D3D12))
ifneq ($(WINDOWS_BUILD),1)
$(error DirectX is only supported on Windows)
endif
ifneq ($(WINDOW_API),DXGI)
$(warning DirectX renderers require DXGI, forcing WINDOW_API value)
WINDOW_API := DXGI
endif
else
ifeq ($(WINDOW_API),DXGI)
$(error DXGI can only be used with DirectX renderers)
endif
ifneq ($(WINDOW_API),DUMMY)
ifeq ($(RENDER_API),DUMMY)
$(warning Dummy renderer requires dummy window API, forcing WINDOW_API value)
WINDOW_API := DUMMY
endif
else
ifneq ($(RENDER_API),DUMMY)
$(warning Dummy window API requires dummy renderer, forcing RENDER_API value)
RENDER_API := DUMMY
endif
endif
endif
ifeq ($(HEADLESS),1)
$(info Compiling headless)
RENDER_API := DUMMY
WINDOW_API := DUMMY
AUDIO_API := DUMMY
CONTROLLER_API :=
endif
# NON_MATCHING - whether to build a matching, identical copy of the ROM
# 1 - enable some alternate, more portable code that does not produce a matching ROM
# 0 - build a matching ROM
NON_MATCHING ?= 0
$(eval $(call validate-option,NON_MATCHING,0 1))
ifeq ($(TARGET_N64),0)
NON_MATCHING := 1
endif
ifeq ($(NON_MATCHING),1)
DEFINES += NON_MATCHING=1 AVOID_UB=1
COMPARE := 0
endif
# COMPARE - whether to verify the SHA-1 hash of the ROM after building
# 1 - verifies the SHA-1 hash of the selected version of the game
# 0 - does not verify the hash
COMPARE ?= 1
$(eval $(call validate-option,COMPARE,0 1))
ifeq ($(OSX_BUILD),0)
USE_APP := 0
else ifeq ($(shell uname -m),arm64)
DISCORD_SDK := 0
endif
TARGET_STRING := sm64.$(VERSION).$(GRUCODE)
# If non-default settings were chosen, disable COMPARE
ifeq ($(filter $(TARGET_STRING), sm64.jp.f3d_old sm64.us.f3d_old sm64.eu.f3d_new sm64.sh.f3d_new),)
COMPARE := 0
endif
# Whether to hide commands or not
VERBOSE ?= 0
ifeq ($(VERBOSE),0)
V := @
endif
# Whether to colorize build messages
COLOR ?= 1
# display selected options unless 'make clean' or 'make distclean' is run
ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
$(info ==== Build Options ====)
$(info Version: $(VERSION))
$(info Microcode: $(GRUCODE))
$(info Target: $(TARGET))
ifeq ($(COMPARE),1)
$(info Compare ROM: yes)
else
$(info Compare ROM: no)
endif
ifeq ($(NON_MATCHING),1)
$(info Build Matching: no)
else
$(info Build Matching: yes)
endif
$(info =======================)
endif
#==============================================================================#
# Universal Dependencies #
#==============================================================================#
TOOLS_DIR := tools
LIBLUA_DIR := lib/src/lua
ifeq ($(TARGET_BSD),1)
LUA_PLATFORM := bsd
else
LUA_PLATFORM := linux
endif
ZLIB_DIR := lib/src/zlib
COOPNET_DIR := lib/src/coopnet
# (This is a bit hacky, but a lot of rules implicitly depend
# on tools and assets, and we use directory globs further down
# in the makefile that we want should cover assets.)
PYTHON := python3
ifeq ($(filter clean distclean print-%,$(MAKECMDGOALS)),)
# Make sure assets exist
NOEXTRACT ?= 0
ifeq ($(NOEXTRACT),0)
DUMMY != $(PYTHON) extract_assets.py $(VERSION) >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to extract assets)
endif
endif
ifeq ($(WINDOWS_AUTO_BUILDER),0)
$(info Building tools...)
DUMMY != $(MAKE) -C $(TOOLS_DIR) >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build tools)
endif
endif
# Make liblua
ifeq ($(TARGET_FOSS),1)
DUMMY != $(MAKE) -C $(LIBLUA_DIR) $(LUA_PLATFORM) >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build lua)
endif
endif
# Make zlib
ifeq ($(TARGET_ANDROID),1)
DUMMY != $(MAKE) -C $(ZLIB_DIR) libz.a >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build zlib)
endif
endif
# Make coopnet
ifeq ($(TARGET_FOSS),1)
DUMMY != $(MAKE) -C $(COOPNET_DIR) >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build coopnet)
endif
endif
$(info Building Game...)
endif
#==============================================================================#
# Extra Source Files #
#==============================================================================#
# Luigi and wario sounds don't work on 32-bit right now
# And the audio code is so terrible I don't care enough to figure it out at the moment
ifeq ($(TARGET_BITS), 32)
ifeq ($(TARGET_FOSS),0)
_ := $(shell rm -rf sound/samples/sfx_custom_luigi/*.aiff)
_ := $(shell rm -rf sound/samples/sfx_custom_luigi_peach/*.aiff)
_ := $(shell rm -rf sound/samples/sfx_custom_wario/*.aiff)
_ := $(shell rm -rf sound/samples/sfx_custom_wario_peach/*.aiff)
# Copy missing character sounds from mario sound banks
_ := $(shell $(PYTHON) $(TOOLS_DIR)/copy_mario_sounds.py)
endif
endif
# Copy missing instrument samples from the music sound banks
_ := $(shell $(PYTHON) $(TOOLS_DIR)/copy_extended_sounds.py)
#==============================================================================#
# Target Executable and Sources #
#==============================================================================#
BUILD_DIR_BASE := build
# BUILD_DIR is the location where all build artifacts are placed
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
ifeq ($(WINDOWS_BUILD),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).exe
else ifeq ($(TARGET_ANDROID),1)
EXE := $(BUILD_DIR)/libmain.so
ZIP_UNCOMPRESSED := $(BUILD_DIR)/$(TARGET).uncompressed.zip
APK_ALIGNED := $(BUILD_DIR)/$(TARGET).aligned.apk
APK_SIGNED := $(BUILD_DIR)/$(TARGET).apk
else # Linux builds/binary namer
ifeq ($(TARGET_RPI),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).arm
else
EXE := $(BUILD_DIR)/$(TARGET_STRING)
endif
endif
ELF := $(BUILD_DIR)/$(TARGET).elf
LIBULTRA := $(BUILD_DIR)/libultra.a
LD_SCRIPT := sm64.ld
MIO0_DIR := $(BUILD_DIR)/bin
SOUND_BIN_DIR := $(BUILD_DIR)/sound
TEXTURE_DIR := textures
ACTOR_DIR := actors
LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
# Directories containing source files
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets asm lib sound
BIN_DIRS := bin bin/$(VERSION)
# PC files
SRC_DIRS += src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes src/pc/mods src/dev src/pc/network src/pc/network/packets src/pc/network/socket src/pc/network/coopnet src/pc/utils src/pc/utils/miniz src/pc/djui src/pc/lua src/pc/lua/utils src/pc/os
ifeq ($(TARGET_ANDROID),1)
SRC_DIRS += platform/android
endif
ifeq ($(DISCORD_SDK),1)
SRC_DIRS += src/pc/discord
endif
ULTRA_SRC_DIRS := lib/src lib/src/math lib/asm lib/data
ULTRA_BIN_DIRS := lib/bin
GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists
# File dependencies and variables for specific files
include Makefile.split
# Dynos
include dynos.mk
# Source code files
LEVEL_C_FILES := $(wildcard levels/*/leveldata.c) $(wildcard levels/*/script.c) $(wildcard levels/*/geo.c)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(LEVEL_C_FILES)
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
ULTRA_C_FILES := $(foreach dir,$(ULTRA_SRC_DIRS),$(wildcard $(dir)/*.c))
GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
ULTRA_S_FILES := $(foreach dir,$(ULTRA_SRC_DIRS),$(wildcard $(dir)/*.s))
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c
ifeq ($(TARGET_N64),0)
GENERATED_C_FILES += $(addprefix $(BUILD_DIR)/bin/,$(addsuffix _skybox.c,$(notdir $(basename $(wildcard textures/skyboxes/*.png)))))
endif
# "If we're N64, use the above"
ifeq ($(TARGET_N64),0)
ULTRA_C_FILES := \
alBnkfNew.c \
guLookAtRef.c \
guMtxF2L.c \
guNormalize.c \
guOrthoF.c \
guPerspectiveF.c \
guRotateF.c \
guScaleF.c \
guTranslateF.c \
ldiv.c
C_FILES := $(filter-out src/game/main.c,$(C_FILES))
ULTRA_C_FILES := $(addprefix lib/src/,$(ULTRA_C_FILES))
endif
# Sound files
SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
SOUND_SAMPLE_DIRS := $(wildcard sound/samples/*)
SOUND_SAMPLE_AIFFS := $(foreach dir,$(SOUND_SAMPLE_DIRS),$(wildcard $(dir)/*.aiff))
SOUND_SAMPLE_TABLES := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.table))
SOUND_SAMPLE_AIFCS := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.aifc))
SOUND_SEQUENCE_DIRS := sound/sequences sound/sequences/$(VERSION)
# all .m64 files in SOUND_SEQUENCE_DIRS, plus all .m64 files that are generated from .s files in SOUND_SEQUENCE_DIRS
SOUND_SEQUENCE_FILES := \
$(foreach dir,$(SOUND_SEQUENCE_DIRS),\
$(wildcard $(dir)/*.m64) \
$(foreach file,$(wildcard $(dir)/*.s),$(BUILD_DIR)/$(file:.s=.m64)) \
)
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(CPP_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(GENERATED_C_FILES),$(file:.c=.o))
ULTRA_O_FILES := $(foreach file,$(ULTRA_S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(ULTRA_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
RPC_LIBS :=
DISCORD_SDK_LIBS :=
ifeq ($(DISCORD_SDK), 1)
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(TARGET_BITS), 32)
DISCORD_SDK_LIBS := lib/discordsdk/x86/discord_game_sdk.dll
else
DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dll
endif
else ifeq ($(OSX_BUILD),1)
# needs testing
# HACKY! Instead of figuring out all of the dynamic library linking madness...
# I copied the library and gave it two names.
# This really shouldn't be required, but I got tired of trying to do it the "right way"
DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dylib lib/discordsdk/libdiscord_game_sdk.dylib
else
DISCORD_SDK_LIBS := lib/discordsdk/libdiscord_game_sdk.so
endif
endif
LANG_DIR := lang
# Remove old lang dir
_ := $(shell rm -rf ./$(BUILD_DIR)/$(LANG_DIR))
MOD_DIR := mods
# Remove old mod dir
_ := $(shell rm -rf ./$(BUILD_DIR)/$(MOD_DIR))
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d
# Segment elf files
SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)
# Files with GLOBAL_ASM blocks
ifeq ($(NON_MATCHING),0)
ifeq ($(VERSION),sh)
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/**/*.c) $(wildcard lib/src/*.c)
else
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/**/*.c)
endif
GLOBAL_ASM_O_FILES = $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
GLOBAL_ASM_DEP = $(BUILD_DIR)/src/audio/non_matching_dep
endif
#==============================================================================#
# Compiler Options #
#==============================================================================#
AS := $(CROSS)as
ifeq ($(OSX_BUILD),1)
AS := i686-w64-mingw32-as
endif
ifeq ($(WINDOWS_AUTO_BUILDER),1)
CC := cc
CXX := g++
else ifeq ($(COMPILER),gcc)
CC := $(CROSS)gcc
CXX := $(CROSS)g++
ifeq ($(OSX_BUILD),0)
EXTRA_CFLAGS += -Wno-unused-result -Wno-format-truncation
else
EXTRA_CFLAGS += -Wno-unused-result
endif
else ifeq ($(COMPILER),clang)
CC := clang
CXX := clang++
CPP := clang++
EXTRA_CFLAGS += -Wno-unused-function -Wno-unused-variable -Wno-unknown-warning-option -Wno-self-assign -Wno-unknown-pragmas -Wno-unused-result
else
ifeq ($(USE_QEMU_IRIX),1)
IRIX_ROOT := $(TOOLS_DIR)/ido5.3_compiler
CC := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
ACPP := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/acpp
COPT := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/copt
else
IDO_ROOT := $(TOOLS_DIR)/ido5.3_recomp
CC := $(IDO_ROOT)/cc
ACPP := $(IDO_ROOT)/acpp
COPT := $(IDO_ROOT)/copt
endif
endif
ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
CPP := cpp
OBJCOPY := objcopy
OBJDUMP := $(CROSS)objdump
else ifeq ($(OSX_BUILD),1)
CPP := cpp-9
OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy
else ifeq ($(TARGET_N64),0) # Linux & other builds
CPP := $(CROSS)cpp
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
else
# Prefer gcc's cpp if installed on the system
ifneq (,$(call find-command,cpp-10))
CPP := cpp-10
else
CPP := cpp
endif
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
endif
# thank you apple very cool
ifeq ($(HOST_OS),Darwin)
CP := gcp
else
CP := cp
endif
ifeq ($(DISCORD_SDK),1)
LD := $(CXX)
else ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL
LD := $(CC)
else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
LD := $(CC)
else
LD := $(CXX)
endif
else
LD := $(CXX)
endif
AR := $(CROSS)ar
ifeq ($(TARGET_N64),1)
TARGET_CFLAGS := -nostdinc -DTARGET_N64 -D_LANGUAGE_C
CC_CFLAGS := -fno-builtin
else
TARGET_CFLAGS := -D_LANGUAGE_C
TARGET_CFLAGS += $(EXTRA_CFLAGS)
endif
INCLUDE_DIRS := include $(BUILD_DIR) $(BUILD_DIR)/include src .
ifeq ($(TARGET_N64),1)
INCLUDE_DIRS += include/libc
else
INCLUDE_DIRS += sound lib/lua/include lib/coopnet/include $(EXTRA_INCLUDES)
endif
ifeq ($(TARGET_ANDROID),1)
INCLUDE_DIRS += platform/android/include
endif
# Configure backend flags
SDLCONFIG := $(CROSS)sdl2-config
BACKEND_CFLAGS := -DRAPI_$(RENDER_API)=1 -DWAPI_$(WINDOW_API)=1 -DAAPI_$(AUDIO_API)=1
# can have multiple controller APIs
BACKEND_CFLAGS += $(foreach capi,$(CONTROLLER_API),-DCAPI_$(capi)=1)
BACKEND_LDFLAGS :=
SDL1_USED := 0
SDL2_USED := 0
# for now, it's either SDL+GL or DXGI+DirectX, so choose based on WAPI
ifeq ($(WINDOW_API),DXGI)
DXBITS := `cat $(ENDIAN_BITWIDTH) | tr ' ' '\n' | tail -1`
ifeq ($(RENDER_API),D3D12)
BACKEND_CFLAGS += -Iinclude/dxsdk
endif
BACKEND_LDFLAGS += -ld3dcompiler -ldxgi -ldxguid
BACKEND_LDFLAGS += -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -static
else ifeq ($(findstring SDL,$(WINDOW_API)),SDL)
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += -lglew32 -lglu32 -lopengl32
else ifeq ($(TARGET_ANDROID),1)
BACKEND_LDFLAGS += -lGLESv2 -llog
else ifeq ($(TARGET_RPI),1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(TARGET_BBB),1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(USE_GLES),1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(OSX_BUILD),1)
BACKEND_LDFLAGS += -framework OpenGL `pkg-config --libs glew` -ld_classic
EXTRA_CPP_FLAGS += -stdlib=libc++ -std=c++0x
else ifeq ($(TARGET_BSD),1)
BACKEND_CFLAGS += $(shell pkg-config gl --cflags)
BACKEND_LDFLAGS += $(shell pkg-config gl --libs)
else
BACKEND_LDFLAGS += -lGL
endif
endif
ifneq (,$(findstring SDL2,$(AUDIO_API)$(WINDOW_API)$(CONTROLLER_API)))
SDL2_USED := 1
endif
ifneq (,$(findstring SDL1,$(AUDIO_API)$(WINDOW_API)$(CONTROLLER_API)))
SDL1_USED := 1
endif
ifeq ($(SDL1_USED)$(SDL2_USED),11)
$(error Cannot link both SDL1 and SDL2 at the same time)
endif
# SDL can be used by different systems, so we consolidate all of that shit into this
ifeq ($(SDL2_USED),1)
SDLCONFIG := $(CROSS)sdl2-config
BACKEND_CFLAGS += -DHAVE_SDL2=1
else ifeq ($(SDL1_USED),1)
SDLCONFIG := $(CROSS)sdl-config
BACKEND_CFLAGS += -DHAVE_SDL1=1
endif
ifneq ($(SDL1_USED)$(SDL2_USED),00)
ifeq ($(TARGET_ANDROID),1)
BACKEND_LDFLAGS += -lSDL2
else ifeq ($(OSX_BUILD),1)
# on OSX at least the homebrew version of sdl-config gives include path as `.../include/SDL2` instead of `.../include`
OSX_PREFIX := $(shell $(SDLCONFIG) --prefix)
BACKEND_CFLAGS += -I$(OSX_PREFIX)/include $(shell $(SDLCONFIG) --cflags)
else ifeq ($(TARGET_BSD),1)
BACKEND_CFLAGS += $(shell pkg-config sdl2 --cflags)
BACKEND_LDFLAGS += $(shell pkg-config sdl2 --libs)
else
BACKEND_CFLAGS += $(shell $(SDLCONFIG) --cflags)
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --static-libs) -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
else
BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --libs)
endif
endif
endif
C_DEFINES := $(foreach d,$(DEFINES),-D$(d))
DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES)
# Check code syntax with host compiler
CC_CHECK := $(CC)
ifeq ($(WINDOWS_BUILD),1)
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra $(TARGET_CFLAGS) -DWINSOCK
CFLAGS := $(OPT_FLAGS) $(DEF_INC_CFLAGS) $(BACKEND_CFLAGS) $(TARGET_CFLAGS) -fno-strict-aliasing -fwrapv -DWINSOCK
ifeq ($(TARGET_BITS), 32)
BACKEND_LDFLAGS += -ldbghelp
endif
else ifeq ($(TARGET_N64),0) # Linux / Other builds below
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra $(TARGET_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(DEF_INC_CFLAGS) $(BACKEND_CFLAGS) $(TARGET_CFLAGS) -fno-strict-aliasing -fwrapv
else # C compiler options for N64
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-main -DNON_MATCHING -DAVOID_UB $(DEF_INC_CFLAGS)
CFLAGS = -G 0 $(OPT_FLAGS) $(TARGET_CFLAGS) $(MIPSISET) $(DEF_INC_CFLAGS)
ifeq ($(COMPILER),gcc)
CFLAGS += -mno-shared -march=vr4300 -mfix4300 -mabi=32 -mhard-float -mdivide-breaks -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-PIC -mno-abicalls -fno-strict-aliasing -fno-inline-functions -ffreestanding -fwrapv -Wall -Wextra
else
CFLAGS += -non_shared -Wab,-r4300_mul -Xcpluscomm -Xfullwarn -signed -32
endif
endif
ifeq ($(TARGET_N64),1)
ASFLAGS := -march=vr4300 -mabi=32 $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(foreach d,$(DEFINES),--defsym $(d))
RSPASMFLAGS := $(foreach d,$(DEFINES),-definelabel $(subst =, ,$(d)))
else
ASFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(foreach d,$(DEFINES),--defsym $(d))
RSPASMFLAGS :=
endif
# C preprocessor flags
CPPFLAGS := -P -Wno-trigraphs $(DEF_INC_CFLAGS)
ifeq ($(TARGET_ANDROID),1)
ifneq ($(shell which termux-setup-storage),) # Termux has clang
CPPFLAGS := -E -P -x c -Wno-trigraphs $(DEF_INC_CFLAGS)