-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.mk
371 lines (302 loc) · 12.3 KB
/
common.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
ifndef COMMON_MK_ONCE
all:
COMMON_MK_ONCE = parsed
ROOT ?= $(CURDIR)
LIBNDS := $(DEVKITPRO)/libnds
OUTPUT=$(ROOT)/outnds
O=$(OUTPUT)
EFSTOOL = $(OUTPUT)/bin/efs
LIBNTXM = $(ROOT)/libntxm
LIBGEDS = $(ROOT)/libgeds
LIBPPP9 = $(ROOT)/ppp9
LIBPLUGINS = $(ROOT)/libplugins
PPP7 = $(OUTPUT)/lib/ppp7.arm7
#NTXM_LIB = $(ROOT)/libntxm/lib
#---------------------------------------------------------------------------------
# path to tools
#---------------------------------------------------------------------------------
export PORTLIBS := $(DEVKITPRO)/portlibs/arm
export PATH := $(DEVKITARM)/bin:$(PORTLIBS)/bin:$(PATH)
#---------------------------------------------------------------------------------
# the prefix on the compiler executables
#---------------------------------------------------------------------------------
PREFIX ?= arm-eabi-
export CC := $(PREFIX)gcc
export CXX := $(PREFIX)g++
export AS := $(PREFIX)as
export AR := $(PREFIX)ar
export OBJCOPY := $(PREFIX)objcopy
endif
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
TARGET := $(ROOT)/$M/$M
DATA := $(addprefix $(ROOT)/$M/,$(DATA))
ifndef $M_SOURCES
S:=$(ROOT)/$M/source
else
S:=$($M_SOURCES)
endif
BUILD := $O/$M
DEPSDIR := $(BUILD)
$M_CPU := $(CPU)
#################### ARM 9 ######################
ifeq ($($M_CPU),arm9)
ARCH := -mthumb -mthumb-interwork
# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
# *insists* it has a FPU or VFP, and it won't take no for an answer!
#CFLAGS := -g -Wall -O2\
# -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer\
# -ffast-math \
# $(ARCH)
CFLAGS = -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9 $($M_CFLAGS) $(_CFLAGS)
CXXFLAGS = $(CFLAGS) -fno-rtti $(_CXXFLAGS) $(EXTRAFLAGS) $($M_CXXFLAGS)
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wall -Xlinker -Map -Xlinker $(notdir $*.map)
#################### ARM 7 ######################
else
ifeq ($($M_CPU),arm7)
ARCH := -mthumb-interwork
CFLAGS = -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH) $(INCLUDE) -DARM7 -D__USING_NTXM__ $(_CFLAGS)
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti -std=gnu++0x $(_CXXFLAGS)
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map
else
$(error "no/unknown cpu '$($M_CPU)' defined for $M")
endif
endif
# $1 is variable name, $@ is in $O/$M
modflags = $($(notdir $(patsubst $O/%,%,$(@D)))_$1)
# $1 is variable name, $< is in $(ROOT)/$M
modfiles = $($(notdir $(patsubst $(ROOT)/%,%,$(<D)))_$1)
$M_S := $S
CFILES := $(foreach dir,$S,$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$S,$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$S,$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
OFILES := $(patsubst %,$O/$M/%,$(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o))
DEPENDS := $(OFILES:.o=.o.d)
INCLUDE := $(foreach dir,$(INCLUDES),-I$(ROOT)/$M/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include)
LIBDEPS := $(filter %.a,$(patsubst $O/lib/liblib%,$O/lib/lib%,$(patsubst $(ROOT)/%,$O/lib/lib%.a,$(LIBDIRS))))
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
# capture variables into per-module vars.
$M_TARGET := $(TARGET)
$M_BUILD := $(BUILD)
$M_LIBDEPS := $(LIBDEPS)
$M_CFLAGS := $(CFLAGS)
$M_CXXFLAGS := $(CXXFLAGS)
$M_LDFLAGS := $(LDFLAGS)
$M_LIBS := $(LIBS)
$M_LIBDIRS := $(LIBDIRS)
$M_LIBPATHS := $(LIBPATHS)
$M_CPPFILES := $(CPPFILES)
$M_OFILES := $(OFILES)
# clean arguments vars.
CPU:=
_CXXFLAGS :=
_CFLAGS :=
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro)")
endif
#ISVC=$(or $(VCBUILDHELPER_COMMAND),$(MSBUILDEXTENSIONSPATH32),$(MSBUILDEXTENSIONSPATH))
#ifneq (,$(ISVC))
# ERROR_FILTER := 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):/\1(\2):/g'
#endif
#---------------------------------------------------------------------------------
%.a:
#---------------------------------------------------------------------------------
@echo $(notdir $@)
@mkdir -p $(@D)
@rm -f $@
$(AR) -rc $@ $^
#---------------------------------------------------------------------------------
$O/$M/%.arm.o: $S/%.arm.cpp
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -MF [email protected] $(call modflags,CXXFLAGS) -marm -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.arm.o: $S/%.arm.c
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(CFLAGS) -marm -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.arm.o: $S/%.arm.m
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(OBJCFLAGS) -marm -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.thumb.o: $S/%.thumb.cpp
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -MF [email protected] $(CXXFLAGS) -mthumb -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.thumb.o: $S/%.thumb.c
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(CFLAGS) -mthumb -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.thumb.o: $S/%.thumb.m
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(OBJCFLAGS) -mthumb -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.iwram.o: $S/%.iwram.cpp
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -MF [email protected] $(CXXFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.iwram.o: $S/%.iwram.c
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(CFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.iwram.o: $S/%.iwram.m
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(OBJCFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.itcm.o: $S/%.itcm.cpp
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -MF [email protected] $(CXXFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.itcm.o: $S/%.itcm.c
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(CFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.itcm.o: $S/%.itcm.m
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(OBJCFLAGS) -marm -mlong-calls -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.o: $S/%.cpp
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -MF [email protected] $(call modflags,CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.o: $S/%.c
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(call modflags,CFLAGS) -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.o: $S/%.m
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] $(call modflags,OBJCFLAGS) -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.o: $S/%.s
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] -x assembler-with-cpp $(call modflags,ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
$O/$M/%.o: $S/%.S
@echo $(notdir $<)
@mkdir -p $(dir $@)
$(CC) -MMD -MP -MF [email protected] -x assembler-with-cpp $(call modflags,ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
#---------------------------------------------------------------------------------
# canned command sequence for binary data
#---------------------------------------------------------------------------------
define bin2o
bin2s $< | $(AS) -o $(@)
echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
endef
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
$O/$M/%.bin.o : $(DATA)/%.bin
#---------------------------------------------------------------------------------
mkdir -p $(@D)
@echo $(notdir $<)
@$(bin2o)
ifndef V
Q ?= @
endif
ifeq ($(strip $(GAME_TITLE)),)
$M_GAME_TITLE := $M
else
$M_GAME_TITLE := $(GAME_TITLE)
endif
ifeq ($(strip $(GAME_SUBTITLE1)),)
$M_GAME_SUBTITLE1 := by PypeBros
else
$M_GAME_SUBTITLE1 := $(GAME_SUBTITLE1)
endif
ifeq ($(strip $(GAME_SUBTITLE2)),)
$M_GAME_SUBTITLE2 := sf.net/p/dsgametools
else
$M_GAME_SUBTITLE2 := $(GAME_SUBTITLE2)
endif
ifeq ($(strip $(GAME_ICON)),)
$M_GAME_ICON := $(DEVKITPRO)/libnds/icon.bmp
else
$M_GAME_ICON := $(GAME_ICON)
endif
ifneq ($(strip $(NITRO_FILES)),)
$M_ADDFILES := -d $(NITRO_FILES)
endif
ifneq ($(strip $(EFS_FILES)),)
$M_ADDFILES := -d $(EFS_FILES)
$(TARGET).nds: $(EFSTOOL)
endif
GAME_ICON :=
GAME_TITLE :=
GAME_SUBTITLE1 :=
GAME_SUBTITLE2 :=
EFS_FILES :=
#---------------------------------------------------------------------------------
%.nds: %.arm9
@echo converting $< to $@, $(notdir $(patsubst $(ROOT)/%,%,$(<D)))_FILES
ndstool -c $@ -9 $(filter %.arm9,$^) -7 $(filter %.arm7,$^) -b $(call modfiles,GAME_ICON) "$(call modfiles,GAME_TITLE);$(call modfiles,GAME_SUBTITLE1);$(call modfiles,GAME_SUBTITLE2)" $(call modfiles,ADDFILES)
@echo built ... $(notdir $@)
$(if $(findstring $(EFSTOOL),$^), $(EFSTOOL) $@, echo "no EFS for $@")
ifneq ($(DLDI),)
dlditool $(DLDI) $(OUTPUT).nds
endif
#---------------------------------------------------------------------------------
%.nds: %.elf
@echo converting $< to $@, $(notdir $(patsubst $(ROOT)/%,%,$(<D)))_FILES
ndstool -c $@ -9 $< -b $(call modfiles,GAME_ICON) "$(call modfiles,GAME_TITLE);$(call modfiles,GAME_SUBTITLE1);$(call modfiles,GAME_SUBTITLE2)" $(call modfiles,ADDFILES)
@echo built ... $(notdir $@)
#---------------------------------------------------------------------------------
%.arm9: %.elf
$Q$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
#---------------------------------------------------------------------------------
%.arm7: %.elf
$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
#---------------------------------------------------------------------------------
$O/$M/%.elf:
@echo mod-linking $(notdir $@)
$(LD) $(call modflags,LDFLAGS) $(filter-out %.a,$^) $(call modflags,LIBPATHS) $(call modflags,LIBS) -o $@
$(ROOT)/$M/%.elf:
@echo mod-linking $(notdir $@)
$(LD) $(call modfiles,LDFLAGS) $(filter-out %.a,$^) $(call modfiles,LIBPATHS) $(call modfiles,LIBS) -o $@