Skip to content

Commit d5d9b2b

Browse files
committed
Rewrite system-font example with citro2d
1 parent d779db0 commit d5d9b2b

File tree

3 files changed

+101
-242
lines changed

3 files changed

+101
-242
lines changed

graphics/printing/system-font/Makefile

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3236
SOURCES := source
3337
DATA := data
3438
INCLUDES := 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
5057
ASFLAGS := -g $(ARCH)
5158
LDFLAGS = -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)
7077
export TOPDIR := $(CURDIR)
7178

7279
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
80+
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
7381
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
7482

7583
export DEPSDIR := $(CURDIR)/$(BUILD)
@@ -79,6 +87,7 @@ CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
7987
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
8088
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
8189
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
90+
GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
8291
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
8392

8493
#---------------------------------------------------------------------------------
@@ -95,21 +104,28 @@ else
95104
endif
96105
#---------------------------------------------------------------------------------
97106

107+
export T3XFILES := $(GFXFILES:.t3s=.t3x)
108+
98109
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
99110

100111
export 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

103115
export 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

107121
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
108122
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
109123
-I$(CURDIR)/$(BUILD)
110124

111125
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
112126

127+
export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh)
128+
113129
ifeq ($(strip $(ICON)),)
114130
icons := $(wildcard *.png)
115131
ifneq (,$(findstring $(TARGET).png,$(icons)))
@@ -131,13 +147,11 @@ ifneq ($(ROMFS),)
131147
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
132148
endif
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
#---------------------------------------------------------------------------------
150164
else
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
#---------------------------------------------------------------------------------
178192
define 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
185201
endef
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
#---------------------------------------------------------------------------------------
194224
endif

0 commit comments

Comments
 (0)