-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
394 lines (291 loc) · 12.1 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
BASENAME = sssv
VERSION := us
# Colors
NO_COL := \033[0m
RED := \033[0;31m
RED2 := \033[1;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
PINK := \033[0;35m
CYAN := \033[0;36m
# Directories
BUILD_DIR = build
ASM_DIRS = asm \
asm/libc \
asm/libultra/audio \
asm/data asm/data/libultra/audio asm/data/core asm/data/sssv asm/data/sssv/animals
BIN_DIRS = assets assets/levels
SRC_DIR = src.$(VERSION)
SRC_DIRS = $(SRC_DIR) $(SRC_DIR)/core \
$(SRC_DIR)/libultra/audio $(SRC_DIR)/libultra/libc \
$(SRC_DIR)/sssv $(SRC_DIR)/sssv/animals \
$(SRC_DIR)/data
TOOLS_DIR = tools
# Files
S_FILES = $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
# H_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
BIN_FILES = $(foreach dir,$(BIN_DIRS),$(wildcard $(dir)/*.bin))
O_FILES := $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(BIN_FILES),$(BUILD_DIR)/$(file).o)
LIBULTRA = lib/libultra_rom.a
# Language data
LANG_RNC_FILES = $(wildcard assets/lang/*.dat.rnc)
LANG_RNC_O_FILES = $(foreach file,$(LANG_RNC_FILES),$(BUILD_DIR)/$(file:.dat.rnc=.dat.rnc.o))
# Compressed Images
RGBA16_RNC_FILES = $(shell find assets/img/ -name "*.rgba16.rnc.png" 2> /dev/null)
RGBA16_RNC_O_FILES = $(foreach file,$(RGBA16_RNC_FILES),$(BUILD_DIR)/$(file:.rgba16.rnc.png=.rgba16.rnc.o))
I4_RNC_FILES = $(shell find assets/img/ -name "*.i4.rnc.png" 2> /dev/null)
I4_RNC_O_FILES = $(foreach file,$(I4_RNC_FILES),$(BUILD_DIR)/$(file:.i4.rnc.png=.i4.rnc.o))
# Uncompressed Images
RGBA16_FILES = $(shell find assets/img/ -name "*.rgba16.png" 2> /dev/null)
I4_FILES = $(shell find assets/img/ -name "*.i4.png" 2> /dev/null)
I8_FILES = $(shell find assets/img/ -name "*.i8.png" 2> /dev/null)
CI4_FILES = $(shell find assets/img/ -name "*.ci4.png" 2> /dev/null)
RGBA16_O_FILES = $(foreach file,$(RGBA16_FILES),$(BUILD_DIR)/$(file:.png=.png.o))
I4_O_FILES = $(foreach file,$(I4_FILES),$(BUILD_DIR)/$(file:.png=.png.o))
I8_O_FILES = $(foreach file,$(I8_FILES),$(BUILD_DIR)/$(file:.png=.png.o))
CI4_O_FILES = $(foreach file,$(CI4_FILES),$(BUILD_DIR)/$(file:.png=.png.o))
CI4_PAL_O_FILES = $(foreach file,$(CI4_FILES),$(BUILD_DIR)/$(file:.ci4.png=.pal.o))
# All Images
IMAGE_O_FILES = $(RGBA16_RNC_O_FILES) $(I4_RNC_O_FILES) $(RGBA16_O_FILES) $(I4_O_FILES) $(I8_O_FILES) $(CI4_O_FILES) $(CI4_PAL_O_FILES)
# Generic RNC compressed files
ALL_RNC_FILES := $(wildcard assets/rnc*.bin) $(wildcard assets/levels/*.bin)
ALL_RNC_EXTRACTED := $(foreach file,$(ALL_RNC_FILES),rnc/$(file))
ALL_RNC_COMPRESSED := $(foreach file,$(ALL_RNC_FILES),build/$(file))
RNC_FILES := $(shell find assets/ -name "*.rnc" 2> /dev/null)
RNC_O_FILES := $(foreach file,$(RNC_FILES),$(BUILD_DIR)/$(file:.rnc=.rnc.o))
# function is not included unless explicitly undefined
UNDEFINED_SYMS := osViGetCurrentLine
# Tools
CROSS = mips-linux-gnu-
AS = $(CROSS)as
CPP = cpp
LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
PYTHON = python3
GCC = gcc
XGCC = $(CROSS)gcc
GREP = grep -rl
CC = $(TOOLS_DIR)/ido5.3_recomp/cc
RNC64 = $(TOOLS_DIR)/rnc_propack_source/rnc64
RNCU = $(PYTHON) $(TOOLS_DIR)/rncu.py
SPLAT = $(TOOLS_DIR)/splat/split.py
N64CRC = $(TOOLS_DIR)/n64crc.py
IMG_CONVERT = $(PYTHON) $(TOOLS_DIR)/image_converter.py
LIBRNCU = $(TOOLS_DIR)/librncu.so
# Flags
OPT_FLAGS = -O2
LOOP_UNROLL =
MIPSISET = -mips2 -32
INCLUDE_CFLAGS = -I . -I include -I include/2.0 -I include/2.0/PR -I include/libc -I assets \
-I src.$(VERSION) -I src.$(VERSION)/libultra/audio
ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -mabi=32 -I include
OBJCOPYFLAGS = -O binary
# Files requiring pre/post-processing
GLOBAL_ASM_C_FILES := $(shell $(GREP) GLOBAL_ASM $(SRC_DIR) </dev/null 2>/dev/null)
GLOBAL_ASM_O_FILES := $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file).o)
DEFINES := -D_LANGUAGE_C -D_FINALROM -DF3DEX_GBI -DWIN32 -DSSSV -DNDEBUG
ifeq ($(VERSION),us)
DEFINES += -DVERSION_US
endif
ifeq ($(VERSION),eu)
DEFINES += -DVERSION_EU
endif
VERIFY = verify
ifeq ($(NON_MATCHING),1)
DEFINES += -DNON_MATCHING
VERIFY = no_verify
PROGRESS_NONMATCHING = --non-matching
endif
CFLAGS := -G0 -Xfullwarn -Xcpluscomm -signed -nostdinc -non_shared -Wab,-r4300_mul
CFLAGS += $(DEFINES)
# ignore compiler warnings about anonymous structs
CFLAGS += -woff 649,838
CFLAGS += $(INCLUDE_CFLAGS)
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -Wno-int-conversion
# CHECK_WARNINGS += -Wdouble-promotion
CC_CHECK := $(GCC) -fsyntax-only -fno-builtin -fsigned-char -std=gnu90 -m32 $(CHECK_WARNINGS) $(INCLUDE_CFLAGS) $(DEFINES)
GCC_FLAGS := $(INCLUDE_CFLAGS) $(DEFINES)
GCC_FLAGS += -G0 -mno-shared -march=vr4300 -mfix4300 -mabi=32 -mhard-float
GCC_FLAGS += -mdivide-breaks -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-PIC -mno-abicalls -fno-strict-aliasing -fno-inline-functions -ffreestanding -fwrapv
GCC_FLAGS += -Wall -Wextra -Wno-missing-braces
TARGET = $(BUILD_DIR)/$(BASENAME).$(VERSION)
LD_SCRIPT = $(BASENAME).ld
LD_FLAGS = -T $(LD_SCRIPT) -T undefined_syms.$(VERSION).txt -T undefined_syms_auto.txt
LD_FLAGS += -Map $(TARGET).map --no-check-sections
ifeq ($(VERSION),us)
LD_FLAGS_EXTRA = -Lbuild/lib -lultra_rom
LD_FLAGS_EXTRA += $(foreach sym,$(UNDEFINED_SYMS),-u $(sym))
else
LD_FLAGS_EXTRA =
endif
ASM_PROCESSOR_DIR := $(TOOLS_DIR)/asm-processor
ASM_PROCESSOR = $(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py
### Optimisation Overrides
$(BUILD_DIR)/$(SRC_DIR)/main_1050.c.o: OPT_FLAGS := -O1
# $(BUILD_DIR)/$(SRC_DIR)/core/eeprom.c.o: OPT_FLAGS := -O2
$(BUILD_DIR)/$(SRC_DIR)/overlay2_6AB090.c.o: LOOP_UNROLL := -Wo,-loopunroll,0
$(BUILD_DIR)/src.eu/overlay1%.c.o: OPT_FLAGS := -g
### Targets
default: all
all: dirs $(VERIFY)
dirs:
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(BIN_DIRS),$(shell mkdir -p $(BUILD_DIR)/$(dir)))
tools: $(RNC64) $(LIBRNCU)
check: .baserom.$(VERSION).ok
verify: $(TARGET).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $(TARGET).z64" | sha1sum --check
no_verify: $(TARGET).z64
@echo "Skipping SHA1SUM check, updating CRC"
@$(PYTHON) $(N64CRC) $(TARGET).z64
progress: dirs $(VERIFY) progress.csv
splat: $(SPLAT)
extract: splat check tools
$(PYTHON) $(SPLAT) $(BASENAME).$(VERSION).yaml
decompress: $(ALL_RNC_EXTRACTED)
compress: dirs $(ALL_RNC_COMPRESSED)
# DO NOT UNCOMMENT NEXT LINE UNTIL COMPRESSION IS MATCHING
#cp $(BUILD_DIR)/assets/rnc*.bin assets/
clean:
rm -rf build
distclean: clean
rm -rf asm
rm -rf assets
rm -f *auto.txt
### Recipes
.baserom.$(VERSION).ok: baserom.$(VERSION).z64
@echo "$$(cat $(BASENAME).$(VERSION).sha1) $<" | sha1sum --check
@touch $@
$(TARGET).elf: $(BASENAME).ld $(BUILD_DIR)/$(LIBULTRA) $(O_FILES) $(LANG_RNC_O_FILES) $(IMAGE_O_FILES) $(RNC_O_FILES)
@$(LD) $(LD_FLAGS) $(LD_FLAGS_EXTRA) -o $@
@printf "[$(PINK) linker $(NO_COL)] $<\n"
ifndef PERMUTER
$(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.c.o: %.c include/functions.$(VERSION).h include/variables.$(VERSION).h include/structs.h
@$(CC_CHECK) $<
@printf "[$(YELLOW) syntax $(NO_COL)] $<\n"
@$(ASM_PROCESSOR) $(OPT_FLAGS) $< > $(BUILD_DIR)/$<
@$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(LOOP_UNROLL) $(MIPSISET) -o $@ $(BUILD_DIR)/$<
@$(ASM_PROCESSOR) $(OPT_FLAGS) $< --post-process $@ \
--assembler "$(AS) $(ASFLAGS)" --asm-prelude $(ASM_PROCESSOR_DIR)/prelude.inc
@printf "[$(GREEN) ido5.3 $(NO_COL)] $<\n"
endif
# non asm-processor recipe
$(BUILD_DIR)/%.c.o: %.c
@$(CC_CHECK) $<
@printf "[$(YELLOW) syntax $(NO_COL)] $<\n"
@$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(LOOP_UNROLL) $(MIPSISET) -o $@ $<
@printf "[$(GREEN) ido5.3 $(NO_COL)] $<\n"
# use modern gcc for data
$(BUILD_DIR)/$(SRC_DIR)/data/%.c.o: $(SRC_DIR)/data/%.c
@$(XGCC) -c $(GCC_FLAGS) -o $@ $<
@printf "[$(GREEN) newgcc $(NO_COL)] $<\n"
$(BUILD_DIR)/%.s.o: %.s
@$(AS) $(ASFLAGS) -o $@ $<
@printf "[$(GREEN) as $(NO_COL)] $<\n"
$(BUILD_DIR)/%.bin.o: %.bin
@$(LD) -r -b binary -o $@ $<
@printf "[$(PINK) linker $(NO_COL)] $<\n"
$(TARGET).bin: $(TARGET).elf
@$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
@printf "[$(CYAN) objcpy $(NO_COL)] $<\n"
$(TARGET).z64: $(TARGET).bin
@cp $< $@
$(BUILD_DIR)/$(LIBULTRA): $(LIBULTRA)
@mkdir -p $$(dirname $@)
@cp $< $@
@$(PYTHON) $(TOOLS_DIR)/set_o32abi_bit.py --quiet $@
rnc/%.bin: %.bin
@mkdir -p rnc/assets/levels
@$(RNCU) $< $@
@printf "[$(RED) rnc u. $(NO_COL)] $<\n"
$(RNC64): $(TOOLS_DIR)/rnc_propack_source/main.c
make -C $(TOOLS_DIR)/rnc_propack_source rnc64
$(LIBRNCU): $(TOOLS_DIR)/rncu.c
$(GCC) -o $@ $< --shared -O3 -fPIC
# language files
%.dat.rnc.json: %.dat.rnc
@mkdir -p $$(dirname $@)
@$(PYTHON) $(TOOLS_DIR)/lang2json.py $< $@
@printf "[$(YELLOW) lang $(NO_COL)] $<\n"
$(BUILD_DIR)/%.dat: %.dat.rnc.json
@mkdir -p $$(dirname $@)
@$(PYTHON) $(TOOLS_DIR)/lang2json.py $< $@ --encode
@printf "[$(RED2) lang $(NO_COL)] $<\n"
# compressed images
$(BUILD_DIR)/%.rgba16: %.rgba16.rnc.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) rgba16 $< $@
@printf "[$(GREEN) rgba16 $(NO_COL)] $<\n"
$(BUILD_DIR)/%.i4: %.i4.rnc.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) i4 $< $@
@printf "[$(GREEN) i4 $(NO_COL)] $<\n"
# uncompressed images
$(BUILD_DIR)/%.rgba16.png: %.rgba16.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) rgba16 $< $@
@printf "[$(GREEN) rgba16 $(NO_COL)] $<\n"
$(BUILD_DIR)/%.i4.png: %.i4.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) i4 $< $@
@printf "[$(GREEN) i4 $(NO_COL)] $<\n"
$(BUILD_DIR)/%.i8.png: %.i8.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) i8 $< $@
@printf "[$(GREEN) i8 $(NO_COL)] $<\n"
$(BUILD_DIR)/%.ci4.png: %.ci4.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) ci4 $< $@
@printf "[$(GREEN) ci4 $(NO_COL)] $<\n"
$(BUILD_DIR)/%.pal: %.ci4.png
@mkdir -p $$(dirname $@)
@$(IMG_CONVERT) palette $< $@
@printf "[$(GREEN) pal $(NO_COL)] $<\n"
# BUILD_DIR prefix to suppress circular dependency
$(BUILD_DIR)/%.png.o: $(BUILD_DIR)/%.png
@$(LD) -r -b binary -o $@ $<
@printf "[$(PINK) linker $(NO_COL)] $<\n"
$(BUILD_DIR)/%.pal.o: $(BUILD_DIR)/%.pal
@$(LD) -r -b binary -o $@ $<
@printf "[$(PINK) linker $(NO_COL)] $<\n"
# rnc compress
%.rnc: %
@$(RNC64) p $< $@ /f >/dev/null
@$(PYTHON) $(TOOLS_DIR)/pad.py $@ $@.pad
@mv $@.pad $@
@printf "[$(RED) rnc p. $(NO_COL)] $<\n"
$(BUILD_DIR)/%.collision.rnc: %.collision.rnc
@$(RNC64) p $< $@ /f >/dev/null
@$(PYTHON) $(TOOLS_DIR)/pad.py $@ $@.pad
@mv $@.pad $@
@printf "[$(RED) rnc p. $(NO_COL)] $<\n"
%.rnc.o: %.rnc
@$(LD) -r -b binary -o $@ $<
@printf "[$(PINK) linker $(NO_COL)] $<\n"
# progress
progress.csv: progress.main.csv progress.lib.csv progress.overlay1.csv progress.overlay2.csv
@awk "(NR == 1) || (FNR > 1)" $^ > $@
@rm $^
progress.main.csv: $(TARGET).elf
$(PYTHON) $(TOOLS_DIR)/progress.py . $(TARGET).map main_TEXT_START main_libultra_start_OFFSET main --version $(VERSION) $(PROGRESS_NONMATCHING) > $@
progress.lib.csv: $(TARGET).elf
$(PYTHON) $(TOOLS_DIR)/progress.py . $(TARGET).map main_libultra_start_OFFSET main_TEXT_END lib --version $(VERSION) $(PROGRESS_NONMATCHING) > $@
progress.overlay1.csv: $(TARGET).elf
$(PYTHON) $(TOOLS_DIR)/progress.py . $(TARGET).map overlay1_TEXT_START overlay1_TEXT_END overlay1 --version $(VERSION) $(PROGRESS_NONMATCHING) > $@
progress.overlay2.csv: $(TARGET).elf
$(PYTHON) $(TOOLS_DIR)/progress.py . $(TARGET).map overlay2_TEXT_START overlay2_TEXT_END overlay2 --version $(VERSION) $(PROGRESS_NONMATCHING) > $@
# fake targets for better error handling
$(SPLAT):
$(info Repo cloned without submodules, attempting to fetch them now...)
@which git >/dev/null || echo "ERROR: git binary not found on PATH"
@which git >/dev/null
git submodule update --init --recursive
baserom.$(VERSION).z64:
$(error Place the SSSV ROM, named '$@', in the root of this repo and try again.)
### Settings
.SECONDARY:
.PHONY: all clean default
SHELL = /bin/bash -e -o pipefail