-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgfxmake.mk
212 lines (143 loc) · 5.41 KB
/
gfxmake.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
#
# Making a gfx library from grit output
#
# For use on data-arrays only. NO CODE!!!
#
# ---------------------------------------------------------------------
# SETUP
# ---------------------------------------------------------------------
export PATH := $(DEVKITARM)/bin:$(PATH)
.SUFFIXES:
include $(DEVKITARM)/base_rules
# ---------------------------------------------------------------------
# (1) PROJECT DETAILS
# ---------------------------------------------------------------------
# GFXTITLE : Graphics library name
# BUILD : Directory for build process temporaries. Should NOT be empty!
# GFXDIRS : List of graphics directories
# GFXEXTS : Graphics extensions.
# General note: use . for the current dir, don't leave them empty.
BUILD := build
GFXDIRS := gfx/map gfx/sprites gfx/menus gfx/menu_sprites
GFXLIB ?= libgfx.a
GFXHDR ?= all_gfx.h
GFXEXTS := png bmp
# --- Exceptions ---
# Add files/file-variables for special rules here. Put the rules
# At the bottom of the makefile. Be careful with directories, as
# we'll be in $(BUILD) when converting.
# GFXSPECIALS : removed from GFXFILES
# OSPECIALS : added to OFILES
export SPRITES ?= $(notdir $(wildcard gfx/sprites/*.png))
export MENU_SPRITES ?= $(notdir $(wildcard gfx/menu_sprites/*.png))
# Key exception variables
export GFXSPECIALS := $(SPRITES) $(MENU_SPRITES)
OSPECIALS := sprites.o menu_sprites.o
# ---------------------------------------------------------------------
# BUILD FLAGS
# ---------------------------------------------------------------------
# Since there's no code to compile, we won't need optimizations,
# architectures etc.
CFLAGS :=
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS :=
# ---------------------------------------------------------------------
# (2) BUILD PROCEDURE
# ---------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
# still in main directory.
export TARGET := $(CURDIR)/$(BUILD)/$(GFXLIB)
export VPATH := $(foreach dir, $(GFXDIRS), $(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
GFXFILES := $(filter-out $(GFXSPECIALS), \
$(foreach dir, $(GFXDIRS), \
$(foreach ext, $(GFXEXTS), \
$(notdir $(wildcard $(dir)/*.$(ext))) \
)))
export OFILES := $(addsuffix .o, $(basename $(GFXFILES))) $(OSPECIALS)
# --- More targets ----------------------------------------------------
.PHONY: $(BUILD) clean
# --- Create BUILD if necessary, and run this makefile from there ---
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/gfxmake.mk
all : $(BUILD)
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET) $(GFXHDR)
# ---------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
.PHONY : all
all : $(TARGET) $(GFXHDR)
$(TARGET) : $(OFILES)
@echo Archiving into $(notdir $@)
-@rm -f $@
@$(AR) rcs $@ $(OFILES)
$(GFXHDR) : $(OFILES)
@echo "Creating master header: $@"
@$(call master-header, $@, $(notdir $(^:.o=.h)) )
# ---------------------------------------------------------------------
# (3) BASE CONVERSION RULES
# ---------------------------------------------------------------------
# --- With separate .grit file ---
%.s %.h : %.png %.grit
grit $< -fts
%.s %.h : %.bmp %.grit
grit $< -fts
%.s %.h : %.pcx %.grit
grit $< -fts
%.s %.h : %.jpg %.grit
grit $< -fts
# --- Without .grit file ; uses dirname/dirname.grit for options ---
%.s %.h : %.png
grit $< -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.bmp
grit $< -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.pcx
grit $< -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.jpg
grit $< -fts -ff $(<D)/$(notdir $(<D)).grit
# ---------------------------------------------------------------------
# (4) SPECIAL RULES
# ---------------------------------------------------------------------
sprites.s sprites.h : sprites.grit $(SPRITES)
@echo $(notdir $^)
grit $(sort $(filter %.png,$^)) -o$@ -ff $<
menu_sprites.s menu_sprites.h : sprites.grit $(MENU_SPRITES)
@echo $(notdir $^)
grit $(sort $(filter %.png,$^)) -o$@ -ff $<
# ---------------------------------------------------------------------
# (5) UTILITY FUNCTIONS
# ---------------------------------------------------------------------
## Merge all headers into a single large one for easier including.
define master-header # $1 : master path, $2 separate header paths
echo "//\n// $(notdir $(strip $1))\n//" > $1
echo "// One header to rule them and in the darkness bind them" >> $1
echo "// Date: $(shell date +'%F %X' )\n" >> $1
echo "#ifdef __cplusplus\nextern \"C\" {\n#endif" >> $1
cat $2 >> $1
echo "\n#ifdef __cplusplus\n};\n#endif\n" >> $1
endef
## if you just want to include the separate headers, use this instead of cat:
# for hdr in $2 ; \
# do echo -e "#include \"$$hdr\"" >> $1 ; done;
# --- odds and ends ---
## Get the title-part of filename.
define title # $1: filepath
$(basename $(notdir $1))
endef
## Get a valid C identifier for a name.
define cident # $1: name
`echo $1 | sed -e 's|^\([0-9]\)|_\1| ; s|[./\\-]|_|g'`
endef
## Create a header file for a bin2s converted binary.
define bin-header # $1: path, $2: identifier
echo "extern const u32 $(strip $2)_size;" > $1
echo "extern const u8 $(strip $2)[];" >> $1
endef
# ---------------------------------------------------------------------
# DEPENDENCIES
# ---------------------------------------------------------------------
-include $(DEPENDS)
endif