forked from doldecomp/melee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
234 lines (184 loc) · 6.09 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
GENERATE_MAP ?= 0
NON_MATCHING ?= 0
EPILOGUE_PROCESS ?= 1
SKIP_CHECK ?= 0
REQUIRE_PROTOS ?= 1
MSG_STYLE ?= gcc
WARN_ERROR ?= 1
VERBOSE ?= 0
MAX_ERRORS ?= 0 # 0 = no maximum
ifeq ($(VERBOSE),0)
QUIET := @
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
TARGET := ssbm.us.1.2
BUILD_DIR := build/$(TARGET)
VANILLA_DIR := $(BUILD_DIR)/vanilla
PROFILE_DIR := $(BUILD_DIR)/profile
# Inputs
LDSCRIPT := ldscript.lcf
# Outputs
DOL := $(BUILD_DIR)/main.dol
ELF := $(DOL:.dol=.elf)
MAP := $(BUILD_DIR)/GALE01.map
include obj_files.mk
O_FILES := $(INIT_O_FILES) $(EXTAB_O_FILES) $(EXTABINDEX_O_FILES) $(TEXT_O_FILES)
DEP_FILES := $(O_FILES:.o=.dep)
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
MWCC_VERSION := 1.2.5
ifeq ($(EPILOGUE_PROCESS),1)
MWCC_EPI_VERSION := 1.2.5e
MWCC_EPI_EXE := mwcceppc.exe
endif
MWCC_LD_VERSION := 1.1
# Programs
ifeq ($(WINDOWS),1)
WINE :=
else
WINE ?= wine
# Disable wine debug output for cleanliness
export WINEDEBUG ?= -all
# Default devkitPPC path
DEVKITPPC ?= /opt/devkitpro/devkitPPC
endif
ifeq ($(shell uname),Darwin)
SHA1SUM := shasum
else
SHA1SUM := sha1sum
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
CC := $(WINE) tools/mwcc_compiler/$(MWCC_VERSION)/mwcceppc.exe
ifeq ($(EPILOGUE_PROCESS),1)
CC_EPI = $(WINE) tools/mwcc_compiler/$(MWCC_EPI_VERSION)/$(MWCC_EPI_EXE)
endif
LD := $(WINE) tools/mwcc_compiler/$(MWCC_LD_VERSION)/mwldeppc.exe
ELF2DOL := tools/elf2dol
HOSTCC := cc
PYTHON := python3
FORMAT := clang-format -i -style=file
FRANK := tools/frank.py
# Options
INCLUDE_DIRS = $(*D)
# TODO dolphin and sysdolphin as system includes
# Then fix include statements to use quotes for other paths
# And make sure that all tools understand this distinction.
SYSTEM_INCLUDE_DIRS := src src/MSL
INCLUDES = $(addprefix -i ,$(INCLUDE_DIRS)) -I- $(addprefix -i ,$(SYSTEM_INCLUDE_DIRS))
ASFLAGS := -mgekko -I src
ifneq ($(NON_MATCHING),1)
ASFLAGS += --defsym MUST_MATCH=1
endif
LDFLAGS := -fp hard -nodefaults
ifeq ($(GENERATE_MAP),1)
LDFLAGS += -map $(MAP)
endif
CFLAGS = -msgstyle $(MSG_STYLE) \
-nowraplines \
-cwd source \
-Cpp_exceptions off \
-proc gekko -fp hard \
-fp_contract on -O4,p \
-enum int \
-nodefaults \
-inline auto $(INCLUDES) \
-maxerrors $(MAX_ERRORS)
ifneq ($(NON_MATCHING),1)
CFLAGS += -DMUST_MATCH
endif
ifeq ($(REQUIRE_PROTOS),1)
CFLAGS += -requireprotos
endif
ifeq ($(MAX_ERRORS),0)
CFLAGS += -nofail
endif
ifeq ($(WARN_ERROR),1)
CFLAGS += -warn iserror
endif
$(BUILD_DIR)/src/melee/pl/player.c.o: CC_EPI := $(CC)
$(BUILD_DIR)/src/melee/lb/lbtime.c.o: CC_EPI := $(CC)
HOSTCFLAGS := -Wall -O3 -s
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
# Remove all built-in rules
.SUFFIXES:
.PHONY: default format clean
### Default target ###
default: $(DOL)
ifeq ($(NON_MATCHING),1)
@echo "Skipping checksum for non-matching build."
else ifeq ($(SKIP_CHECK),1)
@echo "Skipping checksum for this build."
else
$(QUIET) $(SHA1SUM) -c $(TARGET).sha1
endif
# clang-format all source files
format:
$(QUIET) find src -type f \( -name '*.c' -o -name '*.h' \) -exec $(FORMAT) {} +
$(QUIET) tools/newlines.sh
clean:
rm -f -d -r build $(ELF2DOL)
ALL_DIRS := $(sort $(dir $(O_FILES)))
ALL_DIRS += $(patsubst $(BUILD_DIR)/%,$(VANILLA_DIR)/%,$(ALL_DIRS)) \
$(patsubst $(BUILD_DIR)/%,$(PROFILE_DIR)/%,$(ALL_DIRS))
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
%.dol: %.elf $(ELF2DOL)
@echo Converting $< to $@
$(QUIET) $(ELF2DOL) $< $@
ifeq ($(GENERATE_MAP),1)
$(QUIET) $(PYTHON) tools/calcprogress/calcprogress.py --dol $(DOL) --map $(MAP) --asm-obj-ext .s.o --old-map true
endif
# ELF creation makefile instructions
$(ELF): $(O_FILES) $(LDSCRIPT)
@echo Linking ELF $@
$(QUIET) echo $(O_FILES) > build/o_files
$(QUIET) $(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files
$(BUILD_DIR)/%.s.o: %.s
@echo Assembling $<
$(QUIET) $(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.c.dep: %.c
$(QUIET) $(HOSTCC) -E $(addprefix -I ,$(INCLUDE_DIRS) $(SYSTEM_INCLUDE_DIRS)) -MMD -MF $(@:.o=.dep) \
-MT "$(VANILLA_DIR)/$<.o $(PROFILE_DIR)/$<.o" $< >/dev/null
$(BUILD_DIR)/%.c.o: $(VANILLA_DIR)/%.c.o
cp $< $@
$(VANILLA_DIR)/%.c.o: %.c $(BUILD_DIR)/%.c.dep
@echo "Compiling (vanilla)" $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
# Overrides for targets using frank to simulate patched MWCC 1.2.5
ifeq ($(EPILOGUE_PROCESS),1)
$(PROFILE_DIR)/%.c.o: %.c $(BUILD_DIR)/%.c.dep
@echo "Compiling (profile)" $<
$(QUIET) $(CC_EPI) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/src/melee/%.c.o: $(VANILLA_DIR)/src/melee/%.c.o $(PROFILE_DIR)/src/melee/%.c.o $(FRANK)
@echo Frank is fixing $@
$(QUIET) $(PYTHON) $(FRANK) $(word 1,$^) $(word 2,$^) $@
$(BUILD_DIR)/src/sysdolphin/%.c.o: $(VANILLA_DIR)/src/sysdolphin/%.c.o $(PROFILE_DIR)/src/sysdolphin/%.c.o $(FRANK)
@echo Frank is fixing $@
$(QUIET) $(PYTHON) $(FRANK) $(word 1,$^) $(word 2,$^) $@
$(BUILD_DIR)/src/dolphin/card/%.c.o: $(VANILLA_DIR)/src/dolphin/card/%.c.o $(PROFILE_DIR)/src/dolphin/card/%.c.o $(FRANK)
@echo Frank is fixing $@
$(QUIET) $(PYTHON) $(FRANK) $(word 1,$^) $(word 2,$^) $@
$(BUILD_DIR)/src/dolphin/pad/%.c.o: $(VANILLA_DIR)/src/dolphin/pad/%.c.o $(PROFILE_DIR)/src/dolphin/pad/%.c.o $(FRANK)
@echo Frank is fixing $@
$(QUIET) $(PYTHON) $(FRANK) $(word 1,$^) $(word 2,$^) $@
endif
-include $(DEP_FILES)
#-------------------------------------------------------------------------------
# Tool Recipes
#-------------------------------------------------------------------------------
$(ELF2DOL): tools/elf2dol.c
@echo Building tool $@
$(QUIET) $(HOSTCC) $(HOSTCFLAGS) -o $@ $^
### Debug Print ###
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true