-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
560 lines (462 loc) · 20.8 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
# Build options can be changed by modifying the makefile or by building with 'make SETTING=value'.
# It is also possible to override the settings in Defaults in a file called .make_options as 'SETTING=value'.
-include .make_options
MAKEFLAGS += --no-builtin-rules --no-print-directory
# Returns the path to the command $(1) if exists. Otherwise returns an empty string.
find-command = $(shell which $(1) 2>/dev/null)
#### Defaults ####
# If COMPARE is 1, check the output md5sum after building
COMPARE ?= 1
# If NON_MATCHING is 1, define the NON_MATCHING C flag when building
NON_MATCHING ?= 0
# if WERROR is 1, pass -Werror to CC_CHECK, so warnings would be treated as errors
WERROR ?= 0
# Keep .mdebug section in build
KEEP_MDEBUG ?= 0
# Check code syntax with host compiler
RUN_CC_CHECK ?= 1
CC_CHECK_COMP ?= gcc
# Dump build object files
OBJDUMP_BUILD ?= 0
# Number of threads to compress with
N_THREADS ?= $(shell nproc)
# If COMPILER is GCC, compile with GCC instead of IDO.
COMPILER ?= ido
# Whether to colorize build messages
COLOR ?= 1
# Whether to hide commands or not
VERBOSE ?= 0
# Command for printing messages during the make.
PRINT ?= printf
# Set prefix to mips binutils binaries (mips-linux-gnu-ld => 'mips-linux-gnu-') - Change at your own risk!
# Auto-detect prefix for MIPS toolchain
ifneq ($(call find-command,mips-linux-gnu-ld),)
MIPS_BINUTILS_PREFIX := mips-linux-gnu-
else ifneq ($(call find-command,mips64-linux-gnu-ld),)
MIPS_BINUTILS_PREFIX := mips64-linux-gnu-
else ifneq ($(call find-command,mips64-elf-ld),)
MIPS_BINUTILS_PREFIX := mips64-elf-
else
$(error Unable to detect a suitable MIPS toolchain installed)
endif
VERSION ?= us
REV ?= rev0
BASEROM := baserom.$(VERSION).$(REV).z64
TARGET := fzerox
### Output ###
BUILD_DIR := build
TOOLS := tools
PYTHON := python3
ROMC := $(BUILD_DIR)/$(TARGET).$(VERSION).$(REV).z64
ELF := $(BUILD_DIR)/$(TARGET).$(VERSION).$(REV).elf
LD_MAP := $(BUILD_DIR)/$(TARGET).$(VERSION).$(REV).map
LD_SCRIPT := linker_scripts/$(VERSION)/$(REV)/$(TARGET).ld
#### Setup ####
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(OS),Windows_NT)
$(error Native Windows is currently unsupported for building this repository, use WSL instead c:)
else ifeq ($(UNAME_S),Linux)
DETECTED_OS := linux
#Detect aarch64 devices (Like Raspberry Pi OS 64-bit)
#If it's found, then change the compiler to a version that can compile in 32 bit mode.
ifeq ($(UNAME_M),aarch64)
CC_CHECK_COMP := arm-linux-gnueabihf-gcc
endif
else ifeq ($(UNAME_S),Darwin)
DETECTED_OS := macos
MAKE := gmake
CPPFLAGS += -xc++
CC_CHECK_COMP := clang
endif
# If gcc is used, define the NON_MATCHING flag respectively so the files that
# are safe to be used can avoid using GLOBAL_ASM which doesn't work with gcc.
ifeq ($(COMPILER),gcc)
$(warning WARNING: GCC support is experimental. Use at your own risk.)
CFLAGS += -DCOMPILER_GCC
NON_MATCHING := 1
endif
# Detect compiler and set variables appropriately.
ifeq ($(COMPILER),gcc)
CC := $(MIPS_BINUTILS_PREFIX)gcc
else
ifeq ($(COMPILER),ido)
CC := $(TOOLS)/ido-recomp/$(DETECTED_OS)/7.1/cc
else
$(error Unsupported compiler. Please use either ido or gcc as the COMPILER variable.)
endif
endif
ifeq ($(COMPILER),gcc)
OPTFLAGS := -Os
else
OPTFLAGS := -O2
endif
ifeq ($(COMPILER),gcc)
CFLAGS += -G 0 -ffast-math -fno-unsafe-math-optimizations -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-zero-initialized-in-bss -fno-toplevel-reorder -ffreestanding -fno-common -fno-merge-constants -mno-explicit-relocs -mno-split-addresses $(CHECK_WARNINGS) -funsigned-char
MIPS_VERSION := -mips3
else
# we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff.
CFLAGS += -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(IINC) -nostdinc -Wab,-r4300_mul -woff 649,838,712,516
MIPS_VERSION := -mips2
WARNINGS := -fullwarn -verbose -woff 624,649,838,712,516,513,596,564,594,709
endif
ifeq ($(COMPILER),ido)
# Have CC_CHECK pretend to be a MIPS compiler
MIPS_BUILTIN_DEFS := -D_MIPS_ISA_MIPS2=2 -D_MIPS_ISA=_MIPS_ISA_MIPS2 -D_ABIO32=1 -D_MIPS_SIM=_ABIO32 -D_MIPS_SZINT=32 -D_MIPS_SZLONG=32 -D_MIPS_SZPTR=32
CC_CHECK = gcc -fno-builtin -fsyntax-only -funsigned-char -std=gnu90 -D_LANGUAGE_C -DNON_MATCHING $(MIPS_BUILTIN_DEFS) $(IINC) $(CHECK_WARNINGS)
ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU
export QEMU_GUEST_BASE := 1
else
# Ensure that gcc (warning check) treats the code as 32-bit
CC_CHECK += -m32
endif
else
CC_CHECK = @:
endif
BUILD_DEFINES ?=
# Version check
ifeq ($(VERSION),jp)
BUILD_DEFINES += -DVERSION_JP=1
endif
ifeq ($(VERSION),us)
BUILD_DEFINES += -DVERSION_US=1
endif
ifeq ($(VERSION),eu)
BUILD_DEFINES += -DVERSION_EU=1
REV := rev0
endif
ifeq ($(NON_MATCHING),1)
BUILD_DEFINES += -DNON_MATCHING -DAVOID_UB
CPPFLAGS += -DNON_MATCHING -DAVOID_UB
endif
MAKE = make
CPPFLAGS += -fno-dollars-in-identifiers -P
LDFLAGS := --no-check-sections --accept-unknown-input-arch --emit-relocs
# Support python venv's if one is installed.
PYTHON_VENV = .venv/bin/python3
ifneq "$(wildcard $(PYTHON_VENV) )" ""
PYTHON = $(PYTHON_VENV)
endif
ifeq ($(VERBOSE),0)
V := @
endif
ifeq ($(COLOR),1)
NO_COL := \033[0m
RED := \033[0;31m
GREEN := \033[0;32m
BLUE := \033[0;34m
YELLOW := \033[0;33m
PURPLE := \033[0;35m
BLINK := \033[33;5m
endif
# Common build print status function
define print
@$(PRINT) "$(GREEN)$(1) $(YELLOW)$(2)$(GREEN) -> $(BLUE)$(3)$(NO_COL)\n"
endef
#### Tools ####
ifneq ($(shell type $(MIPS_BINUTILS_PREFIX)ld >/dev/null 2>/dev/null; echo $$?), 0)
$(error Unable to find $(MIPS_BINUTILS_PREFIX)ld. Please install or build MIPS binutils, commonly mips-linux-gnu. (or set MIPS_BINUTILS_PREFIX if your MIPS binutils install uses another prefix))
endif
### Compiler ###
IDO53 := $(TOOLS)/ido-recomp/$(DETECTED_OS)/5.3/cc
IDO := $(TOOLS)/ido-recomp/$(DETECTED_OS)/7.1/cc
AS := $(MIPS_BINUTILS_PREFIX)as
LD := $(MIPS_BINUTILS_PREFIX)ld
OBJCOPY := $(MIPS_BINUTILS_PREFIX)objcopy
OBJDUMP := $(MIPS_BINUTILS_PREFIX)objdump
ICONV := iconv
ASM_PROC := $(PYTHON) $(TOOLS)/asm-processor/build.py
CAT := cat
TORCH := $(TOOLS)/Torch/cmake-build-release/torch
# Prefer clang as C preprocessor if installed on the system
ifneq (,$(call find-command,clang))
CPP := clang
CPPFLAGS := -E -P -x c -Wno-trigraphs -Wmissing-prototypes -Wstrict-prototypes -D_LANGUAGE_ASSEMBLY
else
CPP := cpp
CPPFLAGS := -P -Wno-trigraphs -Wmissing-prototypes -Wstrict-prototypes -D_LANGUAGE_ASSEMBLY
endif
ASM_PROC_FLAGS := --input-enc=utf-8 --output-enc=euc-jp --convert-statics=global-with-filename
SPLAT ?= $(PYTHON) $(TOOLS)/splat/split.py
SPLAT_YAML ?= $(TARGET).$(VERSION).$(REV).yaml
MIO0 := $(TOOLS)/mio0
EXTRACT_MIO0 := $(PYTHON) $(TOOLS)/decompressMio0Segments.py
IINC := -Iinclude -Ibin/$(VERSION).$(REV) -I.
IINC += -Ilib/ultralib/include -Ilib/ultralib/include/PR -Ilib/ultralib/include/ido
ifeq ($(KEEP_MDEBUG),0)
RM_MDEBUG = $(OBJCOPY) --remove-section .mdebug $@
else
RM_MDEBUG = @:
endif
# Check code syntax with host compiler
CHECK_WARNINGS := -Wall -Wextra -Wimplicit-fallthrough -Wno-unknown-pragmas -Wno-missing-braces -Wno-sign-compare -Wno-uninitialized
# Have CC_CHECK pretend to be a MIPS compiler
MIPS_BUILTIN_DEFS := -DMIPSEB -D_MIPS_FPSET=16 -D_MIPS_ISA=2 -D_ABIO32=1 -D_MIPS_SIM=_ABIO32 -D_MIPS_SZINT=32 -D_MIPS_SZPTR=32
ifneq ($(RUN_CC_CHECK),0)
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
CHECK_WARNINGS := -Wno-unused-variable -Wno-int-conversion
CC_CHECK := $(CC_CHECK_COMP)
CC_CHECK_FLAGS := -MMD -MP -fno-builtin -fsyntax-only -funsigned-char -fdiagnostics-color -std=gnu89 -DNON_MATCHING -DAVOID_UB -DCC_CHECK=1
# Ensure that gcc treats the code as 32-bit
ifeq ($(UNAME_M),aarch64)
CC_CHECK_FLAGS += -march=armv7-a+fp
else
CC_CHECK_FLAGS += -m32
endif
ifneq ($(WERROR), 0)
CHECK_WARNINGS += -Werror
endif
else
CC_CHECK := @:
endif
ASFLAGS := -march=vr4300 -32 -G0
COMMON_DEFINES := -D_MIPS_SZLONG=32
GBI_DEFINES := -DF3DEX_GBI_2
RELEASE_DEFINES := -DNDEBUG
AS_DEFINES := -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_ULTRA64
C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C -DBUILD_VERSION=VERSION_H ${RELEASE_DEFINES}
ENDIAN := -EB
ICONV_FLAGS := --from-code=UTF-8 --to-code=EUC-JP
# Use relocations and abi fpr names in the dump
OBJDUMP_FLAGS := --disassemble --reloc --disassemble-zeroes -Mreg-names=32 -Mno-aliases
ifneq ($(OBJDUMP_BUILD), 0)
OBJDUMP_CMD = $(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.dump.s)
OBJCOPY_BIN = $(OBJCOPY) -O binary $@ [email protected]
else
OBJDUMP_CMD = @:
OBJCOPY_BIN = @:
endif
# rom compression flags
COMPFLAGS := --threads $(N_THREADS)
ifeq ($(NON_MATCHING),0)
COMPFLAGS += --matching
endif
#### Files ####
$(shell mkdir -p asm bin linker_scripts/$(VERSION)/$(REV)/auto)
SRC_DIRS := $(shell find src -type d)
ASM_DIRS := $(shell find asm/$(VERSION)/$(REV) -type d -not -path "asm/$(VERSION)/$(REV)/nonmatchings/*")
BIN_DIRS := $(shell find bin -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
C_FILES := $(filter-out %.inc.c,$(C_FILES))
C_FILES := $(filter-out %.incbin.c,$(C_FILES))
S_FILES := $(foreach dir,$(ASM_DIRS) $(SRC_DIRS),$(wildcard $(dir)/*.s))
BIN_FILES := $(foreach dir,$(BIN_DIRS),$(wildcard $(dir)/*.bin))
O_FILES := $(foreach f,$(C_FILES:.c=.o),$(BUILD_DIR)/$f) \
$(foreach f,$(S_FILES:.s=.o),$(BUILD_DIR)/$f) \
$(foreach f,$(BIN_FILES:.bin=.o),$(BUILD_DIR)/$f)
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) \
$(O_FILES:.o=.asmproc.d)
# create build directories
$(shell mkdir -p $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV) $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/auto $(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(BIN_DIRS),$(BUILD_DIR)/$(dir)))
ifeq ($(COMPILER),ido)
# directory flags
$(BUILD_DIR)/src/libultra/gu/%.o: OPTFLAGS := -O3 -g0
$(BUILD_DIR)/src/libultra/io/%.o: OPTFLAGS := -O1 -g0
$(BUILD_DIR)/src/libultra/io/pimgr.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/vimgr.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/sirawdma.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsselectbank.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/leointerrupt.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/crc.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/contramread.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/contramwrite.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/contreaddata.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/contpfs.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsreadwritefile.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsallocatefile.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsfreeblocks.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfssearchfile.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsinitpak.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfsgetstatus.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/pfschecker.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/leodiskinit.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/viswapcontext.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/io/motor.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/os/%.o: OPTFLAGS := -O1 -g0
# libleo
$(BUILD_DIR)/src/leo/%.o: OPTFLAGS := -g
# per-file flags
$(BUILD_DIR)/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/libc/sprintf.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/libc/xlitob.o: OPTFLAGS := -O2 -g0
$(BUILD_DIR)/src/libultra/libc/xldtob.o: OPTFLAGS := -O3 -g0
$(BUILD_DIR)/src/libultra/libc/xprintf.o: OPTFLAGS := -O3 -g0
$(BUILD_DIR)/src/libultra/libc/ll.o: OPTFLAGS := -O1 -g0
$(BUILD_DIR)/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/libultra/libc/llcvt.o: OPTFLAGS := -O1 -g0
$(BUILD_DIR)/src/libultra/libc/llcvt.o: MIPS_VERSION := -mips3 -32
# cc & asm-processor
CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) --
$(BUILD_DIR)/src/libultra/gu/%.o: CC := $(IDO53)
$(BUILD_DIR)/src/libultra/io/%.o: CC := $(IDO53)
$(BUILD_DIR)/src/libultra/os/%.o: CC := $(IDO53)
$(BUILD_DIR)/src/libultra/libc/%.o: CC := $(IDO53)
# libleo
$(BUILD_DIR)/src/leo/lib/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO53) -- $(AS) $(ASFLAGS) --
else
# directory flags
# $(BUILD_DIR)/src/libultra/gu/%.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/io/%.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/os/%.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/rmon/%.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/debug/%.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/host/%.o: OPTFLAGS := -Os
# per-file flags
# $(BUILD_DIR)/src/audio/audio_load.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_heap.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_effects.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_general.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_playback.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_seqplayer.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/audio/audio_thread.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libc_sprintf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libc_math64.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/ldiv.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/string.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/xlitob.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/xldtob.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/xprintf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/ll.o: OPTFLAGS := -O2
# $(BUILD_DIR)/src/libultra/libc/ll.o: MIPS_VERSION := -mips3
# cc & asm-processor
# $(BUILD_DIR)/src/libultra/gu/sqrtf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/sinf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/lookat.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/ortho.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/perspective.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/mtxutil.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/gu/cosf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/xprintf.o: OPTFLAGS := -Os
# $(BUILD_DIR)/src/libultra/libc/xldtob.o: OPTFLAGS := -Os
endif
all: compressed
toolchain:
@$(MAKE) -s -C $(TOOLS)
torch:
@$(MAKE) -s -C $(TOOLS) torch
rm -f torch.hash.yml
init:
@$(MAKE) clean
@$(MAKE) extract -j $(N_THREADS)
@$(MAKE) assets -j $(N_THREADS)
@$(MAKE) compressed -j $(N_THREADS)
FZERO :=$(PURPLE)________ _______ _______ ______ ____ ___ ___\n| ____/ |___ | | ____| | __ \ / __ \ \ \ / /\n| |____ ___ / / | |___ | |_/ / | | | | \ V /\n| ____| |___| / / | ___| | _ | | | | | | |\n| | / /__ | |____ | | \ \ | |__| | / . \ \n|_| |______| |______| |_| \_| \____/ /__/ \__\ \n$(NO_COL)
compressed: $(ROMC)
ifeq ($(COMPARE),1)
@echo "$(GREEN)Calculating Rom Header Checksum... $(YELLOW)$<$(NO_COL)"
@md5sum --status -c $(TARGET).$(VERSION).$(REV).md5 && \
$(PRINT) "$(BLUE)$(TARGET).$(VERSION).$(REV).z64$(NO_COL): $(GREEN)OK$(NO_COL)\n$(FZERO)" || \
$(PRINT) "$(BLUE)$(TARGET).$(VERSION).$(REV).z64 $(RED)FAILED$(NO_COL)\n"
endif
#### Main Targets ###
extract:
@$(RM) -r asm/$(VERSION)/$(REV) bin/$(VERSION)/$(REV) mio0/$(VERSION)/$(REV)
@echo "Unifying yamls..."
@$(CAT) yamls/$(VERSION)/$(REV)/header.yaml yamls/$(VERSION)/$(REV)/main.yaml yamls/$(VERSION)/$(REV)/overlays.yaml yamls/$(VERSION)/$(REV)/assets.yaml > $(SPLAT_YAML)
@echo "Extracting..."
@$(SPLAT) $(SPLAT_YAML)
@echo "Decompressing MIO0s..."
@$(EXTRACT_MIO0) $(VERSION) $(REV)
assets:
@echo "Extracting assets from ROM..."
@$(TORCH) code $(BASEROM)
@$(TORCH) header $(BASEROM)
@$(TORCH) modding export $(BASEROM)
mod:
@$(TORCH) modding import code $(BASEROM)
clean:
rm -f torch.hash.yml
@git clean -fdx asm/$(VERSION)/$(REV)
@git clean -fdx bin/$(VERSION)/$(REV)
@git clean -fdx mio0/$(VERSION)/$(REV)
@git clean -fdx $(BUILD_DIR)/
@git clean -fdx src/assets/
@git clean -fdx include/assets/
@git clean -fdx linker_scripts/$(VERSION)/$(REV)/*.ld
format:
@$(PYTHON) $(TOOLS)/format.py -j $(N_THREADS)
checkformat:
@$(TOOLS)/check_format.sh -j $(N_THREADS)
# asm-differ expected object files
expected:
mkdir -p expected/build
rm -rf expected/build/
cp -r $(BUILD_DIR)/ expected/build/
context:
@echo "Generating ctx.c ..."
@$(PYTHON) ./$(TOOLS)/m2ctx.py $(filter-out $@, $(MAKECMDGOALS))
disasm:
@$(RM) -r asm/$(VERSION)/$(REV) bin/$(VERSION)/$(REV) mio0/$(VERSION)/$(REV)
@echo "Unifying yamls..."
@$(CAT) yamls/$(VERSION)/$(REV)/header.yaml yamls/$(VERSION)/$(REV)/main.yaml yamls/$(VERSION)/$(REV)/overlays.yaml yamls/$(VERSION)/$(REV)/assets.yaml > $(SPLAT_YAML)
@echo "Extracting..."
@$(SPLAT) $(SPLAT_YAML) --disassemble-all
#### Various Recipes ####
# Compressed ROM
$(ROMC): $(ELF)
$(call print,ELF->ROM:,$<,$@)
$(V)$(OBJCOPY) -O binary $< $@
# Link
$(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/pif_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/auto/undefined_funcs_auto.ld
$(call print,Linking:,$<,$@)
$(V)$(LD) $(LDFLAGS) -T $(LD_SCRIPT) \
-T $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/pif_syms.ld \
-T $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/auto/undefined_syms_auto.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/$(REV)/auto/undefined_funcs_auto.ld \
-Map $(LD_MAP) -o $@
# PreProcessor
$(BUILD_DIR)/%.ld: %.ld
$(call print,PreProcessor:,$<,$@)
$(V)$(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@
# Mio0 Todo: Figure out how to link mio0 bins through here only
# $(BUILD_DIR)/%.mio0: %.mio0d
# $(call print,mio0:,$<,$@)
# $(V)$(MIO0) -c $< $@
# $(BUILD_DIR)/%.mio0.s: $(BUILD_DIR)/%.mio0
# $(call print,Generating mio0 asm:,$<,$@)
# $(V)$(PRINT) ".section .data\n\n.balign 4\n\n.incbin \"$<\"\n" > $@
# $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.mio0.s
# $(call print,Compiling mio0:,$<,$@)
# $(V)$(AS) $(ASFLAGS) -o $@ $<
# $(BUILD_DIR)/%.o: %.mio0
# $(call print,mio0:,$<,$@)
# $(V)$(MIO0) -c $< $@
# $(V)$(OBJCOPY) -I binary -O elf32-big $@ $@
# Binary
$(BUILD_DIR)/%.o: %.bin
$(call print,Binary:,$<,$@)
$(V)$(OBJCOPY) -I binary -O elf32-big $< $@
# Assembly
$(BUILD_DIR)/%.o: %.s
$(call print,Assembling:,$<,$@)
$(V)$(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) -I $(dir $*) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(AS_DEFINES) $< | $(ICONV) $(ICONV_FLAGS) | $(AS) $(ASFLAGS) $(ENDIAN) $(IINC) -I $(dir $*) -o $@
$(V)$(OBJDUMP_CMD)
# C
$(BUILD_DIR)/%.o: %.c
$(call print,Compiling:,$<,$@)
@$(CC_CHECK) $(CC_CHECK_FLAGS) $(IINC) -I $(dir $*) $(CHECK_WARNINGS) $(BUILD_DEFINES) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $<
$(V)$(CC) -c $(CFLAGS) $(BUILD_DEFINES) $(IINC) $(WARNINGS) $(MIPS_VERSION) $(ENDIAN) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(OPTFLAGS) -o $@ $<
$(V)$(OBJDUMP_CMD)
$(V)$(RM_MDEBUG)
# Patch ll.o
$(BUILD_DIR)/src/libultra/libc/ll.o: src/libultra/libc/ll.c
$(call print,Patching:,$<,$@)
@$(CC_CHECK) $(CC_CHECK_FLAGS) $(IINC) -I $(dir $*) $(CHECK_WARNINGS) $(BUILD_DEFINES) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $<
$(V)$(CC) -c $(CFLAGS) $(BUILD_DEFINES) $(IINC) $(WARNINGS) $(MIPS_VERSION) $(ENDIAN) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(OPTFLAGS) -o $@ $<
$(V)$(PYTHON) $(TOOLS)/set_o32abi_bit.py $@
$(V)$(OBJDUMP_CMD)
$(V)$(RM_MDEBUG)
# Patch llcvt.o
$(BUILD_DIR)/src/libultra/libc/llcvt.o: src/libultra/libc/llcvt.c
$(call print,Patching:,$<,$@)
@$(CC_CHECK) $(CC_CHECK_FLAGS) $(IINC) -I $(dir $*) $(CHECK_WARNINGS) $(BUILD_DEFINES) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $<
$(V)$(CC) -c $(CFLAGS) $(BUILD_DEFINES) $(IINC) $(WARNINGS) $(MIPS_VERSION) $(ENDIAN) $(COMMON_DEFINES) $(RELEASE_DEFINES) $(GBI_DEFINES) $(C_DEFINES) $(OPTFLAGS) -o $@ $<
$(V)$(PYTHON) $(TOOLS)/set_o32abi_bit.py $@
$(V)$(OBJDUMP_CMD)
$(V)$(RM_MDEBUG)
-include $(DEP_FILES)
# Print target for debugging
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
.PHONY: all compressed clean init extract expected format checkformat assets context disasm toolchain