forked from AloUltraExt/sm64ex-alo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
1646 lines (1319 loc) · 51.7 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
### Default target ###
default: all
### Build Options ###
# These options can either be changed by modifying the makefile, or
# by building with 'make SETTING=value'. 'make clean' may be required.
# Makefile Refactor from Refresh 13 isn't included because how much
# changes are in this Makefile in sm64ex, especially in this repo
# However, the build clean output is there in it's own way
# Build debug version
DEBUG ?= 0
# Version of the game to build
VERSION ?= us
# Graphics microcode used
GRUCODE ?= f3dzex
# If COMPARE is 1, check the output sha1sum when building 'all'
COMPARE ?= 0
# If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended)
NON_MATCHING ?= 1
# Compiler to use in N64 (ido or gcc)
COMPILER_N64 ?= gcc
# Build for original N64 (no pc code)
TARGET_N64 = 0
# Build and optimize for Raspberry Pi(s)
TARGET_RPI ?= 0
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
# Build for the Wii U
TARGET_WII_U ?= 0
# Build for the 3DS
TARGET_N3DS ?= 0
# Build for Nintendo Switch
TARGET_SWITCH ?= 0
# Makeflag to enable OSX fixes
OSX_BUILD ?= 0
# Specify the target you are building for, TARGET_BITS=0 means native
TARGET_ARCH ?= native
TARGET_BITS ?= 0
# Enable extended options menu by default
EXT_OPTIONS_MENU ?= 1
# Enable better camera (Puppycam)
BETTERCAMERA ?= 1
# Enable cheats
CHEATS_ACTIONS ?= 1
# Disable no drawing distance by default
NODRAWINGDISTANCE ?= 0
# Disable text-based save-files by default
TEXTSAVES ?= 0
# Load resources from external files
EXTERNAL_DATA ?= 0
# Enable Discord Rich Presence
DISCORDRPC ?= 0
# Enable rumble functions (Originally in Shindou)
RUMBLE_FEEDBACK ?= 0
# Enable Goddard (Mario Face)
GODDARD_MFACE ?= 1
# Enable PC Port defines
PC_PORT_DEFINES ?= 0
# Quality of life features
QOL_FEATURES ?= 1
# Quality of life fixes
QOL_FIXES ?= 1
# Various workarounds for weird toolchains
NO_BZERO_BCOPY ?= 0
NO_LDIV ?= 0
# Check if is compiling on a console (N64 doesn't count)
TARGET_PORT_CONSOLE ?= 0
# Backend selection
# Renderers: GL, GL_LEGACY, D3D11, D3D12, WHB (forced if the target is Wii U), C3D (forced if the target is 3DS)
RENDER_API ?= GL
# Window managers: SDL1, SDL2, DXGI (forced if D3D11 or D3D12 in RENDER_API), WHB (forced if the target is Wii U), 3DS (forced if the target is 3DS)
WINDOW_API ?= SDL2
# Audio backends: SDL1, SDL2 (forced if the target is Wii U), 3DS (forced if the target is 3DS)
AUDIO_API ?= SDL2
# Controller backends (can have multiple, space separated): SDL1, SDL2
# WII_U (forced if the target is Wii U), 3DS (forced if the target is 3DS), SWITCH (forced if the target is SWITCH)
CONTROLLER_API ?= SDL2
ifeq ($(TARGET_WII_U),1)
RENDER_API := WHB
WINDOW_API := WHB
AUDIO_API := SDL2
CONTROLLER_API := WII_U
TARGET_PORT_CONSOLE := 1
endif
ifeq ($(TARGET_N3DS),1)
RENDER_API := C3D
WINDOW_API := 3DS
AUDIO_API := 3DS
CONTROLLER_API := 3DS
TARGET_PORT_CONSOLE := 1
endif
ifeq ($(TARGET_SWITCH),1)
RENDER_API := GL
WINDOW_API := SDL2
AUDIO_API := SDL2
CONTROLLER_API := SWITCH
TARGET_PORT_CONSOLE := 1
endif
# Misc settings for EXTERNAL_DATA
ifeq ($(TARGET_PORT_CONSOLE),1)
BASEDIR ?= sm64ex_res
else
BASEDIR ?= res
endif
BASEPACK ?= base.zip
# Automatic settings for PC port(s)
WINDOWS_BUILD ?= 0
ifeq ($(TARGET_N64),0)
GRUCODE := f3dex2e
RUMBLE_FEEDBACK := 1
PC_PORT_DEFINES := 1
else
GRUCODE := $(GRUCODE)
NO_LDIV := 1
endif
# 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 ($(TARGET_WEB),0)
ifeq ($(TARGET_PORT_CONSOLE),0)
ifeq ($(HOST_OS),Windows)
WINDOWS_BUILD := 1
endif
endif
endif
# MXE overrides
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
ifneq ($(TARGET_BITS),0)
BITS := -m$(TARGET_BITS)
endif
# Set up WUT for Wii U
ifeq ($(TARGET_WII_U),1)
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>/devkitPro/devkitPPC")
endif
include $(DEVKITPPC)/base_tools
PORTLIBS := $(PORTLIBS_PATH)/wiiu $(PORTLIBS_PATH)/ppc
export PATH := $(PORTLIBS_PATH)/wiiu/bin:$(PORTLIBS_PATH)/ppc/bin:$(PATH)
WUT_ROOT ?= $(DEVKITPRO)/wut
RPXSPECS := -specs=$(WUT_ROOT)/share/wut.specs
MACHDEP = -DESPRESSO -mcpu=750 -meabi -mhard-float
LIBDIRS := $(PORTLIBS) $(WUT_ROOT)
INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include)
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
endif
# Release (version) flag defs
ifeq ($(VERSION),jp)
VERSION_DEF := VERSION_JP
else ifeq ($(VERSION),us)
VERSION_DEF := VERSION_US
else ifeq ($(VERSION),eu)
VERSION_DEF := VERSION_EU
else ifeq ($(VERSION),sh)
VERSION_DEF := VERSION_SH
RUMBLE_FEEDBACK := 1
# Audio changed so much in SH that just fails building
ifeq ($(TARGET_N64),0)
$(error Shindou currently doesn't work on PC Port, wait for a dev until it's fixed.)
else
$(warning Shindou compiles but just hangs in a black screen. Try at your own risk.)
endif
else
$(error unknown version "$(VERSION)")
endif
TARGET := sm64.$(VERSION)
VERSION_CFLAGS := -D$(VERSION_DEF) -D_LANGUAGE_C
VERSION_ASFLAGS := --defsym $(VERSION_DEF)=1
# Microcode
ifeq ($(GRUCODE),f3dex) # Fast3DEX
GRUCODE_DEF := F3DEX_GBI
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
TARGET := $(TARGET).f3dex
COMPARE := 0
else ifeq ($(GRUCODE),f3dex2) # Fast3DEX2
GRUCODE_DEF := F3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
TARGET := $(TARGET).f3dex2
COMPARE := 0
else ifeq ($(GRUCODE),f3dex2e) # Fast3DEX2 Extended (PC default)
GRUCODE_DEF := F3DEX_GBI_2E
TARGET := $(TARGET).f3dex2e
COMPARE := 0
else ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H (Shindou)
GRUCODE_DEF := F3D_NEW
TARGET := $(TARGET).f3d_new
COMPARE := 0
else ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori)
GRUCODE_DEF := F3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
TARGET := $(TARGET).f3dzex
COMPARE := 0
endif
GRUCODE_CFLAGS := -D$(GRUCODE_DEF)
GRUCODE_ASFLAGS := $(GRUCODE_ASFLAGS) --defsym $(GRUCODE_DEF)=1
# Default build is for PC now
VERSION_CFLAGS := $(VERSION_CFLAGS) -DNON_MATCHING -DAVOID_UB
ifeq ($(TARGET_RPI),1) # Define RPi to change SDL2 title & GLES2 hints
VERSION_CFLAGS += -DUSE_GLES
else ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
VERSION_CFLAGS += -DOSX_BUILD
else ifeq ($(TARGET_WEB),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB -DUSE_GLES
else ifeq ($(TARGET_WII_U),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WII_U
else ifeq ($(TARGET_N3DS),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_N3DS
else ifeq ($(TARGET_SWITCH),1)
VERSION_CFLAGS += $(VERSION_CFLAGS) -DUSE_GLES -DTARGET_SWITCH
endif
VERSION_ASFLAGS := $(VERSION_ASFLAGS) --defsym AVOID_UB=1
COMPARE := 0
# 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
endif
################### Universal Dependencies ###################
# (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
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
# 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
# Make tools if out of date
DUMMY != make -C tools >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build tools)
endif
endif
endif
################ Target Executable and Sources ###############
# BUILD_DIR is location where all build artifacts are placed
BUILD_DIR_BASE := build
ifeq ($(TARGET_WEB),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_web
else ifeq ($(TARGET_N64),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)
else ifeq ($(TARGET_WII_U),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_wiiu
else ifeq ($(TARGET_N3DS),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_3ds
else ifeq ($(TARGET_SWITCH),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_nx
else
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
endif
LIBULTRA := $(BUILD_DIR)/libultra.a
ifeq ($(TARGET_N64),0)
ifeq ($(TARGET_WEB),1)
EXE := $(BUILD_DIR)/$(TARGET).html
else ifeq ($(TARGET_WII_U),1)
EXE := $(BUILD_DIR)/$(TARGET).rpx
else ifeq ($(TARGET_N3DS),1)
EXE := $(BUILD_DIR)/$(TARGET).3dsx
ELF := $(BUILD_DIR)/$(TARGET).elf
CIA := $(BUILD_DIR)/$(TARGET).cia
else ifeq ($(WINDOWS_BUILD),1)
EXE := $(BUILD_DIR)/$(TARGET).exe
else # Linux builds/binary namer
ifeq ($(TARGET_RPI),1)
EXE := $(BUILD_DIR)/$(TARGET).arm
else
EXE := $(BUILD_DIR)/$(TARGET)
endif
endif
endif
ifeq ($(TARGET_N64),1)
EXE := $(BUILD_DIR)/$(TARGET)
endif
ROM := $(BUILD_DIR)/$(TARGET).z64
ELF := $(BUILD_DIR)/$(TARGET).elf
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
# Hi, I'm a PC
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers src/extras actors levels bin bin/$(VERSION) data assets
ASM_DIRS := lib
ifeq ($(TARGET_N64),1)
ASM_DIRS := asm $(ASM_DIRS)
else
SRC_DIRS := $(SRC_DIRS) src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
ASM_DIRS :=
ifeq ($(WINDOWS_BUILD),1)
RES_DIRS := res_win
endif
endif
ifeq ($(TARGET_WII_U),1)
SRC_DIRS += src/pc/gfx/shaders_wiiu
else ifeq ($(DISCORDRPC),1)
SRC_DIRS += src/pc/discord
endif
BIN_DIRS := bin bin/$(VERSION)
ULTRA_SRC_DIRS := lib/src lib/src/math
ULTRA_ASM_DIRS := lib/asm lib/data
ULTRA_BIN_DIRS := lib/bin
ifeq ($(GODDARD_MFACE),1)
GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists
endif
MIPSISET := -mips2
MIPSBIT := -32
ifeq ($(TARGET_N64),1)
ifeq ($(COMPILER_N64),gcc)
MIPSISET := -mips3
OPT_FLAGS := -O2
endif
endif
# to get 32 bit working, use debug
ifeq ($(DEBUG),1)
OPT_FLAGS := -g
else
# At some point -O2 broke on PC, only -O1 and -g works
ifeq ($(TARGET_PORT_CONSOLE),1)
OPT_FLAGS := -O2
else
OPT_FLAGS := -O1
endif
endif
# Set BITS (32/64) to compile for
OPT_FLAGS += $(BITS)
ifeq ($(TARGET_WEB),1)
OPT_FLAGS := -O2 -g4 --source-map-base http://localhost:8080/
endif
ifeq ($(TARGET_RPI),1)
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)))
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)))
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
# 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
# TODO: Add Info for other targets
ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
$(info ==== Build Options ====)
$(info Version: $(VERSION))
$(info Microcode: $(GRUCODE))
$(info Target: $(TARGET))
$(info =======================)
endif
ifeq ($(COLOR),1)
NO_COL := \033[0m
RED := \033[0;31m
GREEN := \033[0;32m
BLUE := \033[0;34m
YELLOW := \033[0;33m
BLINK := \033[33;5m
endif
# File dependencies and variables for specific files
include Makefile.split
# 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)
ifeq ($(TARGET_N64),1)
ULTRA_C_FILES := $(foreach dir,$(ULTRA_SRC_DIRS),$(wildcard $(dir)/*.c))
endif
CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
ifeq ($(GODDARD_MFACE),1)
GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
endif
ifeq ($(WINDOWS_BUILD),1)
RC_FILES := $(foreach dir,$(RES_DIRS),$(wildcard $(dir)/*.rc))
endif
ifeq ($(TARGET_N64),1)
ULTRA_S_FILES := $(foreach dir,$(ULTRA_ASM_DIRS),$(wildcard $(dir)/*.s))
endif
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c \
$(addprefix $(BUILD_DIR)/bin/,$(addsuffix _skybox.c,$(notdir $(basename $(wildcard textures/skyboxes/*.png)))))
ifneq ($(TARGET_N64),1)
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
# "If we're not N64, use the above"
SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
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)) \
)
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_OBJ_FILES := $(SOUND_BIN_DIR)/sound_data.o
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(CXX_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(GENERATED_C_FILES),$(file:.c=.o))
ifeq ($(WINDOWS_BUILD),1)
O_FILES += $(foreach file,$(RC_FILES),$(BUILD_DIR)/$(file:.rc=.o))
endif
ULTRA_O_FILES := $(foreach file,$(ULTRA_S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(ULTRA_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
ifeq ($(GODDARD_MFACE),1)
GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
endif
RPC_LIBS :=
ifeq ($(TARGET_PORT_CONSOLE),0)
ifeq ($(DISCORDRPC),1)
ifeq ($(WINDOWS_BUILD),1)
RPC_LIBS := lib/discord/libdiscord-rpc.dll
else ifeq ($(OSX_BUILD),1)
# needs testing
RPC_LIBS := lib/discord/libdiscord-rpc.dylib
else
RPC_LIBS := lib/discord/libdiscord-rpc.so
endif
endif
endif
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d
# Files with GLOBAL_ASM blocks
ifeq ($(NON_MATCHING),0)
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/**/*.c)
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
###################### Custom Defines ########################
CUSTOM_C_DEFINES :=
ifeq ($(TARGET_N64),0)
# Check for PC Port Defines
ifeq ($(PC_PORT_DEFINES),1)
CUSTOM_C_DEFINES += -DNO_SEGMENTED_MEMORY -DWIDESCREEN -DUSE_SYSTEM_MALLOC
endif
# Use Console exclusive defines
ifeq ($(TARGET_PORT_CONSOLE),1)
CUSTOM_C_DEFINES += -DTARGET_PORT_CONSOLE
endif
# Use PC-only exclusive defines
ifeq ($(TARGET_PORT_CONSOLE),0)
# Check for Discord Rich Presence option
ifeq ($(DISCORDRPC),1)
CUSTOM_C_DEFINES += -DDISCORDRPC
endif
# Check for PC text save format
ifeq ($(TEXTSAVES),1)
CUSTOM_C_DEFINES += -DTEXTSAVES
endif
# Check for Mouse Puppycam Option
ifeq ($(BETTERCAMERA),1)
CUSTOM_C_DEFINES += -DBETTERCAM_MOUSE
endif
endif
endif
# Check for Puppycam option
ifeq ($(BETTERCAMERA),1)
CUSTOM_C_DEFINES += -DBETTERCAMERA
EXT_OPTIONS_MENU := 1
endif
# Check for Cheats option
ifeq ($(CHEATS_ACTIONS),1)
CUSTOM_C_DEFINES += -DCHEATS_ACTIONS
EXT_OPTIONS_MENU := 1
endif
# Check for extended options menu option
ifeq ($(EXT_OPTIONS_MENU),1)
CUSTOM_C_DEFINES += -DEXT_OPTIONS_MENU
endif
# Check for Rumble option
ifeq ($(RUMBLE_FEEDBACK),1)
CUSTOM_C_DEFINES += -DRUMBLE_FEEDBACK
endif
# Check for no drawing distance option
ifeq ($(NODRAWINGDISTANCE),1)
CUSTOM_C_DEFINES += -DNODRAWINGDISTANCE
endif
# Check for Goddard option
ifeq ($(GODDARD_MFACE),1)
CUSTOM_C_DEFINES += -DGODDARD_MFACE
endif
# Check for QoL fixes option
ifeq ($(QOL_FIXES),1)
CUSTOM_C_DEFINES += -DQOL_FIXES
endif
# Check for QoL features option
ifeq ($(QOL_FEATURES),1)
CUSTOM_C_DEFINES += -DQOL_FEATURES
endif
# Check for no bzero/bcopy workaround option
ifeq ($(NO_BZERO_BCOPY),1)
CUSTOM_C_DEFINES += -DNO_BZERO_BCOPY
endif
# Use internal ldiv()/lldiv()
ifeq ($(NO_LDIV),1)
CUSTOM_C_DEFINES += -DNO_LDIV
endif
##################### Compiler Options #######################
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
# minimap
ifeq ($(TARGET_N3DS),1)
MINIMAP := 3ds/minimap
MINIMAP_C := $(wildcard $(MINIMAP)/*.c)
MINIMAP_O := $(foreach file,$(MINIMAP_C),$(BUILD_DIR)/$(file:.c=.o))
MINIMAP_TEXTURES := $(MINIMAP)/textures
MINIMAP_PNG := $(wildcard $(MINIMAP_TEXTURES)/*.png)
MINIMAP_T3S := $(foreach file,$(MINIMAP_PNG),$(BUILD_DIR)/$(file:.png=.t3s))
MINIMAP_T3X := $(foreach file,$(MINIMAP_T3S),$(file:.t3s=.t3x))
MINIMAP_T3X_O := $(foreach file,$(MINIMAP_T3X),$(file:.t3x=.t3x.o))
MINIMAP_T3X_HEADERS := $(foreach file,$(MINIMAP_PNG),$(BUILD_DIR)/$(file:.png=_t3x.h))
endif
ifeq ($(TARGET_N64),1)
IRIX_ROOT := tools/ido5.3_compiler
ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips-linux-gnu-
else ifeq ($(shell type mips64-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips64-linux-gnu-
else
CROSS := mips64-elf-
endif
# check that either QEMU_IRIX is set or qemu-irix package installed
ifeq ($(COMPILER_N64),ido)
ifndef QEMU_IRIX
QEMU_IRIX := $(shell which qemu-irix 2>/dev/null)
ifeq (, $(QEMU_IRIX))
$(error Please install qemu-irix package or set QEMU_IRIX env var to the full qemu-irix binary path)
endif
endif
endif
AS := $(CROSS)as
CC := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
CPP := cpp -P -Wno-trigraphs
LD := $(CROSS)ld
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
# change the compiler to gcc, to use the default, install the gcc-mips-linux-gnu package
ifeq ($(COMPILER_N64),gcc)
CC := $(CROSS)gcc
endif
N64_CFLAGS := -nostdinc -I include/libc -DTARGET_N64 -D_LANGUAGE_C
CC_CFLAGS := -fno-builtin
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
# Check code syntax with host compiler
CC_CHECK := gcc
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(N64_CFLAGS) $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
COMMON_CFLAGS = $(OPT_FLAGS) $(N64_CFLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(MATCH_CFLAGS) $(MIPSISET) $(GRUCODE_CFLAGS)
ASFLAGS := -march=vr4300 -mabi=32 -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS) $(MATCH_ASFLAGS) $(GRUCODE_ASFLAGS)
CFLAGS = -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(COMMON_CFLAGS) $(MIPSBIT)
OBJCOPYFLAGS := --pad-to=0x800000 --gap-fill=0xFF
SYMBOL_LINKING_FLAGS := $(addprefix -R ,$(SEG_FILES))
LDFLAGS := -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/sm64.$(VERSION).map --no-check-sections $(SYMBOL_LINKING_FLAGS)
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
ifeq ($(COMPILER_N64),gcc)
CFLAGS := -march=vr4300 -mfix4300 -mabi=32 -mno-shared -G 0 $(COMMON_CFLAGS) -mhard-float -mdivide-breaks -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I . -fno-PIC -mno-abicalls -fno-strict-aliasing -fno-inline-functions -ffreestanding -fwrapv -Wall -Wextra
endif
CC_CHECK += $(CUSTOM_C_DEFINES)
CFLAGS += $(CUSTOM_C_DEFINES)
ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU
export QEMU_GUEST_BASE := 1
else
# Ensure that gcc treats the code as 32-bit
CC_CHECK_CFLAGS += -m32
endif
# Prevent a crash with -sopt
export LANG := C
else # TARGET_N64
ifeq ($(TARGET_WII_U),1)
LD := $(CXX)
CPP := powerpc-eabi-cpp -P
OBJDUMP := powerpc-eabi-objdump
SDLCONFIG :=
else ifeq ($(TARGET_N3DS),1)
CPP := $(DEVKITARM)/bin/arm-none-eabi-cpp -P
OBJDUMP := $(DEVKITARM)/bin/arm-none-eabi-objdump
OBJCOPY := $(DEVKITARM)/bin/arm-none-eabi-objcopy
AS := $(DEVKITARM)/bin/arm-none-eabi-as
CC := $(DEVKITARM)/bin/arm-none-eabi-gcc
CXX := $(DEVKITARM)/bin/arm-none-eabi-g++
LD := $(CXX)
SDLCONFIG :=
else
ifeq ($(TARGET_SWITCH),1)
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
export PATH := $(DEVKITPRO)/devkitA64/bin:$(PATH)
PORTLIBS ?= $(DEVKITPRO)/portlibs/switch
LIBNX ?= $(DEVKITPRO)/libnx
CROSS ?= aarch64-none-elf-
SDLCROSS :=
CC := $(CROSS)gcc
CXX := $(CROSS)g++
STRIP := $(CROSS)strip
NXARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE -ftls-model=local-exec
APP_TITLE := Super Mario 64
APP_AUTHOR := Nintendo, n64decomp team, sm64pc team
APP_VERSION := 1_master_$(VERSION)
APP_ICON := $(CURDIR)/switch/logo.jpg
INCLUDE_CFLAGS += -isystem$(LIBNX)/include -I$(PORTLIBS)/include
OPT_FLAGS := -O2
endif
# for some reason sdl-config in dka64 is not prefixed, while pkg-config is
SDLCROSS ?= $(CROSS)
AS := $(CROSS)as
ifeq ($(OSX_BUILD),1)
AS := i686-w64-mingw32-as
endif
ifneq ($(TARGET_WEB),1) # As in, not-web PC port
CC ?= $(CROSS)gcc
CXX ?= $(CROSS)g++
else
CC := emcc
CXX := emcc
endif
LD := $(CC)
ifeq ($(DISCORDRPC),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
endif
ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
CPP := cpp -P
OBJCOPY := objcopy
OBJDUMP := $(CROSS)objdump
else ifeq ($(OSX_BUILD),1)
CPP := cpp-9 -P
OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy
else # Linux & other builds
CPP := $(CROSS)cpp -P
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
endif
SDLCONFIG := $(SDLCROSS)sdl2-config
WINDRES := $(CROSS)windres
endif
# configure backend flags
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, DXGI+DirectX, WHB or C3D 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_RPI),1)
else ifneq ($(TARGET_RPI)$(TARGET_SWITCH),00)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ($(OSX_BUILD),1)
BACKEND_LDFLAGS += -framework OpenGL `pkg-config --libs glew`
else
BACKEND_LDFLAGS += -lGL
endif
else ifeq ($(WINDOW_API),WHB)
BACKEND_LDFLAGS += -lSDL2 -lwut
else ifeq ($(WINDOW_API),C3D)
BACKEND_LDFLAGS +=
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 := $(SDLCROSS)sdl2-config
BACKEND_CFLAGS += -DHAVE_SDL2=1
else ifeq ($(SDL1_USED),1)
SDLCONFIG := $(SDLCROSS)sdl-config
BACKEND_CFLAGS += -DHAVE_SDL1=1
endif
ifneq ($(SDL1_USED)$(SDL2_USED),00)
BACKEND_CFLAGS += `$(SDLCONFIG) --cflags`
ifeq ($(WINDOWS_BUILD),1)
BACKEND_LDFLAGS += `$(SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
else
BACKEND_LDFLAGS += `$(SDLCONFIG) --libs`
endif
endif
ifeq ($(WINDOWS_BUILD),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
else ifeq ($(TARGET_WEB),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
# Linux / Other builds below
else
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
endif
ifeq ($(TARGET_WII_U),1)
CC_CHECK += -ffunction-sections $(MACHDEP) -ffast-math -D__WIIU__ -D__WUT__ $(INCLUDE)
CFLAGS += -ffunction-sections $(MACHDEP) -ffast-math -D__WIIU__ -D__WUT__ $(INCLUDE)
endif
ifeq ($(TARGET_N3DS),1)
CTRULIB := $(DEVKITPRO)/libctru
LIBDIRS := $(CTRULIB)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
CC_CHECK += -mtp=soft -DARM11 -DosGetTime=n64_osGetTime -D_3DS -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations -fomit-frame-pointer -ffast-math $(foreach dir,$(LIBDIRS),-I$(dir)/include)
CFLAGS += -mtp=soft -DARM11 -DosGetTime=n64_osGetTime -D_3DS -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations -fomit-frame-pointer -ffast-math $(foreach dir,$(LIBDIRS),-I$(dir)/include)
ifeq ($(DISABLE_N3DS_AUDIO),1)
CFLAGS += -DDISABLE_N3DS_AUDIO
endif
ifeq ($(DISABLE_N3DS_FRAMESKIP),1)
CFLAGS += -DDISABLE_N3DS_FRAMESKIP
endif
endif
ifeq ($(TARGET_SWITCH),1)
CC_CHECK := $(CC) $(NXARCH) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -D__SWITCH__=1
CFLAGS := $(NXARCH) $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -ftls-model=local-exec -fPIE -fwrapv -D__SWITCH__=1
endif
CC_CHECK += $(CUSTOM_C_DEFINES)
CFLAGS += $(CUSTOM_C_DEFINES)
# Load external textures
ifeq ($(EXTERNAL_DATA),1)
CC_CHECK += -DEXTERNAL_DATA -DFS_BASEDIR="\"$(BASEDIR)\""
CFLAGS += -DEXTERNAL_DATA -DFS_BASEDIR="\"$(BASEDIR)\""
# tell skyconv to write names instead of actual texture data and save the split tiles so we can use them later
SKYTILE_DIR := $(BUILD_DIR)/textures/skybox_tiles
SKYCONV_ARGS := --store-names --write-tiles "$(SKYTILE_DIR)"
endif
ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS)
ifeq ($(TARGET_WEB),1)