forked from TricksterGuy/3ds-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
285 lines (222 loc) · 9.97 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
.SUFFIXES:
#---------------------------------------------------------------------------------
# Environment Setup
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
endif
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/3ds_rules
# ip address of 3ds for hblauncher/fbi target.
IP3DS := 192.168.1.11
#---------------------------------------------------------------------------------
# Directory Setup
#---------------------------------------------------------------------------------
BUILD := build
OUTPUT := output
SOURCES := source
DATA := data
INCLUDES := $(SOURCES) include
ROMFS := romfs
RESOURCES := resources
#---------------------------------------------------------------------------------
# Resource Setup
#---------------------------------------------------------------------------------
APP_INFO := $(RESOURCES)/AppInfo
BANNER_AUDIO := $(RESOURCES)/audio
BANNER_IMAGE := $(RESOURCES)/banner
ICON := $(RESOURCES)/icon.png
RSF := $(TOPDIR)/$(RESOURCES)/template.rsf
#---------------------------------------------------------------------------------
# Build Setup (code generation)
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
COMMON_FLAGS := -g -Wall -Wno-strict-aliasing -O3 -mword-relocations -fomit-frame-pointer \
-ffast-math $(ARCH) $(INCLUDE) -DARM11 -D_3DS $(BUILD_FLAGS)
CFLAGS := $(COMMON_FLAGS) -std=gnu99
CXXFLAGS := $(COMMON_FLAGS) -std=gnu++11
ifeq ($(ENABLE_EXCEPTIONS),)
CXXFLAGS += -fno-rtti -fno-exceptions
endif
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lcitro3d -lctru -lm
LIBDIRS := $(PORTLIBS) $(CTRULIB) ./lib
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
# Build Variable Setup
#---------------------------------------------------------------------------------
recurse = $(shell find $2 -type $1 -name '$3' 2> /dev/null)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(call recurse,f,$(dir),*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(call recurse,f,$(dir),*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(call recurse,f,$(dir),*.s)))
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(call recurse,f,$(dir),*.pica)))
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(PICAFILES:.v.pica=.shbin.o) \
$(SHLISTFILES:.shlist=.shbin.o) \
$(CPPFILES:.cpp=.o) \
$(CFILES:.c=.o) \
$(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) -I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir) $(call recurse,d,$(CURDIR)/$(dir),*)) $(foreach dir,$(DATA),$(CURDIR)/$(dir) $(call recurse,d,$(CURDIR)/$(dir),*))
export TOPDIR := $(CURDIR)
OUTPUT_DIR := $(TOPDIR)/$(OUTPUT)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
# Initial Targets
#---------------------------------------------------------------------------------
all: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
3dsx: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
cia: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
3ds: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
elf: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
citra: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
hblauncher: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
fbi: $(BUILD) $(OUTPUT_DIR)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $@
$(BUILD):
@[ -d $@ ] || mkdir -p $@
$(OUTPUT_DIR):
@[ -d $@ ] || mkdir -p $@
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
# Build Information Setup
#---------------------------------------------------------------------------------
DEPENDS := $(OFILES:.o=.d)
include $(TOPDIR)/$(APP_INFO)
APP_TITLE := $(shell echo "$(APP_TITLE)" | cut -c1-128)
APP_DESCRIPTION := $(shell echo "$(APP_DESCRIPTION)" | cut -c1-256)
APP_AUTHOR := $(shell echo "$(APP_AUTHOR)" | cut -c1-128)
APP_PRODUCT_CODE := $(shell echo $(APP_PRODUCT_CODE) | cut -c1-16)
APP_UNIQUE_ID := $(shell echo $(APP_UNIQUE_ID) | cut -c1-7)
APP_VER_MAJOR := $(shell echo $(APP_VER_MAJOR) | cut -c1-3)
APP_VER_MINOR := $(shell echo $(APP_VER_MINOR) | cut -c1-3)
APP_VER_MICRO := $(shell echo $(APP_VER_MICRO) | cut -c1-3)
ifneq ("$(wildcard $(TOPDIR)/$(BANNER_IMAGE).cgfx)","")
BANNER_IMAGE_FILE := $(TOPDIR)/$(BANNER_IMAGE).cgfx
BANNER_IMAGE_ARG := -ci $(BANNER_IMAGE_FILE)
else
BANNER_IMAGE_FILE := $(TOPDIR)/$(BANNER_IMAGE).png
BANNER_IMAGE_ARG := -i $(BANNER_IMAGE_FILE)
endif
ifneq ("$(wildcard $(TOPDIR)/$(BANNER_AUDIO).cwav)","")
BANNER_AUDIO_FILE := $(TOPDIR)/$(BANNER_AUDIO).cwav
BANNER_AUDIO_ARG := -ca $(BANNER_AUDIO_FILE)
else
BANNER_AUDIO_FILE := $(TOPDIR)/$(BANNER_AUDIO).wav
BANNER_AUDIO_ARG := -a $(BANNER_AUDIO_FILE)
endif
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
OUTPUT_NAME := $(subst $(SPACE),,$(APP_TITLE))
OUTPUT_DIR := $(TOPDIR)/$(OUTPUT)
OUTPUT_FILE := $(OUTPUT_DIR)/$(OUTPUT_NAME)
APP_ICON := $(TOPDIR)/$(ICON)
APP_ROMFS := $(TOPDIR)/$(ROMFS)
COMMON_MAKEROM_PARAMS := -rsf $(RSF) -target t -exefslogo -elf $(OUTPUT_FILE).elf -icon icon.icn -banner banner.bnr \
-DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(APP_PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(APP_UNIQUE_ID)" \
-DAPP_ROMFS="$(APP_ROMFS)" -DAPP_SYSTEM_MODE="64MB" -DAPP_SYSTEM_MODE_EXT="Legacy" -major "$(APP_VER_MAJOR)" \
-minor "$(APP_VER_MINOR)" -micro "$(APP_VER_MICRO)"
ifeq ($(OS),Windows_NT)
MAKEROM = makerom.exe
BANNERTOOL = bannertool.exe
else
MAKEROM = makerom
BANNERTOOL = bannertool
endif
_3DSXFLAGS += --smdh=$(OUTPUT_FILE).smdh
ifneq ("$(wildcard $(TOPDIR)/$(ROMFS))","")
_3DSXFLAGS += --romfs=$(TOPDIR)/$(ROMFS)
endif
#---------------------------------------------------------------------------------
# Main Targets
#---------------------------------------------------------------------------------
.PHONY: all 3dsx cia elf 3ds citra fbi hblauncher
all: $(OUTPUT_FILE).zip $(OUTPUT_FILE).3ds $(OUTPUT_FILE).cia
banner.bnr: $(BANNER_IMAGE_FILE) $(BANNER_AUDIO_FILE)
@$(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) $(BANNER_AUDIO_ARG) -o banner.bnr > /dev/null
icon.icn: $(TOPDIR)/$(ICON)
@$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_TITLE)" -p "$(APP_AUTHOR)" -i $(TOPDIR)/$(ICON) -o icon.icn > /dev/null
$(OUTPUT_FILE).elf: $(OFILES)
$(OUTPUT_FILE).3dsx: $(OUTPUT_FILE).elf $(OUTPUT_FILE).smdh
$(OUTPUT_FILE).3ds: $(OUTPUT_FILE).elf banner.bnr icon.icn
@$(MAKEROM) -f cci -o $(OUTPUT_FILE).3ds -DAPP_ENCRYPTED=true $(COMMON_MAKEROM_PARAMS)
@echo "built ... $(notdir $@)"
$(OUTPUT_FILE).cia: $(OUTPUT_FILE).elf banner.bnr icon.icn
@$(MAKEROM) -f cia -o $(OUTPUT_FILE).cia -DAPP_ENCRYPTED=false $(COMMON_MAKEROM_PARAMS)
@echo "built ... $(notdir $@)"
$(OUTPUT_FILE).zip: $(OUTPUT_FILE).smdh $(OUTPUT_FILE).3dsx
@cd $(OUTPUT_DIR); \
mkdir -p 3ds/$(OUTPUT_NAME); \
cp $(OUTPUT_FILE).3dsx 3ds/$(OUTPUT_NAME); \
cp $(OUTPUT_FILE).smdh 3ds/$(OUTPUT_NAME); \
zip -r $(OUTPUT_FILE).zip 3ds > /dev/null; \
rm -r 3ds
@echo "built ... $(notdir $@)"
3dsx : $(OUTPUT_FILE).3dsx
cia : $(OUTPUT_FILE).cia
3ds : $(OUTPUT_FILE).3ds
elf : $(OUTPUT_FILE).elf
citra : $(OUTPUT_FILE).3dsx
citra $(OUTPUT_FILE).3dsx
fbi : $(OUTPUT_FILE).cia
python ../buildtools/servefiles.py $(IP3DS) $(OUTPUT_FILE).cia
hblauncher : $(OUTPUT_FILE).3dsx
3dslink -a $(IP3DS) $(OUTPUT_FILE).3dsx
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
picasso -o $(CURBIN) $1
bin2s $(CURBIN) | $(AS) -o $@
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
endef
%.shbin.o : %.v.pica %.g.pica
@echo $(notdir $^)
@$(call shader-as,$^)
%.shbin.o : %.v.pica
@echo $(notdir $<)
@$(call shader-as,$<)
%.shbin.o : %.shlist
@echo $(notdir $<)
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------