-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
318 lines (227 loc) · 10.3 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
# Makefile to rebuild Kirby 64 split image
################ Target Executable and Sources ###############
# BUILD_DIR is location where all build artifacts are placed
BUILD_DIR_BASE = build
VERSION = us
BUILD_DIR = $(BUILD_DIR_BASE)/$(VERSION)
GRUCODE := F3DEX2_2.04H
LOCAL_ARMIPS=tools/armips/build/armips
VERBOSE := 1
# check that either QEMU_IRIX is set or qemu-irix package installed
ifndef QEMU_IRIX
QEMU_IRIX := $(shell which qemu-irix)
ifeq (, $(QEMU_IRIX))
$(error Please install qemu-irix package or set QEMU_IRIX env var to the full qemu-irix binary path)
endif
endif
V := @
ifeq (VERBOSE, 1)
V=
endif
##################### Compiler Options #######################
# IRIX_ROOT := tools/ido5.3_compiler
IRIX_ROOT := tools/ido7.1
# CC := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
CC := tools/ido-7.1recomp/cc
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 ifeq ($(shell type mips-n64-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips-n64-
else
CROSS := mips64-elf-
endif
GCC := $(CROSS)gcc
AS = $(CROSS)as
# CC = $(CROSS)gcc
CPP := $(CROSS)cpp -P -Wno-trigraphs
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
PYTHON := python3
TEXTURES_DIR := textures
# UNNAMED_SYMS := -T unnamed_syms.txt
INCLUDE_FLAGS := -I$(BUILD_DIR)
ASFLAGS = -mtune=vr4300 -march=vr4300 --no-pad-sections -mabi=32 -mips3 $(INCLUDE_FLAGS)
# CFLAGS = -Wall -O2 -mtune=vr4300 -march=vr4300 -G 0 -c -Wab,-r4300_mul
LDFLAGS = --no-check-sections -mips3 --accept-unknown-input-arch \
-T $(BUILD_DIR)/$(LD_SCRIPT) -T libultra_unused.txt $(UNNAMED_SYMS) -T undefined_syms.txt -T rcp_syms.txt \
-Map $(BUILD_DIR)/$(TARGET).map
PRELIM_OBJCOPY_FLAGS = --pad-to=0x101000 --gap-fill=0x00
OBJCOPY_FLAGS = --pad-to=0x2000000 --gap-fill=0xFF
####################### Other Tools #########################
# N64 tools
TOOLS_DIR = tools
N64CRC = tools/n64crc
N64GRAPHICS = $(TOOLS_DIR)/n64graphics
EMULATOR = ~/Downloads/mupen64plus/mupen64plus-gui
EMU_FLAGS = # --noosd --gfx mupen64plus-video-glide64mk2
LOADER = loader64
LOADER_FLAGS = -vwf
FixPath = $(subst /,/,$1)
ASSET_DIRS := $(wildcard assets/geo/bank_0/**) \
$(wildcard assets/geo/bank_1/**) \
$(wildcard assets/geo/bank_2/**) \
$(wildcard assets/geo/bank_7/**) \
$(wildcard assets/geo/bank_3/**)
ASM_DIRS := asm data $(wildcard asm/ovl*) asm/ovl0/lib \
asm/data asm/banks $(wildcard data/ovl*)
SRC_DIRS := src $(wildcard src/ovl*) data $(wildcard data/ovl*)
BIN_DIRS := bin/geo bin/image bin/misc bin/anim
DATA_DIRS := actors
DATA_FILES := $(foreach dir,$(DATA_DIRS),$(wildcard $(dir)/*.c))
LEVEL_DIRS = $(wildcard assets/misc/bank_7/*)
LEVEL_FILES = $(foreach dir, $(LEVEL_DIRS), $(wildcard $(dir)/level.bin))
LEVEL_S_FILES = $(foreach file, $(LEVEL_FILES), $(file:.bin=.s))
LEVEL_O_FILES = $(foreach file, $(LEVEL_S_FILES), $(BUILD_DIR)/$(file:.s=.o))
TEXTURES_DIR = textures
MIPSISET := -mips2 -32
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))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
# S_FILES += $(LEVEL_S_FILES)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
MODEL_FILES := $(foreach dir,$(ASSET_DIRS),$(wildcard $(dir)/geo.bin))
MODEL_C_FILES := $(foreach file,$(MODEL_FILES),$(file:.bin=.c))
UCODE_BASE_DIR := ucode
UCODES := L3DEX2_2.04H S2DEX2_2.04
UCODE_DIRS := $(foreach ucode,$(UCODES) $(GRUCODE),$(UCODE_BASE_DIR)/$(ucode))
UCODE_TEXT_FILES := $(foreach ucode,$(UCODES),$(UCODE_BASE_DIR)/$(ucode)/$(ucode).code)
UCODE_DATA_FILES := $(foreach ucode,$(UCODES),$(UCODE_BASE_DIR)/$(ucode)/$(ucode).data)
UCODE_TEXT_O_FILES := $(addprefix $(BUILD_DIR)/,$(UCODE_TEXT_FILES:.code=.code.o)) $(BUILD_DIR)/$(UCODE_BASE_DIR)/$(GRUCODE)/$(GRUCODE).code.o
UCODE_DATA_O_FILES := $(addprefix $(BUILD_DIR)/,$(UCODE_DATA_FILES:.data=.data.o)) $(BUILD_DIR)/$(UCODE_BASE_DIR)/$(GRUCODE)/$(GRUCODE).data.o
BUILD_ASM_DIRS := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/**/))
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o))
ASSET_O_FILES := $(foreach file,$(MODEL_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
D_FILES := $(O_FILES:.o=.d)
ACTOR_FILES := $(foreach file,$(DATA_FILES),$(BUILD_DIR)/$(file:.c=.o))
# FLAGS
OPT_FLAGS := -O2
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I $(BUILD_DIR)/assets -I src -I .
TARGET_CFLAGS := -nostdinc -I include/libc -DTARGET_N64 -DF3DEX_GBI_2
CFLAGS = -Wab,-r4300_mul -non_shared -G0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) $(MIPSISET)
GCC_CFLAGS = -Wall $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) -march=vr4300 -mtune=vr4300 -mfix4300 -mabi=32 -mno-shared -G 0 -fno-PIC -mno-abicalls -fno-zero-initialized-in-bss -fno-toplevel-reorder -Wno-missing-braces
CC_CHECK := gcc -fsyntax-only -fsigned-char -m32 $(CC_CFLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CC_TEST := gcc -Wall
######################## Targets #############################
NOEXTRACT ?= 0
ALL_DIRS = $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(LEVEL_DIRS) $(ASSET_DIRS) $(SRC_DIRS) $(INCLUDE_DIRS) $(ASM_DIRS) $(TEXTURES_DIR)/raw $(TEXTURES_DIR)/standalone $(UCODE_DIRS))
DUMMY != mkdir -p $(ALL_DIRS)
# Checking if submodules exist
DUMMY != ls libreultra >/dev/null || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Missing submodule libreultra. Please run 'git submodule update --init')
endif
DUMMY != ls f3dex2 >/dev/null || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Missing submodule f3dex2. Please run 'git submodule update --init')
endif
# hardcoded compiler for ml.c until i figure out why it's breaking recomp
$(BUILD_DIR)/src/ovl0/memory_layer.o: CC = $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
default: all
TARGET = kirby.us
LD_SCRIPT = $(TARGET).ld
# TEXTURE_DIR = textures
# RAW_TEXTURE_FILES := $(addprefix $(BUILD_DIR)/,$(patsubst %.png,%,$(wildcard $(TEXTURES_DIR)/raw/*.png)))
$(BUILD_DIR)/data/kirby.066630.o: $(BUILD_DIR)/assets/assets.marker
libreultra/build/2.0I/libultra_rom.a:
$(MAKE) -C libreultra -j4
libreultra/build/2.0I/libn_audio.a:
$(MAKE) -C libreultra naudio -j4
all: $(BUILD_DIR)/$(TARGET).z64
@sha1sum -c $(TARGET).sha1
clean:
rm -rf build/
distclean:
rm -rf build/
tools/extract_assets --clean
$(MAKE) -C tools clean
$(MAKE) -C libreultra clean
$(MAKE) -C f3dex2 clean
rm -rf f3dex2/$(GRUCODE)
# TODO: remove these
rm -rf assets/geo
rm -rf assets/image
rm -rf assets/anim
rm -rf assets/misc
softclean:
rm -rf build/us/src/
rm -rf build/us/asm/
# $(BUILD_DIR)/src/ovl0/ovl0_8.o: OPT_FLAGS += -framepointer
$(BUILD_DIR)/src/ovl7/yakulib.o: OPT_FLAGS = -O2 -Olimit 1000
$(BUILD_DIR)/src/ovl1/ovl1_5.o: OPT_FLAGS = -O2
$(BUILD_DIR)/src/ovl3/ovl3_1.o: OPT_FLAGS = -O2 -Wo,-loopunroll
# $(BUILD_DIR)/src/ovl7/yakulib.o: CC = $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
# $(BUILD_DIR)/src/ovl1/save_file.o: OPT_FLAGS += -Wo,-loopunroll,0
$(BUILD_DIR):
mkdir $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
# assets/misc/%.s: assets/misc/%.bin
# python3 tools/level_settings/helper.py $<
$(BUILD_DIR)/libultra.a: libreultra/build/2.0I/libultra_rom.a
cp $< $@
$(TOOLS_DIR)/patch_libultra_math $@
$(BUILD_DIR)/libn_audio.a: libreultra/build/2.0I/libn_audio.a
cp $< $@
$(TOOLS_DIR)/patch_libultra_math $@
$(BUILD_DIR)/$(UCODE_BASE_DIR)/$(GRUCODE)/$(GRUCODE).%.o: f3dex2/$(GRUCODE)/$(GRUCODE).%
$(OBJCOPY) -I binary -O elf32-big $< $@
$(BUILD_DIR)/%.o: %.s
$(CPP) $(GCC_CFLAGS) -o $(@:.o=.i) $<
$(AS) $(ASFLAGS) -o $@ $(@:.o=.i)
$(BUILD_DIR)/%.o: %.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_DIR)/data/%.o: data/%.c
# $(CC_TEST) -c $(INCLUDE_CFLAGS) -o $@ $<
$(GCC) -c $(GCC_CFLAGS) -D__sgi -o $@ $<
# assets/geo/%.c: assets/geo/%.bin
# python3 tools/decompile_geos.py $<
# $(BUILD_DIR)/assets/geo/%.o: assets/geo/%.c
# $(GCC) -c $(GCC_CFLAGS) -D__sgi -o $@ $<
# $(BUILD_DIR)/assets/geo/%.o: assets/geo/%.s
# $(AS) -c $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/assets/assets.marker:
$(MAKE) -C assets
# $(BUILD_DIR)/assets/misc/%.o: assets/misc/%.s
# $(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c $(CFLAGS) -o $@ $<
$(BUILD_DIR)/$(UCODE_BASE_DIR)/%.o : $(UCODE_BASE_DIR)/%
$(OBJCOPY) -I binary -O elf32-big $< $@
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(UCODE_LD) rcp_syms.txt undefined_syms.txt unnamed_syms.txt $(BUILD_DIR)/assets/assets.marker
$(CPP) $(VERSION_CFLAGS) $(INCLUDE_CFLAGS) -MMD -MP -MT $@ -MF $@.d -o $@ $< \
-DBUILD_DIR=$(BUILD_DIR) -Umips
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) $(BUILD_DIR)/libultra.a $(BUILD_DIR)/libn_audio.a $(UCODE_TEXT_O_FILES) $(UCODE_DATA_O_FILES)
$(V)$(LD) -L $(BUILD_DIR) $(LDFLAGS) -o $@ $(LIBS) -lultra -ln_audio
# final z64 updates checksum
$(BUILD_DIR)/$(TARGET).z64: $(BUILD_DIR)/$(TARGET).elf
$(OBJCOPY) $< $(BUILD_DIR)/$(@F).bin -O binary $(PRELIM_OBJCOPY_FLAGS)
$(LD) -r -b binary -o $(BUILD_DIR)/$(@F).elf.1 $(BUILD_DIR)/$(@F).bin
$(OBJCOPY) $(BUILD_DIR)/$(@F).elf.1 $@ -O binary $(OBJCOPY_FLAGS)
$(N64CRC) $@
@python3 tools/progress2.py -m
$(GLOBAL_ASM_O_FILES): CC := $(PYTHON) tools/asm-processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
test: $(BUILD_DIR)/$(TARGET).z64
$(EMULATOR) $(EMU_FLAGS) $<
test2: $(BUILD_DIR)/$(TARGET).z64
flatpak run --file-forwarding io.github.m64p.m64p @@ $< @@
test-pj64: $(BUILD_DIR)/$(TARGET).z64
wine ~/Desktop/new64/Project64.exe $<
load: $(BUILD_DIR)/$(TARGET).z64
$(LOADER) $(LOADER_FLAGS) $<
setup:
$(MAKE) -C libreultra -j4
$(MAKE) -C libreultra naudio -j4
$(MAKE) -C tools -j4
$(MAKE) -C f3dex2 $(GRUCODE) PARENT_OUTPUT_DIR=../f3dex2/ ARMIPS=../$(LOCAL_ARMIPS)
tools/extract_assets baserom.$(VERSION).z64
.PHONY: all clean default diff test distclean
# Remove built-in rules, to improve performance
MAKEFLAGS += --no-builtin-rules
-include $(D_FILES)
-include $(BUILD_DIR)/$(LD_SCRIPT).d
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true