forked from ethteck/pokemonstadium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
107 lines (76 loc) · 2.83 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
BASEROM = baserom.z64
TARGET = pokemonstadium
NON_MATCHING = 0
# Fail early if baserom does not exist
ifeq ($(wildcard $(BASEROM)),)
$(error Baserom `$(BASEROM)' not found.)
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/os
DATA_DIRS := bin
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=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
$(foreach file,$(DATA_FILES),$(BUILD_DIR)/$(file:.bin=.o)) \
SPLAT_YAML := splat.yaml
SPLAT = $(PYTHON) tools/n64splat/split.py $(BASEROM) $(SPLAT_YAML) .
##################### Compiler Options #######################
CROSS = mips-linux-gnu-
AS = $(CROSS)as
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
CPP := cpp
#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/linux/7.1/cc
CC_OLD = tools/ido_recomp/linux/5.3/cc
ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -Iinclude
CFLAGS = -G 0 -non_shared -Xfullwarn -Xcpluscomm -Iinclude -Wab,-r4300_mul -D _LANGUAGE_C
LDFLAGS = -T undefined_syms.txt -T undefined_funcs.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/$(TARGET).map --no-check-sections
OPTFLAGS := -O2
######################## Targets #############################
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(DATA_DIRS) $(COMPRESSED_DIRS) $(MAP_DIRS) $(BGM_DIRS),$(shell mkdir -p build/$(dir)))
build/src/os/O1/%.o: OPTFLAGS := -O1
default: all
LD_SCRIPT = $(TARGET).ld
all: $(BUILD_DIR) $(TARGET).z64 verify
clean:
rm -rf $(BUILD_DIR) $(TARGET).z64
submodules:
git submodule update --init --recursive
split:
rm -rf $(DATA_DIRS) $(ASM_DIRS) && ./tools/n64splat/split.py baserom.z64 $(SPLAT_YAML) .
setup: clean 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)/%.o: %.c
$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $^
$(BUILD_DIR)/%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.bin
$(LD) -r -b binary -o $@ $<
$(LD_SCRIPT): $(SPLAT_YAML)
$(SPLAT) --modes ld
# final z64 updates checksum
$(TARGET).z64: $(BUILD_DIR)/$(TARGET).bin
@cp $< $@
verify: $(TARGET).z64
md5sum -c checksum.md5
.PHONY: all clean default split setup