-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
188 lines (137 loc) · 5.21 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
BASEROM = baserom.z64
TARGET = pokestadiumgs
NON_MATCHING ?= 0
RUN_CC_CHECK ?= 1
WERROR ?= 0
# Fail early if baserom does not exist
ifeq ($(wildcard $(BASEROM)),)
$(error Baserom `$(BASEROM)' not found.)
endif
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
HOST_OS := linux
else ifeq ($(UNAME_S),Darwin)
HOST_OS := macos
else
$(error Unsupported host/building OS <$(UNAME_S)>)
endif
BUILD_DIR := build
ROM := $(TARGET).z64
ELF := $(BUILD_DIR)/$(TARGET).elf
LD_SCRIPT := $(TARGET).ld
LD_MAP := $(BUILD_DIR)/$(TARGET).map
ASM_DIRS := asm asm/data asm/lib/libc asm/lib/libultra
DATA_DIRS := bin assets
SRC_DIRS := $(shell find src -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
DATA_FILES := $(foreach dir,$(DATA_DIRS),$(wildcard $(dir)/*.bin))
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.c.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.s.o)) \
$(foreach file,$(DATA_FILES),$(BUILD_DIR)/$(file:.bin=.bin.o)) \
DECOMP_C_OBJS := $(filter %.c.o,$(filter-out $(BUILD_DIR)/src/libultra%,$(O_FILES)))
DEP_FILES := $(O_FILES:.o=.d) $(DECOMP_C_OBJS:.o=.asmproc.d)
SPLAT_YAML := pokestadiumgs.yaml
SPLAT = $(PYTHON) tools/splat/split.py $(SPLAT_YAML)
##################### Compiler Options #######################
findcmd = $(shell type $(1) >/dev/null 2>/dev/null; echo $$?)
ifeq ($(call findcmd,mips-linux-gnu-ld),0)
CROSS := mips-linux-gnu-
else ifeq ($(call findcmd,mips64-elf-ld),0)
CROSS := mips64-elf-
else
$(error Missing cross compilation toolchain)
endif
AS = $(CROSS)as
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
ifeq ($(HOST_OS),macos)
CPP := clang -E -P -x c
else
CPP := cpp
endif
#CC := $(QEMU_IRIX) -L tools/ido7.1_compiler tools/ido7.1_compiler/usr/bin/cc
#CC_OLD := $(QEMU_IRIX) -L tools/ido5.3_compiler tools/ido5.3_compiler/usr/bin/cc
CC = tools/ido_recomp/$(HOST_OS)/7.1/cc
CC_OLD = tools/ido_recomp/$(HOST_OS)/5.3/cc
ASMPROC = python3 tools/asmproc/build.py
ASMPROC_FLAGS :=
MIPS_VERSION := -mips2
OPTFLAGS := -O2
OBJDUMP_FLAGS := -d -r -z -Mreg-names=32
# include locations
INC_DIRS := include include/PR include/audio .
IINCS := $(foreach d,$(INC_DIRS),-I$d)
# defines for SGI IDO
CDEFS := -D_LANGUAGE_C -DF3DEX_GBI_2 -DNDEBUG
ifneq ($(RUN_CC_CHECK),0)
CHECK_WARNINGS := -Wall -Wextra
CHECK_DEFS := -D_MIPS_SZLONG=32 -DNON_MATCHING
CHECK_FLAGS := -fno-builtin -funsigned-char -fdiagnostics-color -std=gnu89 $(CDEFS) $(CHECK_DEFS) $(IINCS) -nostdinc
CC_CHECK := gcc -fsyntax-only
ifeq ($(HOST_OS),linux)
CC_CHECK += -m32
endif
ifneq ($(WERROR),0)
CHECK_WARNINGS += -Werror
endif
else
CC_CHECK := @:
endif
######################## Flags #############################
ASFLAGS = -EB -mtune=vr4300 -march=vr4300 $(IINCS) -32
# 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 -Xfullwarn -Xcpluscomm $(IINCS) -Wab,-r4300_mul $(CDEFS) -woff 649,838,712,807 $(MIPS_VERSION)
LDFLAGS = -T undefined_syms.txt -T undefined_funcs.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/$(TARGET).map --no-check-sections
######################## Targets #############################
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(DATA_DIRS) $(COMPRESSED_DIRS) $(MAP_DIRS) $(BGM_DIRS),$(shell mkdir -p build/$(dir)))
# run ASM-processor on non-libultra source files
$(DECOMP_C_OBJS): CC := $(ASMPROC) $(ASMPROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) --
######################## Build #############################
default: all
LD_SCRIPT = $(TARGET).ld
all: $(BUILD_DIR) $(BUILD_DIR)/$(ROM) verify
distclean:
rm -rf asm bin assets $(BUILD_DIR) undefined_syms_auto.txt undefined_funcs_auto.txt
clean:
rm -rf $(BUILD_DIR)
submodules:
git submodule update --init --recursive
split:
rm -rf $(DATA_DIRS) $(ASM_DIRS) && ./tools/splat/split.py $(SPLAT_YAML)
setup: distclean submodules split
$(BUILD_DIR):
echo $(C_FILES)
mkdir $(BUILD_DIR)
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
@mkdir -p $(shell dirname $@)
$(CPP) -P -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
$(OBJCOPY) $< $@ -O binary
$(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT)
@$(LD) $(LDFLAGS) -o $@
$(BUILD_DIR)/%.c.o: %.c
$(CC_CHECK) $(CHECK_FLAGS) $(CHECK_WARNINGS) -MMD -MP -MT $@ -MF $(@:.o=.d) $<
$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $<
$(BUILD_DIR)/src/libultra/libc/ll.c.o: src/libultra/libc/ll.c
$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $<
python3 tools/set_o32abi_bit.py $@
@$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s)
$(BUILD_DIR)/src/libultra/libc/llcvt.c.o: src/libultra/libc/llcvt.c
$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $<
python3 tools/set_o32abi_bit.py $@
@$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s)
$(BUILD_DIR)/%.s.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.bin.o: %.bin
$(LD) -r -b binary -o $@ $<
# final z64 updates checksum
$(BUILD_DIR)/$(ROM): $(BUILD_DIR)/$(TARGET).bin
@cp $< $@
verify: $(BUILD_DIR)/$(ROM)
md5sum -c checksum.md5
.PHONY: all clean distclean default split setup
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
-include $(DEP_FILES)