-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.nds
265 lines (214 loc) · 8.45 KB
/
Makefile.nds
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
# vim: ft=make noexpandtab
ifneq ($(CALLER),MASTER)
include Makefile.inc
endif
# TODO: Make it compatible.
ifeq ("$(RESOURCE)","FILE")
$(error nds target not compatible with RESOURCE=FILE)
endif
# 1. Directories
OBJDIR_NDS := $(OBJDIR)/nds
DEPDIR_NDS := $(DEPDIR)/nds
GENDIR_NDS := $(GENDIR)/nds
DEVKITPATH := $(shell echo "$(DEVKITPRO)" | sed -e 's/^\([a-zA-Z]\):/\/\1/')
# 2. Files
BIN_NDS := $(BINDIR)/$(DSEKAI).nds
ifeq ("$(RESOURCE)","DEFAULT")
DEFINES_RESOURCE := -DRESOURCE_NDS
DSEKAI_C_FILES_RES := unilayer/src/resource/ndsr.c
endif
DSEKAI_C_FILES_NDS_ONLY := \
src/main.c \
unilayer/src/animate.c \
unilayer/src/input/ndsi.c \
unilayer/src/graphics/ndsg.c \
unilayer/src/memory/fakem.c \
unilayer/src/save/file.c
DSEKAI_ASSETS_MAPS_NDS := \
$(subst .json,.h,$(subst $(ASSETDIR)/,$(GENDIR_NDS)/,$(DSEKAI_ASSETS_MAPS_JSON)))
DSEKAI_O_FILES_NDS := \
$(addprefix $(OBJDIR_NDS)/,$(subst .c,.o,$(DSEKAI_C_FILES))) \
$(addprefix $(OBJDIR_NDS)/,$(subst .c,.o,$(DSEKAI_C_FILES_NDS_ONLY))) \
$(addprefix $(OBJDIR_NDS)/,$(subst .c,.o,$(DSEKAI_C_FILES_RES)))
# DS-specific concatenated tilesheets.
# TODO: Change 16x16x16 to depth var.
DSEKAI_BITMAP_NDS_TILES := $(GENDIR_NDS)/$(ASSETDIR)/16x16x16/bgtiles.bmp
DSEKAI_BITMAP_NDS_PATTERNS := $(GENDIR_NDS)/$(ASSETDIR)/16x16x16/bgpatterns.bmp
# DS-specific bitmap lists.
DSEKAI_BITMAP_HS_NDS := \
$(addprefix $(GENDIR_NDS)/,$(subst .bmp,.h,$(DSEKAI_ASSETS_SPRITES))) \
$(addprefix $(GENDIR_NDS)/,$(subst .bmp,.h,$(DSEKAI_ASSETS_CROPS))) \
$(addprefix $(GENDIR_NDS)/,$(subst .bmp,.h,$(DSEKAI_ASSETS_ITEMS))) \
$(subst .bmp,.h,$(DSEKAI_BITMAP_NDS_TILES)) \
$(subst .bmp,.h,$(DSEKAI_BITMAP_NDS_PATTERNS))
DSEKAI_BITMAP_SS_NDS := $(subst .h,.s,$(DSEKAI_BITMAP_HS_NDS))
DSEKAI_BITMAP_OS_NDS := \
$(subst $(GENDIR_NDS),$(OBJDIR_NDS),$(subst .h,.o,$(DSEKAI_BITMAP_HS_NDS)))
CONSOLIDATED_NDS := \
$(DSEKAI_ASSETS_TILES) \
$(DSEKAI_ASSETS_PATTERNS)
RESEXT_H_NDS := $(GENDIR_NDS)/resext.h
# 3. Programs
CC_NDS := arm-none-eabi-gcc
LD_NDS := arm-none-eabi-gcc
NDSTOOL := ndstool
GRIT := grit
IM_CONVERT := convert
# 4. Arguments
#ARCH_NDS := -mthumb -mthumb-interwork
ARCH_NDS := -mlittle-endian
IM_CONVERT_FLAGS := -type palette -depth 8
DEFINES_NDS := \
$(DEFINES_DSEKAI) \
$(DEFINES_DEPTH) \
$(DEFINES_RESOURCE) \
-DNO_SCRIPT_COMPILER \
-DNO_ENGINE_POV \
-DPLATFORM_NDS \
-DNO_QUIT \
-DNO_TRANSITIONS \
-DUSE_SOFTWARE_TEXT \
-DUSE_SOFTWARE_LINES \
-DARM9
INCLUDES_NDS := \
$(INCLUDES_UNILAYER) \
-I $(GENDIR_NDS) \
-I $(DEVKITPRO)/devkitARM/arm-none-eabi/include \
-I $(DEVKITPRO)/devkitARM/include \
-I $(DEVKITPRO)/libnds/include
CFLAGS_NDS := --sysroot $(DEVKITARM)/arm-none-eabi -march=armv5te -mtune=arm946e-s -fomit-frame-pointer -ffast-math $(ARCH_NDS) $(INCLUDES_NDS) $(DEFINES_NDS)
# The DS uses 8x8 tiles, so use -Mx2 to create 2*8=16px h/w metatiles.
GRIT_FLAGS := -gB8 -Mh2 -Mw2 -gTff55ff
ifneq ($(BUILD),RELEASE)
CFLAGS_NDS += -DLOG_TO_FILE
endif
LIBS_NDS := -L$(DEVKITPRO)/libnds/lib -lnds9
LDFLAGS_NDS := -specs=ds_arm9.specs $(ARCH_NDS) -Wl,-Map,$(OBJDIR_NDS)/$(DSEKAI).map
# TODO: Replace 16x16x16 with depth specifier variable.
GENDIR_NDS_ASSETS := $(GENDIR_NDS)/$(ASSETDIR)/16x16x16
BGSHEETS_NDS := $(GENDIR_NDS_ASSETS)/bgsheets.idx
$(BIN_NDS): PATH := $(DEVKITPATH)/tools/bin:$(DEVKITPATH)/devkitARM/bin:$(PATH)
# 5. Targets
platform := nds
platform_upper := NDS
#res_gfx := $(DSEKAI_ASSETS_BITMAPS)
#$(eval $(RESEXT_H_RULE))
pkg_bin := $(BIN_NDS)
pkg_strip := echo
pkg_name := $(DSEKAI)-$(platform)-$(GIT_HASH)
pkg_reqs :=
$(eval $(PKG_RULE))
# These are appended to the variables in resext.h. These have commas, so they
# can't be included directly in the args to subst.
#COMMANEWLINE_NDS := ",\n"
#TILESUFFIX_NDS := "Tiles,\n"
#PALSUFFIX_NDS := "Pal,\n"
$(GENDIR_NDS)/resemb.h: $(DSEKAI_ASSETS_MAPS_JSON) | \
$(GENDIR_NDS)/$(STAMPFILE) $(HEADPACK)
$(HEADPACK) $@ $^
# Make a concatenated global tilesheet.
# These have a side effect of making a "bgsheets.idx" which is grepped for
# tile offsets in the rule to create resext.h.
# TODO: Maybe move this out to a shell script?
$(DSEKAI_BITMAP_NDS_TILES): $(DSEKAI_ASSETS_TILES)
F_COUNT=0 ; \
for f in $^; do \
if [ ! -f "$@" ]; then \
cp -v "$(ASSETDIR)/t_trans.bmp" "$@" ; \
echo "trans bgtiles $${F_COUNT}" >> "$(BGSHEETS_NDS)" ; \
F_COUNT=$$((F_COUNT + 1)) ; \
fi; \
$(IM_CONVERT) "$@" "$$f" -append $(IM_CONVERT_FLAGS) "$@"; \
echo "`echo $$f | sed -e 's/$(ASSETDIR)\/16x16x16\///g' \
| sed -e 's/.bmp//g'` bgtiles $${F_COUNT}" >> "$(BGSHEETS_NDS)" ; \
F_COUNT=$$((F_COUNT + 1)) ; \
done
# Make a concatenated global pattern sheet.
$(DSEKAI_BITMAP_NDS_PATTERNS): $(DSEKAI_ASSETS_PATTERNS)
F_COUNT=0 ; \
for f in $^; do \
if [ ! -f "$@" ]; then \
cp -v "$(ASSETDIR)/t_trans.bmp" "$@" ; \
echo "trans bgpatterns $${F_COUNT}" >> "$(BGSHEETS_NDS)" ; \
F_COUNT=$$((F_COUNT + 1)) ; \
fi; \
$(IM_CONVERT) "$@" "$$f" -append $(IM_CONVERT_FLAGS) "$@"; \
echo "`echo $$f | sed -e 's/$(ASSETDIR)\/16x16x16\///g' \
| sed -e 's/.bmp//g'` bgpatterns $${F_COUNT}" >> "$(BGSHEETS_NDS)" ; \
F_COUNT=$$((F_COUNT + 1)) ; \
done
$(subst .bmp,.h,$(DSEKAI_BITMAP_NDS_TILES)) \
$(subst .bmp,.s,$(DSEKAI_BITMAP_NDS_TILES)): $(DSEKAI_BITMAP_NDS_TILES)
$(MD) $(dir $@)
$(GRIT) $< $(GRIT_FLAGS) -fts -o $@
$(subst .bmp,.h,$(DSEKAI_BITMAP_NDS_PATTERNS)) \
$(subst .bmp,.s,$(DSEKAI_BITMAP_NDS_PATTERNS)): $(DSEKAI_BITMAP_NDS_PATTERNS)
$(MD) $(dir $@)
$(GRIT) $< $(GRIT_FLAGS) -fts -o $@
$(GENDIR_NDS)/$(ASSETDIR)/%.h $(GENDIR_NDS)/$(ASSETDIR)/%.s: $(ASSETDIR)/%.bmp
$(MD) $(dir $@)
$(GRIT) $< $(GRIT_FLAGS) -fts -o $@
$(RESEXT_H_NDS): $(DSEKAI_BITMAP_HS_NDS) | $(GENDIR_NDS)/resemb.h
$(MD) $(dir $@)
echo "#ifndef RESEXT_H\n#define RESEXT_H\n\n" > $@
echo "" >> $@
echo "#ifdef RESOURCE_C\n" >> $@
## Include all the bitmap headers.
echo "$(addprefix #include \",$(addsuffix \"\n,$(subst $(GENDIR_NDS)/,,$^)))" >> $@
echo "" >> $@
## Create an index of bitmap spritesheets.
echo $(GENDIR_NDS_ASSETS) vs $(GENDIR_NDS)/$(ASSETDIR)/16x16x16
echo "const struct RESOURCE_GRIT_DEF gsc_nds_resources[] = {" >> $@
echo " { \"\", NULL, NULL, 0, 0, 0 }," >> $@
for f in $(subst $(GENDIR_NDS)/$(ASSETDIR)/16x16x16/,,$(subst .h,,$^)); do \
F_TILESLEN="`grep "$${f}TilesLen" "$(GENDIR_NDS_ASSETS)/$${f}.h" | \
awk '{print $$3}'`" ; \
F_PALLEN="`grep "$${f}PalLen" "$(GENDIR_NDS_ASSETS)/$${f}.h" | \
awk '{print $$3}'`" ; \
echo " { \"$${f}\", $${f}Tiles," \
"$${f}Pal, $${F_TILESLEN}, $${F_PALLEN}, -1 }," >> $@ ; \
done
## Include consolidated tiles.
# Note the ^\s surrounding the grep criteria for F_IDX and F_PALLEN!
for f in $(subst $(ASSETDIR)/16x16x16/,,$(subst .bmp,,$(CONSOLIDATED_NDS))); do \
F_MASTER="`grep "^$${f}\s" "$(BGSHEETS_NDS)" | awk '{print $$2}'`" \
F_IDX="`grep "^$$f\s" "$(BGSHEETS_NDS)" | awk '{print $$3}'`" ; \
F_PALLEN="`grep "$${F_MASTER}PalLen" \
"$(GENDIR_NDS_ASSETS)/$${F_MASTER}.h" | \
awk '{print $$3}'`" ; \
F_TILESLEN="`grep "$${F_MASTER}TilesLen" \
"$(GENDIR_NDS_ASSETS)/$${F_MASTER}.h" | \
awk '{print $$3}'`" ; \
echo " { \"$${f}\", $${F_MASTER}Tiles, $${F_MASTER}Pal," \
" $${F_TILESLEN}, $${F_PALLEN}, $${F_IDX} }," \
>> $@ ; \
done
echo " { \"\", NULL, NULL, 0, 0, 0 }" >> $@
echo "};" >> $@
echo "" >> $@
echo "#else" >> $@
# Add extern defs for outside of resource.c (or ndsr.c).
echo "extern const struct RESOURCE_GRIT_DEF gsc_nds_resources[];" >> $@
echo "#endif /* RESOURCE_C */\n" >> $@
echo "" >> $@
echo "#include \"resemb.h\"" >> $@
echo "" >> $@
# Terminate the include file.
echo "#endif /* RESEXT_H */" >> $@
$(BIN_NDS): $(OBJDIR_NDS)/$(DSEKAI).elf $(GENDIR_NDS)/$(DSEKAI)-1.bmp
$(NDSTOOL) -c $@ -9 $< -b $(GENDIR_NDS)/$(DSEKAI)-1.bmp "$(DSEKAI);$(DSEKAI);$(DSEKAI)"
$(GENDIR_NDS)/$(DSEKAI)-1.bmp: $(ASSETDIR)/$(DSEKAI).ico
$(IMAGEMAGICK) $< -compress none -type palette -colors 16 $(GENDIR_NDS)/$(DSEKAI).bmp
$(OBJDIR_NDS)/$(DSEKAI).elf: $(DSEKAI_O_FILES_NDS) $(DSEKAI_BITMAP_OS_NDS)
$(LD_NDS) $(LDFLAGS_NDS) $^ $(LIBS_NDS) -o $@
$(OBJDIR_NDS)/$(ASSETDIR)/%.o: $(GENDIR_NDS)/$(ASSETDIR)/%.s
$(MD) $(dir $@)
$(CC_NDS) $(CFLAGS_NDS) -c -o $@ $<
$(OBJDIR_NDS)/%.o: %.c $(RESEXT_H_NDS) | $(BINDIR)/$(STAMPFILE)
$(MD) $(dir $@)
$(CC_NDS) $(CFLAGS_NDS) -c -o $@ $(<:%.o=%)
#$(DEPDIR_NDS)/%.d: %.c $(GENDIR_NDS)/resext.h $(DSEKAI_ASSETS_MAPS_NDS)
# $(MD) $(dir $@)
# $(CC_NDS) $(CFLAGS_NDS) -MM $< \
# -MT $(subst .c,.o,$(addprefix $(DEPDIR_NDS)/,$<)) -MF $@ || touch $@
#include $(subst $(OBJDIR)/,$(DEPDIR)/,$(DSEKAI_O_FILES_NDS:.o=.d))