-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile_gba.mk
249 lines (176 loc) · 6.99 KB
/
makefile_gba.mk
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
# These directories specify where source code files are located.
# Edit these variables if more directories are needed.
# Separate each entry by spaces.
SHARED_SRC_DIRS:=src src/general_utility_stuff \
src/game_engine_stuff src/game_engine_stuff/block_stuff \
src/game_engine_stuff/block_stuff/specific_blocks \
src/game_engine_stuff/level_stuff src/game_engine_stuff/sprite_stuff \
src/game_engine_stuff/sprite_stuff/specific_sprites \
src/gba_specific_stuff src/test_level src/audio src/gfx \
src/testing # Remove this eventually please!
BINARY_DIRS:=src/audio
CXX_DIRS:=$(SHARED_SRC_DIRS)
S_DIRS:=$(SHARED_SRC_DIRS)
# End of source directories
# Comment out or un-comment out the next line to enable debugging stuff to
# be generated
DEBUG:=yeah do debug
DEBUG_OPTIMIZATION_LEVEL:=-O0
REGULAR_OPTIMIZATION_LEVEL:=-O2
ALWAYS_DEBUG_SUFFIX:=_debug
ifdef DEBUG
DEBUG_SUFFIX:=$(ALWAYS_DEBUG_SUFFIX)
endif
# This is the name of the output file. Change this if needed!
PROJ:=$(shell basename $(CURDIR))$(DEBUG_SUFFIX)
# This is used for do_asmouts
#VERBOSE_ASM_FLAG:=-fverbose-asm
PREFIX:=$(DEVKITARM)/bin/arm-none-eabi-
# Compilers and initial compiler flags
CXX:=$(PREFIX)g++
CXX_FLAGS:=$(CXX_FLAGS) -std=c++17 -Wall
AS:=$(PREFIX)as
OBJDUMP:=$(PREFIX)objdump
OBJCOPY:=$(PREFIX)objcopy
LD:=$(CXX)
# Initial linker flags
LD_FLAGS:=$(LD_FLAGS) -lm
ifdef DEBUG
EXTRA_DEBUG_FLAGS:=-g
DEBUG_FLAGS:=-gdwarf-3 $(EXTRA_DEBUG_FLAGS)
EXTRA_LD_FLAGS:=$(DEBUG_FLAGS)
OPTIMIZATION_LEVEL:=$(DEBUG_OPTIMIZATION_LEVEL)
else
OPTIMIZATION_LEVEL:=$(REGULAR_OPTIMIZATION_LEVEL)
endif
LD_SCRIPT:=linkscript.ld
#LD_SCRIPT_GPP_SRC:=linkscript.gpp
COMMON_LD_FLAGS:=$(COMMON_LD_FLAGS) -T $(LD_SCRIPT)
EXTRA_BASE_FLAGS:=-mcpu=arm7tdmi -mtune=arm7tdmi -mthumb \
-mthumb-interwork \
-fno-threadsafe-statics -nostartfiles
EXTRA_LD_FLAGS:=$(EXTRA_LD_FLAGS) -mthumb --specs=nosys.specs \
-lm -lgcc -lc -lstdc++
COMMON_LD_FLAGS:=$(COMMON_LD_FLAGS) -L$(DEVKITPRO)/libgba/lib \
-Wl,--entry=_start2 -lmm
DISASSEMBLE_BASE_FLAGS:=-marm7tdmi
FINAL_BASE_FLAGS:=$(OPTIMIZATION_LEVEL) \
$(EXTRA_BASE_FLAGS) $(EXTRA_DEBUG_FLAGS)
FINAL_BASE_FLAGS:=-I$(DEVKITPRO)/libgba/include $(FINAL_BASE_FLAGS)
# Final compiler and linker flags
CXX_FLAGS:=$(CXX_FLAGS) $(FINAL_BASE_FLAGS)
LD_FLAGS:=$(LD_FLAGS) $(EXTRA_LD_FLAGS) $(COMMON_LD_FLAGS)
# Generated directories
OBJDIR:=objs$(DEBUG_SUFFIX)
ASMOUTDIR:=asmouts$(DEBUG_SUFFIX)
DEPDIR:=deps$(DEBUG_SUFFIX)
PREPROCDIR:=preprocs$(DEBUG_SUFFIX)
# Directories to search, specified at the top of this file
export VPATH := \
$(foreach DIR,$(BINARY_DIRS),$(CURDIR)/$(DIR)) \
$(foreach DIR,$(CXX_DIRS),$(CURDIR)/$(DIR)) \
$(foreach DIR,$(S_DIRS),$(CURDIR)/$(DIR)) \
BIN_SOURCES:=$(foreach DIR,$(BINARY_DIRS),$(notdir $(wildcard $(DIR)/*.bin)))
BIN_OFILES:=$(BIN_SOURCES:%.bin=$(OBJDIR)/%.o)
BIN_PFILES:=$(BIN_SOURCES:%.bin=$(DEPDIR)/%.P)
CXX_SOURCES:=$(foreach DIR,$(CXX_DIRS),$(notdir $(wildcard $(DIR)/*.cpp)))
CXX_OFILES:=$(CXX_SOURCES:%.cpp=$(OBJDIR)/%.o)
CXX_PFILES:=$(CXX_SOURCES:%.cpp=$(DEPDIR)/%.P)
# Assembly source code generated by gcc/g++
CXX_ASMOUTS:=$(CXX_SOURCES:%.cpp=$(ASMOUTDIR)/%.s)
S_SOURCES:=$(foreach DIR,$(S_DIRS),$(notdir $(wildcard $(DIR)/*.s)))
S_OFILES:=$(S_SOURCES:%.s=$(OBJDIR)/%.o)
S_PFILES:=$(S_SOURCES:%.s=$(DEPDIR)/%.P)
# Compiler-generated files
# OFILES are object code files (extension .o)
OFILES:=$(BIN_OFILES) $(CXX_OFILES) $(S_OFILES)
# PFILES are used for automatic dependency generation
PFILES:=$(BIN_PFILES) $(CXX_PFILES) $(S_PFILES)
ASMOUTS:=$(CXX_ASMOUTS) $(C_ASMOUTS)
# Preprocessed output of only C++ files
CXX_EFILES:=$(CXX_SOURCES:%.cpp=$(PREPROCDIR)/%.E)
EFILES:=$(CXX_EFILES)
#all : all_pre $(LD_SCRIPT) $(OFILES)
all : all_pre $(OFILES)
$(LD) $(OBJDIR)/*.o -o $(PROJ).elf $(LD_FLAGS) -Wl,-M > linker_map.txt
$(OBJCOPY) -O binary -S -g -R .iwram -R .bss -R .ewram -R .sram \
-R .bss0 -R .bss1 -R .bss2 -R .bss3 -R .bss4 -R .bss5 -R .bss6 -R .bss7 \
-R .bss8 -R .bss9 -R .bss10 -R .bss11 -R .bss12 -R .bss13 -R .bss14 -R .bss15 \
-R .iwram_bss0 -R .iwram_bss1 -R .iwram_bss2 -R .iwram_bss3 \
-R .iwram_bss4 -R .iwram_bss5 -R .iwram_bss6 -R .iwram_bss7 \
-R .iwram_bss8 -R .iwram_bss9 -R .iwram_bss10 -R .iwram_bss11 \
-R .iwram_bss12 -R .iwram_bss13 -R .iwram_bss14 -R .iwram_bss15 \
-R .sram0 -R .sram1 -R .sram2 -R .sram3 -R .sram4 -R .sram5 -R .sram6 -R .sram7 \
-R .sram8 -R .sram9 -R .sram10 -R .sram11 -R .sram12 -R .sram13 -R .sram14 -R .sram15 \
$(PROJ).elf $(PROJ).gba
./do_gbafix.sh
# all_objs is ENTIRELY optional.
all_objs : all_pre $(OFILES)
@#
do_asmouts : all_pre all_pre_asmout $(ASMOUTS)
@#
all_pre :
mkdir -p $(OBJDIR) $(DEPDIR)
all_pre_asmout :
mkdir -p $(ASMOUTDIR)
$(BIN_OFILES) : $(OBJDIR)/%.o : %.bin
util/bin2o_gba.sh $< $@
#$(LD_SCRIPT) : $(LD_SCRIPT_GPP_SRC)
# gpp $(LD_SCRIPT_GPP_SRC) > $(LD_SCRIPT)
# Here's where things get really messy.
$(CXX_OFILES) : $(OBJDIR)/%.o : %.cpp
@#echo "Generating dependency information for "$@"...."
@echo $@" was updated or has no object file. (Re)Compiling...."
$(CXX) $(CXX_FLAGS) -MMD -c $< -o $@
@cp $(OBJDIR)/$*.d $(DEPDIR)/$*.P
@#$(sed_script) < $(OBJDIR)/$*.d >> $(DEPDIR)/$*.P
@rm -f $(OBJDIR)/$*.d
$(S_OFILES) : $(OBJDIR)/%.o : %.s
@#echo "Generating dependency information for "$@"...."
@echo $@" was updated or has no object file. (Re)Assembling...."
$(AS) $(S_FLAGS) -MD $(OBJDIR)/$*.d -c $< -o $@
@cp $(OBJDIR)/$*.d $(DEPDIR)/$*.P
@#$(sed_script) < $(OBJDIR)/$*.d >> $(DEPDIR)/$*.P
@rm -f $(OBJDIR)/$*.d
# Here we have stuff for outputting assembly source code instead of an object file.
$(CXX_ASMOUTS) : $(ASMOUTDIR)/%.s : %.cpp
@#$(CXX) $(CXX_FLAGS) -MMD -S -fverbose-asm $< -o $@
@#$(CXX) $(CXX_FLAGS) -MMD -S $< -o $@
$(CXX) $(CXX_FLAGS) -MMD -S $(VERBOSE_ASM_FLAG) $< -o $@
@cp $(ASMOUTDIR)/$*.d $(DEPDIR)/$*.P
@#$(sed_script) < $(ASMOUTDIR)/$*.d >> $(DEPDIR)/$*.P
@rm -f $(ASMOUTDIR)/$*.d
-include $(PFILES)
only_preprocess : only_preprocess_pre $(EFILES)
@#
only_preprocess_pre :
mkdir -p $(DEPDIR) $(PREPROCDIR)
#$(CXX_EFILES) : $(PREPROCDIR)/%.E : %.cpp
$(CXX_EFILES) : $(PREPROCDIR)/%.E : %.cpp
$(CXX) $(CXX_FLAGS) -MMD -E $< -o $@
@cp $(PREPROCDIR)/$*.d $(DEPDIR)/$*.P
@#$(sed_script) < $(PREPROCDIR)/$*.d >> $(DEPDIR)/$*.P
@rm -f $(PREPROCDIR)/$*.d
#¯\(°_o)/¯
.PHONY : clean
clean :
rm -rfv $(OBJDIR) $(DEPDIR) $(ASMOUTDIR) $(PREPROCDIR) \
$(PROJ).gba $(PROJ).elf tags *.taghl gmon.out
#$(PROJ).gba $(PROJ).elf tags *.taghl gmon.out $(LD_SCRIPT)
# Flags for make disassemble*
DISASSEMBLE_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -d
DISASSEMBLE_ALL_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -D
DISASSEMBLE_2_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -S -l -d
DISASSEMBLE_ALL_2_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -S -l -D
.PHONY : disassemble
disassemble :
$(OBJDUMP) $(DISASSEMBLE_FLAGS) $(PROJ).elf
.PHONY : disassemble_all
disassemble_all :
$(OBJDUMP) $(DISASSEMBLE_ALL_FLAGS) $(PROJ).elf
.PHONY : disassemble_2
disassemble_2 :
$(OBJDUMP) $(DISASSEMBLE_2_FLAGS) $(PROJ).elf
.PHONY : disassemble_all_2
disassemble_all_2 :
$(OBJDUMP) $(DISASSEMBLE_ALL_2_FLAGS) $(PROJ).elf