-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfxmake
210 lines (143 loc) · 5.25 KB
/
gfxmake
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
#
# 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
GRIT := grit
# ---------------------------------------------------------------------
# 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
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
# Key exception variables
export GFXSPECIALS :=
OSPECIALS :=
# ---------------------------------------------------------------------
# BUILD FLAGS
# ---------------------------------------------------------------------
# Since there's not *code* to compile, we won't need optimizations,
# architectures etc.
CFLAGS :=
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS :=
# ---------------------------------------------------------------------
# BUILD PROCEDURE
# ---------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
# still in main directory.
export TARGET := $(CURDIR)/$(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
all : $(BUILD)
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET)
# ---------------------------------------------------------------------
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)) )
# ---------------------------------------------------------------------
# BASE CONVERSION RULES
# ---------------------------------------------------------------------
# --- With separate .grit file ---
%.s %.h : %.png %.grit
$(GRIT) $< -o$* -fts
%.s %.h : %.bmp %.grit
@$(GRIT) $< -o$* -fts
%.s %.h : %.pcx %.grit
@$(GRIT) $< -o$* -fts
%.s %.h : %.jpg %.grit
@$(GRIT) $< -o$* -fts
# --- Base gfx rules (without .grit) ---
# $(<D)/$(notdir $(<D)).grit evaluates to dirname/dirname.grit
%.s %.h : %.png
$(GRIT) $< -o$* -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.bmp
$(GRIT) $< -o$* -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.pcx
$(GRIT) $< -o$* -fts -ff $(<D)/$(notdir $(<D)).grit
%.s %.h : %.jpg
$(GRIT) $< -o$* -fts -ff $(<D)/$(notdir $(<D)).grit
# ---------------------------------------------------------------------
# SPECIAL RULES
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# FUNCTIONS
# ---------------------------------------------------------------------
## Merge all headers into a single large one for easier including.
## $1 : master path
## $2 : separate header paths
define master-header
echo -e "//\n// $(notdir $(strip $1))\n//" > $1
echo -e "// One header to rule them and in the darkness bind them" >> $1
echo -e "// Date: $(shell date +'%F %X' )\n" >> $1
echo -e "#ifdef __cplusplus\nextern \"C\" {\n#endif" >> $1
if [ $2 ]; then cat $2 >> $1 ; fi
echo -e "\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.
## $1: filepath
define title
$(basename $(notdir $1))
endef
## Get a valid C identifier for a name.
## $1: name
define cident
`echo $1 | sed -e 's|^\([0-9]\)|_\1| ; s|[./\\-]|_|g'`
endef
## Create a header file for a bin2s converted binary.
## $1: path
## $2: identifier
define bin-header
echo "extern const u32 $(strip $2)_size;" > $1
echo "extern const u8 $(strip $2)[];" >> $1
endef
# ---------------------------------------------------------------------
# DEPENDENCIES
# ---------------------------------------------------------------------
-include $(DEPENDS)
endif