@@ -15,6 +15,10 @@ include $(DEVKITARM)/3ds_rules
1515# SOURCES is a list of directories containing source code
1616# DATA is a list of directories containing data files
1717# INCLUDES is a list of directories containing header files
18+ # GRAPHICS is a list of directories containing graphics files
19+ # GFXBUILD is the directory where converted graphics files will be placed
20+ # If set to $(BUILD), it will statically link in the converted
21+ # files as if they were data files.
1822#
1923# NO_SMDH: if set to anything, no SMDH file is generated.
2024# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
@@ -32,7 +36,10 @@ BUILD := build
3236SOURCES := source
3337DATA := data
3438INCLUDES := include
39+ GRAPHICS := gfx
40+ GFXBUILD := $(BUILD )
3541# ROMFS := romfs
42+ # GFXBUILD := $(ROMFS)/gfx
3643
3744# ---------------------------------------------------------------------------------
3845# options for code generation
@@ -50,7 +57,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
5057ASFLAGS := -g $(ARCH )
5158LDFLAGS = -specs=3dsx.specs -g $(ARCH ) -Wl,-Map,$(notdir $* .map)
5259
53- LIBS := -lcitro3d -lctru -lm
60+ LIBS := -lcitro2d - lcitro3d -lctru -lm
5461
5562# ---------------------------------------------------------------------------------
5663# list of directories containing libraries, this must be the top level containing
@@ -70,6 +77,7 @@ export OUTPUT := $(CURDIR)/$(TARGET)
7077export TOPDIR := $(CURDIR )
7178
7279export VPATH := $(foreach dir,$(SOURCES ) ,$(CURDIR ) /$(dir ) ) \
80+ $(foreach dir,$(GRAPHICS ) ,$(CURDIR ) /$(dir ) ) \
7381 $(foreach dir,$(DATA ) ,$(CURDIR ) /$(dir ) )
7482
7583export DEPSDIR := $(CURDIR ) /$(BUILD )
@@ -79,6 +87,7 @@ CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
7987SFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .s) ) )
8088PICAFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .v.pica) ) )
8189SHLISTFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .shlist) ) )
90+ GFXFILES := $(foreach dir,$(GRAPHICS ) ,$(notdir $(wildcard $(dir ) /* .t3s) ) )
8291BINFILES := $(foreach dir,$(DATA ) ,$(notdir $(wildcard $(dir ) /* .* ) ) )
8392
8493# ---------------------------------------------------------------------------------
@@ -95,21 +104,28 @@ else
95104endif
96105# ---------------------------------------------------------------------------------
97106
107+ export T3XFILES := $(GFXFILES:.t3s=.t3x )
108+
98109export OFILES_SOURCES := $(CPPFILES:.cpp=.o ) $(CFILES:.c=.o ) $(SFILES:.s=.o )
99110
100111export OFILES_BIN := $(addsuffix .o,$(BINFILES ) ) \
101- $(PICAFILES:.v.pica=.shbin.o ) $(SHLISTFILES:.shlist=.shbin.o )
112+ $(PICAFILES:.v.pica=.shbin.o ) $(SHLISTFILES:.shlist=.shbin.o ) \
113+ $(if $(filter $(BUILD ) ,$(GFXBUILD ) ) ,$(addsuffix .o,$(T3XFILES ) ) )
102114
103115export OFILES := $(OFILES_BIN ) $(OFILES_SOURCES )
104116
105- export HFILES := $(PICAFILES:.v.pica=_shbin.h ) $(addsuffix .h,$(subst .,_,$(BINFILES ) ) )
117+ export HFILES := $(PICAFILES:.v.pica=_shbin.h ) $(SHLISTFILES:.shlist=_shbin.h ) \
118+ $(addsuffix .h,$(subst .,_,$(BINFILES ) ) ) \
119+ $(GFXFILES:.t3s=.h )
106120
107121export INCLUDE := $(foreach dir,$(INCLUDES ) ,-I$(CURDIR ) /$(dir ) ) \
108122 $(foreach dir,$(LIBDIRS ) ,-I$(dir ) /include) \
109123 -I$(CURDIR ) /$(BUILD )
110124
111125export LIBPATHS := $(foreach dir,$(LIBDIRS ) ,-L$(dir ) /lib)
112126
127+ export _3DSXDEPS := $(if $(NO_SMDH ) ,,$(OUTPUT ) .smdh)
128+
113129ifeq ($(strip $(ICON ) ) ,)
114130 icons := $(wildcard *.png)
115131 ifneq (,$(findstring $(TARGET).png,$(icons)))
@@ -131,13 +147,11 @@ ifneq ($(ROMFS),)
131147 export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
132148endif
133149
134- .PHONY : $( BUILD ) clean all
150+ .PHONY : all clean
135151
136152# ---------------------------------------------------------------------------------
137- all : $(BUILD )
138-
139- $(BUILD ) :
140- @[ -d $@ ] || mkdir -p $@
153+ all :
154+ @mkdir -p $(BUILD ) $(GFXBUILD )
141155 @$(MAKE ) --no-print-directory -C $(BUILD ) -f $(CURDIR ) /Makefile
142156
143157# ---------------------------------------------------------------------------------
@@ -149,16 +163,10 @@ clean:
149163# ---------------------------------------------------------------------------------
150164else
151165
152- DEPENDS := $(OFILES:.o=.d )
153-
154166# ---------------------------------------------------------------------------------
155167# main targets
156168# ---------------------------------------------------------------------------------
157- ifeq ($(strip $(NO_SMDH ) ) ,)
158- $(OUTPUT ) .3dsx : $(OUTPUT ) .elf $(OUTPUT ) .smdh
159- else
160- $(OUTPUT ) .3dsx : $(OUTPUT ) .elf
161- endif
169+ $(OUTPUT ) .3dsx : $(OUTPUT ) .elf $(_3DSXDEPS )
162170
163171$(OFILES_SOURCES ) : $(HFILES )
164172
@@ -172,23 +180,45 @@ $(OUTPUT).elf : $(OFILES)
172180 @echo $(notdir $<)
173181 @$(bin2o)
174182
183+ # ---------------------------------------------------------------------------------
184+ .PRECIOUS : % .t3x
185+ % .t3x.o % _t3x.h : % .t3x
186+ # ---------------------------------------------------------------------------------
187+ @$(bin2o)
188+
175189# ---------------------------------------------------------------------------------
176190# rules for assembling GPU shaders
177191# ---------------------------------------------------------------------------------
178192define shader-as
179193 $(eval CURBIN := $* .shbin)
194+ $(eval DEPSFILE := $(DEPSDIR ) /$* .shbin.d)
195+ echo "$(CURBIN ) .o: $< $1" > $(DEPSFILE )
180196 echo "extern const u8" `(echo $(CURBIN ) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN ) | tr . _)`.h
181197 echo "extern const u8" `(echo $(CURBIN ) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN ) | tr . _)`.h
182198 echo "extern const u32" `(echo $(CURBIN ) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN ) | tr . _)`.h
183199 picasso -o $(CURBIN ) $1
184200 bin2s $(CURBIN ) | $(AS ) -o $* .shbin.o
185201endef
186202
203+ % .shbin.o % _shbin.h : % .v.pica % .g.pica
204+ @echo $(notdir $^ )
205+ @$(call shader-as,$^ )
206+
187207% .shbin.o % _shbin.h : % .v.pica
188208 @echo $(notdir $< )
189209 @$(call shader-as,$< )
190210
191- -include $(DEPENDS )
211+ % .shbin.o % _shbin.h : % .shlist
212+ @echo $(notdir $< )
213+ @$(call shader-as,$(foreach file,$(shell cat $< ) ,$(dir $< )$(file ) ) )
214+
215+ # ---------------------------------------------------------------------------------
216+ % .t3x % .h : % .t3s
217+ # ---------------------------------------------------------------------------------
218+ @echo $(notdir $<)
219+ @tex3ds -i $< -H $*.h -d $*.d -o $(TOPDIR)/$(GFXBUILD)/$*.t3x
220+
221+ -include $(DEPSDIR ) /*.d
192222
193223# ---------------------------------------------------------------------------------------
194224endif
0 commit comments