-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
272 lines (211 loc) · 7.44 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# version of library
MAJOR = 2
MINOR = 0
REVISION = 0
VERSION = mml-$(MAJOR).$(MINOR).$(REVISION)
# GNU tools
CC = powerpc-eabi-gcc
AR = powerpc-eabi-ar
OBJCPY = powerpc-eabi-objcopy
# sources and header files (included in distribution)
SRCS = src/ai.c src/controller.c src/game_state.c src/moves.c \
src/math.c src/print.c src/random.c src/state_check.c src/matrix.c \
src/string.c src/system.c src/melee_info.c src/version.c src/error.c \
src/profile.c src/input_queue.c
HEADERS = $(SRCS:.c=.h) src/gctypes.h src/native_functions.h \
src/unit_test.h src/logic.h src/action_state.h \
src/native_functions_102.h src/native_functions_PAL.h
# object files and their dependencies
OBJS_O0 = $(SRCS:src/%.c=build/%_O0.o)
OBJS_O1 = $(OBJS_O0:%_O0.o=%_O1.o)
OBJS_O2 = $(OBJS_O0:%_O0.o=%_O2.o)
OBJS_O3 = $(OBJS_O0:%_O0.o=%_O3.o)
OBJS_Os = $(OBJS_O0:%_O0.o=%_Os.o)
OBJS_PAL = $(OBJS_O0:%_O0.o=%_PAL.o)
OBJS = $(OBJS_O0) $(OBJS_O1) $(OBJS_O2) $(OBJS_O3) $(OBJS_Os) $(OBJS_PAL)
DEP = $(OBJS:.o=.d)
# names of the libraries (one for each -O flag)
LIBS = libmml.a libmml_O0.a libmml_O2.a libmml_O3.a libmml_Os.a
DIST_LIBS = libmml.a libmml_O0.a libmml_O2.a libmml_O3.a
DIST_TARGETS = $(HEADERS) $(DIST_LIBS) tutorials/*/*.c tutorials/*/*.h \
tutorials/*/*.ini
# link, archive, and compile flags
LDFLAGS =
AFLAGS = -cvr
CFLAGS = -Wall -Wextra -std=c99 -fno-builtin \
-fdata-sections -ffunction-sections -Werror \
-DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DREVISION=$(REVISION)
# sections to remove from object files
SECTIONS = .comment
# library targets (need to set optimizer flag)
libmml.a : $(OBJS_O1)
libmml_O0.a : $(OBJS_O0)
libmml_O2.a : $(OBJS_O2)
libmml_O3.a : $(OBJS_O3)
libmml_Os.a : $(OBJS_Os)
libmml_PAL.a : $(OBJS_PAL)
libs : $(LIBS)
# command to build the libraries
%.a :
$(AR) $(AFLAGS) $@ $^
# include auto-generated dependencies
-include $(DEP)
# rule to build object files and remove unneccesary sections
build/%_O0.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -O0 -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
build/%_O1.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -O1 -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
build/%_O2.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -O2 -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
build/%_O3.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -O3 -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
build/%_Os.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -Os -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
build/%_PAL.o : src/%.c
mkdir -p build
$(CC) $(CFLAGS) -O1 -DPAL -c -MMD $< -o $@
$(OBJCPY) -R $(SECTIONS) $@
$(OBJCPY) --rename-section .rodata=$*.rodata $@
$(OBJCPY) --rename-section .gnu.attributes=$*.gnu.attributes $@
# target for building the distribution
.PHONY : dist tar zip untar
dist : libs
$(MAKE) clean_dist
$(MAKE) tar
$(MAKE) untar
# build the tar.gz version of the distribution
tar :
tar --transform='s|src|include/mml|' -czf $(VERSION).tar.gz \
$(DIST_TARGETS)
# build the .zip version of the distribution
zip :
zip $(VERSION).zip -r $(DIST_TARGETS)
for h in $(HEADERS:src/%.h=%.h) ; do \
printf "@ src/$$h\n@=include/mml/$$h" | zipnote -w $(VERSION).zip ; \
done
# extract dist to folder
untar :
mkdir -p $(VERSION)
tar -xf $(VERSION).tar.gz -C $(VERSION)
# test targets
.PHONY : test_ai test_controller test_error test_game_state test_math \
test_melee_info test_moves test_print test_random test_state_check \
test_string test_system test_version
# iso file to inject test code into
ISO_FILE = Melee.iso
test_ai : $(LIBS)
wiimake $(ISO_FILE) tests/testAI.ini $(MAKE_FLAGS)
test_controller : $(LIBS)
wiimake $(ISO_FILE) tests/testController.ini $(MAKE_FLAGS)
test_error : $(LIBS)
wiimake $(ISO_FILE) tests/testError.ini $(MAKE_FLAGS)
test_game_state : $(LIBS)
wiimake $(ISO_FILE) tests/testGameState.ini $(MAKE_FLAGS)
test_math : $(LIBS)
wiimake $(ISO_FILE) tests/testMath.ini $(MAKE_FLAGS)
test_matrix : $(LIBS)
wiimake $(ISO_FILE) tests/testMatrix.ini $(MAKE_FLAGS)
test_melee_info : $(LIBS)
wiimake $(ISO_FILE) tests/testMeleeInfo.ini $(MAKE_FLAGS)
test_move : $(LIBS)
wiimake $(ISO_FILE) tests/testMove.ini $(MAKE_FLAGS)
test_print : $(LIBS)
wiimake $(ISO_FILE) tests/testPrint.ini $(MAKE_FLAGS)
test_random : $(LIBS)
wiimake $(ISO_FILE) tests/testRandom.ini $(MAKE_FLAGS)
test_state_check : $(LIBS)
wiimake $(ISO_FILE) tests/testStateCheck.ini $(MAKE_FLAGS)
test_string : $(LIBS)
wiimake $(ISO_FILE) tests/testString.ini $(MAKE_FLAGS)
test_system : $(LIBS)
wiimake $(ISO_FILE) tests/testSystem.ini $(MAKE_FLAGS)
test_version : $(LIBS)
wiimake $(ISO_FILE) tests/testVersion.ini $(MAKE_FLAGS)
# tutorial targets
.PHONY : tutorial_SimpleProgram tutorial_Teching tutorial_DI \
tutorial_Recovery tutorial_DefensiveAI tutorial_data
TUTORIALS = tutorial_SimpleProgram tutorial_Teching tutorial_DI \
tutorial_Recovery tutorial_DefensiveAI
tutorial_data : $(TUTORIALS)
cp $(VERSION)/tutorials/SimpleProgram/SimpleProgram.data \
tutorials/SimpleProgram/SimpleProgram.data && \
cp $(VERSION)/tutorials/Teching/TechingTutorial.data \
tutorials/Teching/TechingTutorial.data && \
cp $(VERSION)/tutorials/DI/DITutorial.data \
tutorials/DI/DITutorial.data && \
cp $(VERSION)/tutorials/Recovery/RecoveryTutorial.data \
tutorials/Recovery/RecoveryTutorial.data && \
cp $(VERSION)/tutorials/DefensiveAI/DefensiveAI.data \
tutorials/DefensiveAI/DefensiveAI.data
tutorial_SimpleProgram : dist
cd $(VERSION)/tutorials/SimpleProgram && \
wiimake ../../../$(ISO_FILE) SimpleProgram.ini $(MAKE_FLAGS) && \
cd ../../..
tutorial_Teching : dist
cd $(VERSION)/tutorials/Teching && \
wiimake ../../../$(ISO_FILE) TechingTutorial.ini $(MAKE_FLAGS) && \
cd ../../..
tutorial_DI : dist
cd $(VERSION)/tutorials/DI && \
wiimake ../../../$(ISO_FILE) DITutorial.ini $(MAKE_FLAGS) && \
cd ../../..
tutorial_Recovery : dist
cd $(VERSION)/tutorials/Recovery && \
wiimake ../../../$(ISO_FILE) RecoveryTutorial.ini $(MAKE_FLAGS) && \
cd ../../..
tutorial_DefensiveAI : dist
cd $(VERSION)/tutorials/DefensiveAI && \
wiimake ../../../$(ISO_FILE) DefensiveAI.ini $(MAKE_FLAGS) && \
cd ../../..
tutorial_DashDancing : dist
cd $(VERSION)/tutorials/DashDancing && \
wiimake ../../../$(ISO_FILE) DashDancing.ini $(MAKE_FLAGS) && \
cd ../../..
# documentation target
.PHONY : docs
docs :
echo "PROJECT_NUMBER =" $(MAJOR).$(MINOR).$(REVISION) >> doxygen.ini
doxygen doxygen.ini
# create todo list
.PHONY : todo_list
todo_list :
grep -r TODO src || true
# restore iso to vanilla state
restore_iso :
rm -f $(ISO_FILE)
cp VanillaMelee102.iso $(ISO_FILE)
# clean targets
.PHONY : clean clean_libs clean_deps clean_objects clean_dist clean_tests
clean : clean_libs clean_deps clean_objects clean_dist clean_tests
clean_deps :
rm -f $(DEP)
clean_libs :
rm -f $(LIBS)
clean_objects :
rm -f $(OBJS) tests/*.o
clean_dist :
rm -f $(VERSION).tar.gz $(VERSION).zip
rm -rf $(VERSION)
clean_tests :
rm -f tests/*.o final.txt *.o *.s linker_script.txt \
size_linker_script.txt sizes.out sizes.txt final.out