This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
174 lines (135 loc) · 6.73 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
# TODO think about how to split this up
AS := $(MIPS_BINUTILS_PREFIX)as
LD := $(MIPS_BINUTILS_PREFIX)ld
IRIX_71_ROOT := ./tools/ido7.1_compiler/
IRIX_53_ROOT := ./tools/ido5.3_compiler/
CFLAGS := -G 0 -non_shared -Xfullwarn -Xcpluscomm
ASFLAGS := -march=vr4300 -32
MIPS_VERSION := -mips2
OPTIMIZATION := -O2 -g3
build/src/libultra/os/%: OPTIMIZATION := -O1
build/src/libultra/io/%: OPTIMIZATION := -O2
build/src/libultra/libc/%: OPTIMIZATION := -O2
build/src/libultra/libc/ll%: OPTIMIZATION := -O1
build/src/libultra/libc/ll%: MIPS_VERSION := -mips3 -32
build/src/libultra/gu/%: OPTIMIZATION := -O2
build/src/libultra/rmon/%: OPTIMIZATION := -O2
build/src/libultra/%: CC := $(QEMU_IRIX) -L $(IRIX_53_ROOT) $(IRIX_53_ROOT)/usr/bin/cc
build/src/libultra/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/boot_O1/%: OPTIMIZATION := -O1
build/src/boot_O2/%: OPTIMIZATION := -O2
build/src/boot_O2_g3/%: OPTIMIZATION := -O2 -g3
build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3
build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
test.txt: OPTIMIZATION := -O2 -g3
test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
test.txt: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2_g3/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2_g3_trapuv/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/code/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/actors/%: CC := ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
BASEROM_FILES := $(wildcard baserom/*)
# 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/%)
BASE_DECOMP_FILES := $(wildcard decomp/*)
DECOMP_FILES := $(BASE_DECOMP_FILES:decomp/%=build/decomp/%)
COMP_FILES := $(DECOMP_FILES:build/decomp/%=build/comp/%.yaz0)
DMADATA_FILES := $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
# Exclude code files, they will be extracted from the file instead
DMADATA_FILES := $(subst build/baserom/boot ,,$(DMADATA_FILES))
DMADATA_FILES := $(subst build/decomp/code ,,$(DMADATA_FILES))
DMADATA_FILES := $(DMADATA_FILES:build/decomp/ovl_%=)
S_FILES := $(wildcard asm/*)
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
C_FILES := $(wildcard src/libultra/*) \
$(wildcard src/libultra/os/*) \
$(wildcard src/libultra/io/*) \
$(wildcard src/libultra/libc/*) \
$(wildcard src/libultra/gu/*) \
$(wildcard src/libultra/rmon/*) \
$(wildcard src/code/*) \
$(wildcard src/boot_O2/*) \
$(wildcard src/boot_O2_g3/*) \
$(wildcard src/boot_O2_g3_trapuv/*) \
$(wildcard src/boot_O1/*) \
$(wildcard src/actors/Bg_Fu_Kaiten/*) \
$(wildcard src/actors/Bg_Ikana_Ray/*)
C_O_FILES = $(C_FILES:src/%.c=build/src/%.o)
ROM_FILES := $(shell cat ./tables/makerom_files.txt)
ROM := rom.z64
BUILD_DIR := ./build
# make build directories
$(shell mkdir -p $(BUILD_DIR)/asm)
$(shell mkdir -p $(BUILD_DIR)/baserom)
$(shell mkdir -p $(BUILD_DIR)/comp)
$(shell mkdir -p $(BUILD_DIR)/decomp)
$(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)
$(shell mkdir -p $(BUILD_DIR)/src/libultra/rmon)
$(shell mkdir -p $(BUILD_DIR)/src/code)
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2)
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2_g3)
$(shell mkdir -p $(BUILD_DIR)/src/boot_O2_g3_trapuv)
$(shell mkdir -p $(BUILD_DIR)/src/boot_O1)
$(shell mkdir -p $(BUILD_DIR)/src/actors/Bg_Fu_Kaiten)
$(shell mkdir -p $(BUILD_DIR)/src/actors/Bg_Ikana_Ray)
check: $(ROM)
@md5sum -c checksum.md5
$(ROM): $(ROM_FILES)
@./tools/makerom.py ./tables/dmadata_table.txt $@
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 -N -o $@
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
$(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 -N -o $@
linker_scripts/dmadata_script.txt: $(DMADATA_FILES) build/code_pre_dmadata.elf
./tools/dmadata.py ./tables/dmadata_table.txt /dev/null -u -l linker_scripts/dmadata_script.txt -e build/code_pre_dmadata.elf
test.txt: build/src/test.o
$(MIPS_BINUTILS_PREFIX)objdump -d -z --adjust-vma=0x80080790 $< > test.txt
clean:
rm $(ROM) -r build
build/baserom/dmadata: $(COMP_FILES) $(DECOMP_FILES) $(BASEROM_BUILD_FILES)
./tools/dmadata.py ./tables/dmadata_table.txt $@
build/baserom/boot: build/boot.bin
cp $< $@
build/decomp/code: build/code.bin
cp $< $@
build/decomp/ovl_%: build/code.elf
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section ovl_$*=$@ $< /dev/null
disasm:
@./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
@while read -r file; do \
./tools/split_asm.py ./asm/$$file.asm ./asm/non_matchings/$$file; \
done < ./tables/files_with_nonmatching.txt
# Recipes
build/%.bin: build/code.elf
$(MIPS_BINUTILS_PREFIX)objcopy --dump-section $*=$@ $< /dev/null
build/baserom/%: baserom/%
cp $< $@
build/asm/%.o: asm/%.asm
$(AS) $(ASFLAGS) $^ -o $@
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
build/src/%.o: src/%.c include/*
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
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 $@
build/decomp/%: decomp/%
cp $< $@
build/comp/%.yaz0: build/decomp/%
./tools/yaz0.py $< $@