forked from ZetaTwo/gb-wordle
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
273 lines (207 loc) · 8.6 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
# If you move this project you can change the directory
# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/"
ifndef GBDK_HOME
GBDK_HOME = ~/git/gbdev/gbdk2020/gbdk-2020-git/build/gbdk/
endif
LCC = $(GBDK_HOME)bin/lcc
VERSION=1.0.5
# Alternate languages can be passed in as follows
# de en es fr it nl pt-br
# make LANG_CODE=<lang code>
ifndef LANG_CODE
LANG_CODE=en
endif
# Alternate languages can be passed in as follows
# - 32k_nosave
# - 31k_1kflash
# - mbc5
# make CART_TYPE=<cart type>
ifndef CART_TYPE
# CART_TYPE=32k_nosave
CART_TYPE=mbc5
# CART_TYPE=31k_1kflash
endif
CFLAGS += -DLANG_CODE=$(LANG_CODE)
CFLAGS += -DCART_$(CART_TYPE)
# CFLAGS += -Wf--max-allocs-per-node50000
# CFLAGS += -Wf--max-allocs-per-node150000 # diminishing (but present) size returns after this
# CFLAGS += -Wf--max-allocs-per-node500000
# CFLAGS += -Wf--opt-code-size # This doesn't shrink code size much vs -Wf--max-allocs-per-node150000
# Configure platform specific LCC flags here:
LCCFLAGS_gb = -Wm-yc # Color No MBC Wl-yt0x1B # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT)
LCCFLAGS_pocket = -Wm-yc # No MBC -Wl-yt0x1B # Usually the same as required for .gb
LCCFLAGS_duck = # No MBC -Wl-yt0x1B # Usually the same as required for .gb
LCCFLAGS_gbc = # No MBC -Wl-yt0x1B -Wm-yc # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive)
LCCFLAGS_sms =
LCCFLAGS_gg =
### Handle cart specific flags
ifeq ($(CART_TYPE),mbc5)
TARGETS=gb pocket
LCCFLAGS_gb += -Wl-yt0x1B -Wl-ya1 # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT)
LCCFLAGS_pocket += -Wl-yt0x1B -Wl-ya1 # Same as for .gb
endif
# 31K+1k cart loses 1024 bytes at the end for flash storage
ifeq ($(CART_TYPE),31k_1kflash)
# No reason to build .pocket for the 31K + 1k flash cart
TARGETS=gb
# Add the flash 1K region as an exclusive no-use area for rom usage calcs
ROMUSAGE_flags = -e:FLASH_SAVE:7C00:400
endif
# Generic 32 Cart with no save support
ifeq ($(CART_TYPE),32k_nosave)
TARGETS=gb pocket megaduck
endif
# Targets can be forced with this override, but normally they will be controlled per-cart type above
#
# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets)
# They can also be built/cleaned individually: "make gg" and "make gg-clean"
# Possible are: gb gbc pocket megaduck sms gg
# TARGETS=gb pocket
LCCFLAGS += $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags
# Super Game Boy (border) support (only for GB/AP targets, save ROM space otherwise)
ifeq ($(PLAT),gb)
LCCFLAGS += -Wm-ys
else ifeq ($(PLAT),ap)
LCCFLAGS += -Wm-ys
endif
# Set ROM name (11 chars max in CGB land)
LCCFLAGS += -Wm-yn"GB-WORDYL"
# No autobanking needed for 32k ROM
# LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -autobank -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags
LCCFLAGS += -debug # Uncomment to enable debug output
# LCCFLAGS += -v # Uncomment for lcc verbose output
# You can set the name of the ROM file here
PROJECTNAME = gb-wordyl_$(VERSION)_$(CART_TYPE)_$(LANG_CODE)
CFLAGS += -debug
CFLAGS += -Wf-MMD -Wf-Wp-MP
# Add include path for type of flash cart if enabled
CFLAGS += -Wf-I"$(CART_TYPE_DIR)/"
# Add language directory to include path
CFLAGS += -Wf-I"$(LANGDIR)/"
# Code size improvements continue to show up to 250000
# 15000 seems to balance code size improvements vs compile time
# CFLAGS += -Wf--max-allocs-per-node15000
# EXT?=gb # Only sets extension to default (game boy .gb) if not populated
SRCDIR = src
SFXDIR = $(SRCDIR)/sfx
LANGDIR = $(SRCDIR)/lang_$(LANG_CODE)
CART_TYPE_DIR = $(SRCDIR)/cart_$(CART_TYPE)
SGBDIR = $(SRCDIR)/sgb
MEGADUCK_LAPTOP = $(SRCDIR)/megaduck_laptop
OBJDIR = obj/$(EXT)/$(CART_TYPE)_$(LANG_CODE)
RESDIR = res
BINDIR = build/$(EXT)
MKDIRS = $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation
BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT)
CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c)))
CSOURCES += $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c)))
CSOURCES += $(foreach dir,$(SFXDIR),$(notdir $(wildcard $(dir)/*.c)))
# Super Game Boy (border) support only for GB/AP targets, save ROM space otherwise
ifeq ($(PLAT),gb)
CSOURCES += $(foreach dir,$(SGBDIR),$(notdir $(wildcard $(dir)/*.c)))
else ifeq ($(PLAT),ap)
CSOURCES += $(foreach dir,$(SGBDIR),$(notdir $(wildcard $(dir)/*.c)))
endif
# Extra sources when building MegaDuck laptop
ifeq ($(PLAT),duck)
CSOURCES += $(foreach dir,$(MEGADUCK_LAPTOP),$(notdir $(wildcard $(dir)/*.c)))
endif
CSOURCES_LANG = $(foreach dir,$(LANGDIR),$(notdir $(wildcard $(dir)/*.c)))
CSOURCES_CART = $(foreach dir,$(CART_TYPE_DIR),$(notdir $(wildcard $(dir)/*.c)))
ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s)))
ASMSOURCES_CART = $(foreach dir,$(CART_TYPE_DIR),$(notdir $(wildcard $(dir)/*.s)))
OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o)
OBJS += $(CSOURCES_LANG:%.c=$(OBJDIR)/%.o)
OBJS += $(CSOURCES_CART:%.c=$(OBJDIR)/%.o)
OBJS += $(ASMSOURCES:%.s=$(OBJDIR)/%.o)
OBJS += $(ASMSOURCES_CART:%.s=$(OBJDIR)/%.o)
# Builds all targets sequentially
all: $(TARGETS)
# Dependencies
DEPS = $(OBJS:%.o=%.d)
-include $(DEPS)
# Compile .c files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "res/" to .o object files
$(OBJDIR)/%.o: $(RESDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/sfx/" to .o object files
$(OBJDIR)/%.o: $(SFXDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/sgb/" to .o object files
$(OBJDIR)/%.o: $(SGBDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/megaduck_laptop/" to .o object files
$(OBJDIR)/%.o: $(MEGADUCK_LAPTOP)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/<LANG_CODE>/" to .o object files
$(OBJDIR)/%.o: $(LANGDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/<CART_TYPE_DIR>/" to .o object files
$(OBJDIR)/%.o: $(CART_TYPE_DIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/" to .o object files
$(OBJDIR)/%.o: $(CART_TYPE_DIR)/%.s
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.s
$(LCC) $(CFLAGS) -c -o $@ $<
# If needed, compile .c files in "src/" to .s assembly files
# (not required if .c is compiled directly to .o)
$(OBJDIR)/%.s: $(SRCDIR)/%.c
$(LCC) $(CFLAGS) -S -o $@ $<PROJECTNAME
# Link the compiled object files into a .gb ROM file
$(BINS): $(OBJS)
$(LCC) $(LCCFLAGS) $(CFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(OBJS)
langs:
${MAKE} LANG_CODE=de CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=en CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=es CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=fr CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=it CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=nl CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=la CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=pt-br CART_TYPE=$(CART_TYPE)
${MAKE} LANG_CODE=kw CART_TYPE=$(CART_TYPE)
# PT full answer file is too big
# ${MAKE} LANG_CODE=pt
langs-clean:
${MAKE} clean LANG_CODE=de CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=en CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=es CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=fr CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=it CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=nl CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=la CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=pt-br CART_TYPE=$(CART_TYPE)
${MAKE} clean LANG_CODE=kw CART_TYPE=$(CART_TYPE)
# PT full answer file is too big
# ${MAKE} LANG_CODE=pt
carts:
${MAKE} CART_TYPE=31k_1kflash langs
${MAKE} CART_TYPE=mbc5 langs
${MAKE} CART_TYPE=32k_nosave langs
carts-clean:
${MAKE} CART_TYPE=31k_1kflash langs-clean
${MAKE} CART_TYPE=mbc5 langs-clean
${MAKE} CART_TYPE=32k_nosave langs-clean
dictionaries: langs-compress
langs-compress:
make -C compress compress-all-langs
romusage:
# Ignores failure if romusage not in path
-romusage build/gb/gb-wordyl_$(VERSION)_$(CART_TYPE)_$(LANG_CODE).noi $(ROMUSAGE_flags) -e:STACK:DEFF:100 -e:SHADOW_OAM:C000:A0
-romusage build/gb/gb-wordyl_$(VERSION)_$(CART_TYPE)_$(LANG_CODE).noi $(ROMUSAGE_flags) -e:STACK:DEFF:100 -e:SHADOW_OAM:C000:A0 > romusage.txt
clean:
@echo Cleaning
@for target in $(TARGETS); do \
$(MAKE) $$target-clean; \
done
# Include available build targets
include Makefile.targets
# create necessary directories after Makefile is parsed but before build
# info prevents the command from being pasted into the makefile
ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target
$(info $(shell mkdir -p $(MKDIRS)))
endif