2018-10-26 02:29:41 +00:00
|
|
|
# TODO think about how to split this up
|
|
|
|
|
2020-01-25 06:22:56 +00:00
|
|
|
AS := $(MIPS_BINUTILS_PREFIX)as
|
|
|
|
LD := $(MIPS_BINUTILS_PREFIX)ld
|
2018-10-26 02:29:41 +00:00
|
|
|
|
2019-12-16 05:06:39 +00:00
|
|
|
IRIX_71_ROOT := ./tools/ido7.1_compiler/
|
|
|
|
IRIX_53_ROOT := ./tools/ido5.3_compiler/
|
2018-10-26 02:29:41 +00:00
|
|
|
|
|
|
|
CFLAGS := -G 0 -non_shared -Xfullwarn -Xcpluscomm
|
2018-11-14 04:10:59 +00:00
|
|
|
ASFLAGS := -march=vr4300 -32
|
2018-10-26 02:29:41 +00:00
|
|
|
|
|
|
|
MIPS_VERSION := -mips2
|
|
|
|
OPTIMIZATION := -O2 -g3
|
|
|
|
|
|
|
|
build/src/libultra/os/%: OPTIMIZATION := -O1
|
|
|
|
build/src/libultra/io/%: OPTIMIZATION := -O2
|
|
|
|
build/src/libultra/libc/%: OPTIMIZATION := -O2
|
2020-01-21 05:26:49 +00:00
|
|
|
build/src/libultra/libc/ll%: OPTIMIZATION := -O1
|
|
|
|
build/src/libultra/libc/ll%: MIPS_VERSION := -mips3 -32
|
2018-11-17 08:16:20 +00:00
|
|
|
build/src/libultra/gu/%: OPTIMIZATION := -O2
|
2020-01-21 05:26:49 +00:00
|
|
|
build/src/libultra/rmon/%: OPTIMIZATION := -O2
|
2018-11-17 08:16:20 +00:00
|
|
|
build/src/libultra/%: CC := $(QEMU_IRIX) -L $(IRIX_53_ROOT) $(IRIX_53_ROOT)/usr/bin/cc
|
|
|
|
build/src/libultra/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
2018-11-14 04:10:59 +00:00
|
|
|
build/src/boot_O1/%: OPTIMIZATION := -O1
|
2020-01-13 02:18:31 +00:00
|
|
|
build/src/boot_O2/%: OPTIMIZATION := -O2
|
2018-10-29 04:12:21 +00:00
|
|
|
build/src/boot_O2_g3/%: OPTIMIZATION := -O2 -g3
|
2020-01-12 22:52:32 +00:00
|
|
|
build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3
|
2019-03-07 03:48:32 +00:00
|
|
|
build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
2019-12-28 02:55:17 +00:00
|
|
|
build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
2020-01-12 22:52:32 +00:00
|
|
|
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
|
2020-01-21 07:45:43 +00:00
|
|
|
test.txt: OPTIMIZATION := -O2 -g3
|
|
|
|
test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
|
2020-01-13 02:18:31 +00:00
|
|
|
test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
|
2018-11-17 08:16:20 +00:00
|
|
|
|
2018-12-06 19:47:07 +00:00
|
|
|
CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
|
2018-10-26 02:29:41 +00:00
|
|
|
|
2019-12-16 05:06:39 +00:00
|
|
|
test.txt: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2020-01-13 02:18:31 +00:00
|
|
|
build/src/boot_O2/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2019-12-16 05:06:39 +00:00
|
|
|
build/src/boot_O2_g3/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2020-01-12 22:52:32 +00:00
|
|
|
build/src/boot_O2_g3_trapuv/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2019-12-16 05:06:39 +00:00
|
|
|
build/src/code/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2019-12-28 02:55:17 +00:00
|
|
|
build/src/actors/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
|
2018-11-14 04:10:59 +00:00
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
BASEROM_FILES := $(wildcard baserom/*)
|
2019-04-12 02:12:49 +00:00
|
|
|
# Exclude dmadata, it will be generated right before packing the rom
|
|
|
|
BASEROM_FILES := $(subst baserom/dmadata ,,$(BASEROM_FILES))
|
|
|
|
BASEROM_BUILD_FILES := $(BASEROM_FILES:baserom/%=build/baserom/%)
|
2019-11-16 09:28:05 +00:00
|
|
|
BASEROM_PRE_DMADATA_FILES := $(BASEROM_BUILD_FILES:build/baserom/%=build/baserom_pre_dmadata/%)
|
2019-04-12 02:12:49 +00:00
|
|
|
|
2019-11-13 04:58:52 +00:00
|
|
|
BASE_DECOMP_FILES := $(wildcard decomp/*)
|
|
|
|
DECOMP_FILES := $(BASE_DECOMP_FILES:decomp/%=build/decomp/%)
|
2019-11-16 09:28:05 +00:00
|
|
|
DECOMP_PRE_DMADATA_FILES := $(DECOMP_FILES:build/decomp/%=build/decomp_pre_dmadata/%)
|
|
|
|
COMP_FILES := $(DECOMP_FILES:build/decomp/%=build/comp/%.yaz0)
|
2019-04-12 02:12:49 +00:00
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
S_FILES := $(wildcard asm/*)
|
|
|
|
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
|
2018-11-14 04:10:59 +00:00
|
|
|
C_FILES := $(wildcard src/libultra/*) \
|
2018-10-29 04:12:21 +00:00
|
|
|
$(wildcard src/libultra/os/*) \
|
|
|
|
$(wildcard src/libultra/io/*) \
|
|
|
|
$(wildcard src/libultra/libc/*) \
|
2018-11-17 08:16:20 +00:00
|
|
|
$(wildcard src/libultra/gu/*) \
|
2020-01-21 05:26:49 +00:00
|
|
|
$(wildcard src/libultra/rmon/*) \
|
2018-10-29 04:12:21 +00:00
|
|
|
$(wildcard src/code/*) \
|
2020-01-13 02:18:31 +00:00
|
|
|
$(wildcard src/boot_O2/*) \
|
2018-11-14 04:10:59 +00:00
|
|
|
$(wildcard src/boot_O2_g3/*) \
|
2020-01-12 22:52:32 +00:00
|
|
|
$(wildcard src/boot_O2_g3_trapuv/*) \
|
2019-12-28 02:55:17 +00:00
|
|
|
$(wildcard src/boot_O1/*) \
|
2019-12-28 08:23:17 +00:00
|
|
|
$(wildcard src/actors/Bg_Fu_Kaiten/*) \
|
|
|
|
$(wildcard src/actors/Bg_Ikana_Ray/*)
|
2018-10-26 02:29:41 +00:00
|
|
|
C_O_FILES = $(C_FILES:src/%.c=build/src/%.o)
|
2019-09-22 08:11:22 +00:00
|
|
|
ROM_FILES := $(shell cat ./tables/makerom_files.txt)
|
2018-10-28 08:32:16 +00:00
|
|
|
|
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
ROM := rom.z64
|
|
|
|
|
2019-12-28 02:55:17 +00:00
|
|
|
BUILD_DIR := ./build
|
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
# make build directories
|
2019-12-28 02:55:17 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/asm)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/baserom)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/baserom_pre_dmadata)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/comp)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/decomp)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/decomp_pre_dmadata)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra/os)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra/io)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra/libc)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra/gu)
|
2020-01-21 05:26:49 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/libultra/rmon)
|
2019-12-28 02:55:17 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/code)
|
2020-01-13 02:18:31 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2)
|
2019-12-28 02:55:17 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2_g3)
|
2020-01-12 22:52:32 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2_g3_trapuv)
|
2019-12-28 02:55:17 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/boot_O1)
|
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/actors/Bg_Fu_Kaiten)
|
2019-12-28 08:23:17 +00:00
|
|
|
$(shell mkdir -p $(BUILD_DIR)/src/actors/Bg_Ikana_Ray)
|
2018-10-26 02:29:41 +00:00
|
|
|
|
2019-04-16 02:01:57 +00:00
|
|
|
check: $(ROM)
|
2018-10-26 02:29:41 +00:00
|
|
|
@md5sum -c checksum.md5
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2019-04-11 04:58:55 +00:00
|
|
|
$(ROM): $(ROM_FILES)
|
2020-02-19 20:08:04 +00:00
|
|
|
@./tools/makerom.py ./tables/dmadata_table.txt $@
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2019-12-28 08:23:17 +00:00
|
|
|
build/%_pre_dmadata.bin: build/code_pre_dmadata.elf
|
2020-01-25 06:22:56 +00:00
|
|
|
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section $*=$@ $<
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2019-12-28 08:23:17 +00:00
|
|
|
build/%.bin: build/code.elf
|
2020-01-25 06:22:56 +00:00
|
|
|
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section $*=$@ $<
|
2019-12-28 02:55:17 +00:00
|
|
|
|
2019-11-28 06:26:09 +00:00
|
|
|
build/code_pre_dmadata.elf: $(S_O_FILES) $(C_O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt
|
|
|
|
$(LD) -r -T linker_scripts/code_script.txt -T undef.txt -T linker_scripts/object_script.txt --no-check-sections --accept-unknown-input-arch -o $@
|
2019-11-16 09:28:05 +00:00
|
|
|
|
2019-11-28 06:26:09 +00:00
|
|
|
build/code.elf: $(S_O_FILES) $(C_O_FILES) linker_scripts/code_script.txt undef.txt linker_scripts/object_script.txt linker_scripts/dmadata_script.txt
|
2019-12-20 07:50:43 +00:00
|
|
|
$(LD) -T linker_scripts/code_script.txt -T undef.txt -T linker_scripts/object_script.txt -T linker_scripts/dmadata_script.txt --no-check-sections --accept-unknown-input-arch -Map build/mm.map -o $@
|
2019-11-16 09:28:05 +00:00
|
|
|
|
2019-11-28 06:26:09 +00:00
|
|
|
linker_scripts/dmadata_script.txt: $(DECOMP_PRE_DMADATA_FILES) $(BASEROM_PRE_DMADATA_FILES)
|
2019-11-16 09:28:05 +00:00
|
|
|
# TODO is there a better way to avoid this shuffling?
|
|
|
|
mv build/baserom build/baserom_temp
|
|
|
|
mv build/decomp build/decomp_temp
|
|
|
|
mv build/baserom_pre_dmadata build/baserom
|
|
|
|
mv build/decomp_pre_dmadata build/decomp
|
2020-02-19 20:08:04 +00:00
|
|
|
./tools/dmadata.py ./tables/dmadata_table.txt /dev/null -u -l linker_scripts/dmadata_script.txt
|
2019-11-16 09:28:05 +00:00
|
|
|
mv build/baserom build/baserom_pre_dmadata
|
|
|
|
mv build/decomp build/decomp_pre_dmadata
|
|
|
|
mv build/baserom_temp build/baserom
|
|
|
|
mv build/decomp_temp build/decomp
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
test.txt: build/src/test.o
|
2020-01-25 06:22:56 +00:00
|
|
|
$(MIPS_BINUTILS_PREFIX)objdump -d -z --adjust-vma=0x80080790 $< > test.txt
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
clean:
|
2019-11-16 09:28:05 +00:00
|
|
|
rm $(ROM) -r build
|
2018-10-26 02:29:41 +00:00
|
|
|
|
2019-11-13 04:58:52 +00:00
|
|
|
build/baserom/dmadata: $(COMP_FILES) $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
|
2020-02-19 20:08:04 +00:00
|
|
|
./tools/dmadata.py ./tables/dmadata_table.txt $@
|
2019-04-12 02:12:49 +00:00
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/baserom/boot: build/boot.bin
|
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
build/decomp/code: build/code.bin
|
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
build/decomp/ovl_title: build/ovl_title.bin
|
|
|
|
cp $< $@
|
|
|
|
|
2019-12-28 02:55:17 +00:00
|
|
|
build/decomp/ovl_Bg_Fu_Kaiten: build/ovl_Bg_Fu_Kaiten.bin
|
|
|
|
cp $< $@
|
|
|
|
|
2019-12-28 08:23:17 +00:00
|
|
|
build/decomp/ovl_Bg_Ikana_Ray: build/ovl_Bg_Ikana_Ray.bin
|
|
|
|
cp $< $@
|
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/baserom_pre_dmadata/boot: build/boot_pre_dmadata.bin
|
2019-04-12 05:09:21 +00:00
|
|
|
cp $< $@
|
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/decomp_pre_dmadata/code: build/code_pre_dmadata.bin
|
2019-11-13 04:58:52 +00:00
|
|
|
cp $< $@
|
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/decomp_pre_dmadata/ovl_title: build/ovl_title_pre_dmadata.bin
|
2019-11-13 04:58:52 +00:00
|
|
|
cp $< $@
|
|
|
|
|
2019-12-28 02:55:17 +00:00
|
|
|
build/decomp_pre_dmadata/ovl_Bg_Fu_Kaiten: build/ovl_Bg_Fu_Kaiten_pre_dmadata.bin
|
|
|
|
cp $< $@
|
|
|
|
|
2019-12-28 08:23:17 +00:00
|
|
|
build/decomp_pre_dmadata/ovl_Bg_Ikana_Ray: build/ovl_Bg_Ikana_Ray_pre_dmadata.bin
|
|
|
|
cp $< $@
|
|
|
|
|
2019-04-12 05:09:21 +00:00
|
|
|
|
2019-09-21 01:47:01 +00:00
|
|
|
disasm:
|
2020-02-19 20:08:04 +00:00
|
|
|
@./tools/disasm.py -d ./asm -u . -l ./tables/files.txt -f ./tables/functions.txt -o ./tables/objects.txt -v ./tables/variables.txt -v ./tables/vrom_variables.txt -v ./tables/pre_boot_variables.txt
|
2019-09-21 01:47:01 +00:00
|
|
|
@while read -r file; do \
|
2020-02-20 22:29:22 +00:00
|
|
|
./tools/split_asm.py ./asm/$$file.asm ./asm/non_matchings/$$file; \
|
2019-09-21 01:47:01 +00:00
|
|
|
done < ./tables/files_with_nonmatching.txt
|
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
# Recipes
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/baserom/%: build/baserom_pre_dmadata/%
|
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
build/baserom_pre_dmadata/%: baserom/%
|
2019-04-11 04:58:55 +00:00
|
|
|
cp $< $@
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
build/asm/%.o: asm/%.asm
|
2018-11-14 04:10:59 +00:00
|
|
|
$(AS) $(ASFLAGS) $^ -o $@
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2019-12-28 08:23:17 +00:00
|
|
|
build/src/actors/%.o: src/actors/%.c include/*
|
|
|
|
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
|
|
|
./tools/overlay.py $@ build/src/actors/$*_overlay.s
|
|
|
|
$(AS) $(ASFLAGS) build/src/actors/$*_overlay.s -o build/src/actors/$*_overlay.o
|
|
|
|
|
2018-10-26 02:29:41 +00:00
|
|
|
build/src/%.o: src/%.c include/*
|
2018-11-14 04:10:59 +00:00
|
|
|
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
2018-10-28 08:32:16 +00:00
|
|
|
|
2020-01-21 05:26:49 +00:00
|
|
|
build/src/libultra/libc/ll.o: src/libultra/libc/ll.c include/*
|
|
|
|
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
|
|
|
./tools/set_o32abi_bit.py $@
|
|
|
|
|
|
|
|
build/src/libultra/libc/llcvt.o: src/libultra/libc/llcvt.c include/*
|
|
|
|
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
|
|
|
|
./tools/set_o32abi_bit.py $@
|
|
|
|
|
2019-11-16 09:28:05 +00:00
|
|
|
build/decomp/%: build/decomp_pre_dmadata/%
|
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
build/decomp_pre_dmadata/%: decomp/%
|
2019-11-13 04:58:52 +00:00
|
|
|
cp $< $@
|
|
|
|
|
|
|
|
build/comp/%.yaz0: build/decomp/%
|
2019-12-16 05:06:39 +00:00
|
|
|
./tools/yaz0.py $< $@
|
2019-04-11 04:58:55 +00:00
|
|
|
|