-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
169 lines (134 loc) · 5.69 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
# Config
VERSION ?= us
TARGET := NSUE
BASEROM := baserom.$(VERSION).z64
BUILD_ROOT := build
ROM_SIZE := 0xC00000
RFILTER_OUT = $(foreach v,$(2),$(if $(findstring $(1),$(v)),,$(v)))
BUILD_DIR := $(BUILD_ROOT)/$(VERSION)
SRC_DIR := src
ASM_DIR := asm
BIN_DIR := bin
LIBULTRA_DIRS := audio gu io n_audio os sched
ROCKET_SRC_DIRS := $(shell find $(SRC_DIR)/ -type d)
LIBULTRA_SRC_DIRS := $(addprefix ultra/src/,$(LIBULTRA_DIRS))
SRC_DIRS := $(ROCKET_SRC_DIRS) $(LIBULTRA_SRC_DIRS)
ASM_DIRS := $(call RFILTER_OUT,nonmatching,$(shell find $(ASM_DIR)/ -type d))
SRC_BUILD_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) # Don't search libultra dirs, but generate them for manual specifying of libultra asm files
ASM_BUILD_DIRS := $(addprefix $(BUILD_DIR)/,$(ASM_DIRS) $(LIBULTRA_DIRS))
BIN_BUILD_DIR := $(BUILD_DIR)/$(BIN_DIR)
KMCGCCDIR := tools/kmc/gcc
# Files
FILTERED_OUT_SRCS := src/lib/codeseg1/player_commands.c src/lib/codeseg1/player_api.c src/lib/codeseg1/player_fifo.c
C_SRCS := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
C_SRCS := $(filter-out $(FILTERED_OUT_SRCS),$(C_SRCS))
C_ASMS := $(addprefix $(BUILD_DIR)/, $(C_SRCS:.c=.s))
C_OBJS := $(C_ASMS:.s=.o)
LIBULTRA_ASMS := gu/libm_vals.s
AS_SRCS := $(wildcard $(ASM_DIR)/*.s) $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s)) $(addprefix ultra/src/,$(LIBULTRA_ASMS))
AS_OBJS := $(addprefix $(BUILD_DIR)/, $(AS_SRCS:.s=.o))
BINS := $(wildcard $(BIN_DIR)/*.bin)
BIN_OBJS := $(addprefix $(BUILD_DIR)/, $(BINS:.bin=.o))
OBJS := $(C_OBJS) $(AS_OBJS) $(BIN_OBJS)
LD_SCRIPT := NSUE.ld
Z64 := $(BUILD_DIR)/$(TARGET).z64
ELF := $(Z64:.z64=.elf)
LIBULTRA_SRCS := $(foreach dir,$(LIBULTRA_SRC_DIRS),$(wildcard $(dir)/*.c))
SN_SRCS := $(foreach dir,$(shell find $(SRC_DIR)/rocket/ -type d) $(shell find $(SRC_DIR)/lib/ -type d),$(wildcard $(dir)/*.c))
SN_SRCS := $(filter-out $(FILTERED_OUT_SRCS),$(SN_SRCS))
SN_OBJS := $(addprefix $(BUILD_DIR)/, $(SN_SRCS:.c=.o))
# Tools
ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips-linux-gnu-
else ifeq ($(shell type mips64-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0)
CROSS := mips64-linux-gnu-
else
CROSS := mips64-elf-
endif
CPP := $(CROSS)cpp
AS := $(CROSS)gcc
OBJCOPY := $(CROSS)objcopy
LD := $(CROSS)gcc
STRIP := $(CROSS)strip
KMC_DIR := tools/gcc-2.7.2
KMC_CC := $(KMC_DIR)/gcc
KMC_AS := $(KMC_DIR)/as
SN_DIR := tools/modern-sn64
SN_CC := $(SN_DIR)/gcc
SN_AS := $(SN_DIR)/modern-asn64.py
export N64ALIGN := ON
export VR4300MUL := ON
# Flags
CPPFLAGS := -Iinclude -Iinclude/2.0I -Iinclude/2.0I/PR -Iultra/src/audio -Iultra/src/n_audio -Iinclude/mus -DF3DEX_GBI_2 -D_FINALROM -DTARGET_N64 -DSUPPORT_NAUDIO -DN_MICRO -D_LANGUAGE_C
CFLAGS := -G0 -mcpu=vr4300 -mips2 -fno-exceptions -funsigned-char -gdwarf \
-Wa,-G0,-EB,-mips3,-mabi=32,-mgp32,-march=vr4300,-mfp32,-mno-shared
ASN64FLAGS := -q -G0
KMC_CFLAGS := -c -G0 -mgp32 -mfp32 -mips3
WARNFLAGS := -Wall -Werror -Wno-uninitialized
OPTFLAGS := -O2
ASFLAGS := -march=vr4300 -mabi=32 -mgp32 -mfp32 -mips3 -mno-abicalls -G0 -fno-pic -gdwarf -c
LDFLAGS := -march=vr4300 -mabi=32 -mgp32 -mfp32 -mips3 -mno-abicalls -G0 -fno-pic -gdwarf -nostartfiles -Wl,-T,$(LD_SCRIPT) -Wl,-T,tools/undefined_syms.txt -Wl,--build-id=none
BINOFLAGS := -I binary -O elf32-tradbigmips
Z64OFLAGS := -O binary --pad-to=$(ROM_SIZE) --gap-fill=0x00
MKDIR := mkdir -p
RMDIR := rm -rf
DIFF := diff
all: check
$(SRC_BUILD_DIRS) : | $(SRC_DIR)
$(SRC_DIR) : | $(BUILD_DIR)
$(BUILD_DIR) : | $(BUILD_ROOT)
$(BUILD_ROOT) $(BUILD_DIR) $(SRC_DIR) $(SRC_BUILD_DIRS) $(ASM_BUILD_DIRS) $(BIN_BUILD_DIR) :
$(MKDIR) $@
$(BUILD_DIR)/ultra/%.o : ultra/%.c | $(SRC_BUILD_DIRS) $(KMC_CC) $(KMC_AS)
export COMPILER_PATH=$(KMC_DIR) && $(KMC_CC) -D__FILE__=\"$(notdir $<)\" $(CPPFLAGS) $(KMC_CFLAGS) $(OPTFLAGS) $< -o $@
@$(STRIP) $@ -N $(<:.i=.c)
# Legacy stuff in case testing with the original toolchain is needed
# PROC_VERSION != uname -a
# IS_WSL := $(findstring microsoft,$(PROC_VERSION)) $(findstring Microsoft,$(PROC_VERSION))
# ifneq ($(strip $(IS_WSL)),)
# CC1N64 := ./sn/cc1n64.exe
# ASN64 := ./sn/asn64.exe
# else
# CC1N64 := wine ./sn/cc1n64.exe
# ASN64 := wine ./sn/asn64.exe
# endif
# CC1N64_CFLAGS := -quiet -G0 -mcpu=vr4300 -mips3 -mhard-float -meb -g
# SN_LNKS := $(addprefix $(BUILD_DIR)/, $(SN_SRCS:.c=.obj))
# $(SN_LNKS) : $(BUILD_DIR)/%.obj : %.c | $(SRC_BUILD_DIRS)
# @printf "Compiling $<\r\n"
# @$(CPP) $(CPPFLAGS) $< -o [email protected]
# @$(CC1N64) $(CC1N64_CFLAGS) $(OPTFLAGS) [email protected] -o [email protected]
# @$(ASN64) $(ASN64FLAGS) [email protected] -o $@
# $(SN_OBJS) : $(BUILD_DIR)/%.o : $(BUILD_DIR)/%.obj
# @printf "Running obj parser on $<\r\n"
# @tools/psyq-obj-parser $< -o $@ -b -n > /dev/null
$(SN_OBJS) : $(BUILD_DIR)/%.o : %.c | $(SRC_BUILD_DIRS) $(SN_CC) $(SN_AS)
@printf "Compiling $<\r\n"
export COMPILER_PATH=$(SN_DIR) && $(SN_CC) $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) $(CPPFLAGS) $< -c -o $@
$(BUILD_DIR)/%.o : $(BUILD_DIR)/%.s
$(AS) $(ASFLAGS) $(CPPFLAGS) $< -o $@
$(BUILD_DIR)/%.o : %.s | $(ASM_BUILD_DIRS) $(SRC_BUILD_DIRS)
$(AS) $(ASFLAGS) $(CPPFLAGS) $< -o $@
$(BUILD_DIR)/%.o : %.bin | $(BIN_BUILD_DIR)
$(OBJCOPY) $(BINOFLAGS) $< $@
$(ELF) : $(OBJS)
$(LD) $(LDFLAGS) -Wl,-Map,$(@:.elf=.map) -o $@
$(Z64) : $(ELF)
$(OBJCOPY) $(Z64OFLAGS) $< $@
python3 tools/n64cksum.py $@
$(BUILD_DIR)/ultra/%.o: OPTFLAGS := -O3
$(BUILD_DIR)/src/rocket/codeseg2/codeseg2_3.o: OPTFLAGS := -O3
$(BUILD_DIR)/src/lib/%.o: WARNFLAGS :=
clean:
$(RMDIR) $(BUILD_ROOT)
check: $(Z64)
@$(DIFF) $(BASEROM) $(Z64) && printf "OK\n"
setup:
rm -rf asm/ data/
tools/splat/split.py tools/NSUE.00.yaml --modes=all
$(KMC_CC) $(KMC_AS) $(SN_CC) $(SN_AS) :
$(MAKE) -C tools/ $(@:tools/%=%)
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
.PHONY: all clean check setup
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true