-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
128 lines (95 loc) · 3.65 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
BASENAME = mischiefmakers
BUILD_DIR = build
ASM_DIRS = asm asm/os asm/io asm/audio asm/rmon asm/libc asm/host asm/logger asm/gu asm/sp asm/eeprom asm/pi asm/ai asm/error asm/si asm/rsp\
asm/data asm/data/os asm/data/io asm/data/audio asm/data/rmon asm/data/libc asm/data/host asm/data/logger asm/data/gu asm/data/sp
BIN_DIRS = assets
SRC_DIR = src
SRC_DIRS = $(SRC_DIR)
TOOLS_DIR := tools
S_FILES = $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
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)
TARGET = $(BUILD_DIR)/$(BASENAME)
LD_SCRIPT = $(BASENAME).ld
CROSS = mips-linux-gnu-
AS = $(CROSS)as
CPP = cpp
LD = $(CROSS)ld
OBJDUMP = $(CROSS)objdump
OBJCOPY = $(CROSS)objcopy
PYTHON = python3
N64CRC = tools/n64crc
OBJCOPYFLAGS = -O binary
CC := $(TOOLS_DIR)/ido_recomp/linux/5.3/cc
OPT_FLAGS := -O2
MIPSISET := -mips1 -o32
INCLUDE_CFLAGS := -I . -I include -I libreultra/include/2.0I
ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -mabi=32 -I include
# Files requiring pre/post-processing
GREP := grep -rl
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)
CFLAGS := -G0 -Xfullwarn -Xcpluscomm -signed -nostdinc -non_shared -Wab,-r4300_mul
CFLAGS += -D_LANGUAGE_C -D_FINALROM -DF3DEX_GBI -DWIN32
# ignore compiler warnings about anonymous structs
CFLAGS += -woff 649,838
CFLAGS += $(INCLUDE_CFLAGS)
CC_CHECK := gcc -fsyntax-only -fsigned-char -m32 -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-main -DAVOID_UB -D_LANGUAGE_C -D_FINALROM -DF3DEX_GBI -DWIN32 $(INCLUDE_CFLAGS)
LDFLAGS = -T $(LD_SCRIPT) -Map $(TARGET).map -T undefined_syms_auto.txt -T undefined_funcs_auto.txt -T undefined_funcs.txt -T undefined_syms.txt --no-check-sections
ASM_PROCESSOR_DIR := $(TOOLS_DIR)/asm-processor
### Optimisation Overrides
### Targets
default: all
all: dirs $(TARGET).z64 check
check: $(TARGET).z64 $(N64CRC)
$(N64CRC) $<
@md5sum $<
@md5sum -c checksum.md5
dirs:
$(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(BIN_DIRS),$(shell mkdir -p $(BUILD_DIR)/$(dir)))
nuke:
rm -rf asm
rm -rf assets
rm -rf build
rm -f *auto.txt
clean:
rm -rf build
setup:
$(PYTHON) tools/splat/split.py $(BASENAME).yaml
context:
rm -f ctx.c ctx_includes.c
find include/ src/ -type f -name "*.h" | sed -e 's/.*/#include "\0"/' > ctx_includes.c
$(PYTHON) tools/m2ctx.py ctx_includes.c
compare:
$(PYTHON) first_diff.py
### Recipes
$(TARGET).elf: $(O_FILES)
@$(LD) $(LDFLAGS) -o $@
ifndef PERMUTER
$(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.c.o: %.c
$(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< > $(BUILD_DIR)/$<
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c -32 $(CFLAGS) $(OPT_FLAGS) $(MIPSISET) -o $@ $(BUILD_DIR)/$<
$(PYTHON) $(ASM_PROCESSOR_DIR)/asm_processor.py $(OPT_FLAGS) $< --post-process $@ --assembler "$(AS) $(ASFLAGS)" --asm-prelude $(ASM_PROCESSOR_DIR)/prelude.s
endif
# non asm-processor recipe
$(BUILD_DIR)/%.c.o: %.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
$(CC) -c $(CFLAGS) $(OPT_FLAGS) $(MIPSISET) -o $@ $<
$(BUILD_DIR)/%.s.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.bin.o: %.bin
$(LD) -r -b binary -o $@ $<
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
$(TARGET).z64: $(TARGET).bin
@cp $< $@
$(N64CRC): tools/n64crc.c
make -C tools
### Settings
.SECONDARY:
.PHONY: all clean default
SHELL = /bin/bash -e -o pipefail