-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
242 lines (184 loc) · 7.84 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
# 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 = ../../gbdk2020/gbdk-2020-git/build/gbdk/
endif
ZIP = zip
LCC = $(GBDK_HOME)bin/lcc
PNG2ASSET = $(GBDK_HOME)/bin/png2asset
VERSION=1.1.1
# Configure platform specific LCC flags here:
LCCFLAGS_gb = -Wl-yt0x1B -autobank # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT)
LCCFLAGS_pocket = -Wl-yt0x1B -autobank # Usually the same as required for .gb
LCCFLAGS_duck = -Wl-yt0x1B -autobank # Usually the same as required for .gb
LCCFLAGS_gbc = -Wl-yt0x1B -Wm-yc -autobank # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive)
LCCFLAGS_sms =
LCCFLAGS_gg =
LCCFLAGS_nes = -autobank
# Alternate cartridges 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
# Set ROM Title / Name
# Title that generates a Grey CGB palette (id:0x16 -> checksum 0x58)
# "123456789012345"
LCCFLAGS_gb += -Wm-yn"BOUNCENLAVALAMP" # sum(hex) = 0x458 & 0xFF = checksum 0x58
# Set CGB Boot ROM color palette to 0x13 (relies on title settings above)
# 1. Old Licensee is already 0x33 -> Use New Licensee
# 2. Sets New Licensee to "01" "(Nintendo)
# 3. (Calculated by Sum of ROM Header title bytes 0x134 through 0x142 [excluding cgb flag at 0x143]) & 0xFF = checksum val 0xNN -> CGB Boot Pal X
# Legal chars are from 0x20 - 0x5F
# https://gbdev.io/pandocs/Power_Up_Sequence.html#compatibility-palettes
# https://tcrf.net/Notes:Game_Boy_Color_Bootstrap_ROM#Manual_Select_Palette_Configurations
LCCFLAGS_gb += -Wm-yk01
### Handle cart specific flags
# MBC5 - *NO* Rumble
ifeq ($(CART_TYPE),mbc5)
TARGETS=gb pocket
LCCFLAGS_gb += -Wl-yt0x1B -Wl-ya1 # Set an MBC for banking:0x1B MBC-5 SRAM BATTERY 8 MB
LCCFLAGS_pocket += -Wl-yt0x1B -Wl-ya1 # Same as for .gb
CART_TYPE_INC_DIR = mbc5
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
CART_TYPE_INC_DIR = 31k_1kflash
endif
# Generic 32 Cart with no save support
ifeq ($(CART_TYPE),32k_nosave)
TARGETS=gb pocket megaduck
CART_TYPE_INC_DIR = 32k_nosave
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
LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -Wb-ext=.rel -Wb-v # MBC + Autobanking related flags
# GBDK_DEBUG = ON
ifdef GBDK_DEBUG
LCCFLAGS += -debug -v
endif
CFLAGS = -Wf-MMD -Wf-Wp-MP # Header file dependency output (-MMD) for Makefile use + per-header Phoney rules (-MP)
# Pass in defined cart type
CFLAGS += -DCART_$(CART_TYPE)
# Add include path for type of flash cart if enabled
CFLAGS += -Wf-I"$(CART_TYPE_DIR)/"
# Higher optimization setting for compiler
# Can save maybe 2k (allocs=100000) to 8K (allocs=1000000) cycles in the C version
# CFLAGS += -Wf--max-allocs-per-node100000
# CFLAGS += -Wf--max-allocs-per-node1000000
# You can set the name of the ROM file here
PROJECTNAME = breakout-lavalamp_$(VERSION)_$(CART_TYPE)
# EXT?=gb # Only sets extension to default (game boy .gb) if not populated
SRCDIR = src
OBJDIR = obj/$(EXT)/$(CART_TYPE)
RESOBJSRC = obj/$(EXT)/$(CART_TYPE)/res
RESDIR = res
BUILD_DIR = build
BINDIR = $(BUILD_DIR)/$(EXT)
CART_TYPE_DIR = $(SRCDIR)/cart_$(CART_TYPE_INC_DIR)
PACKAGE_DIR = package
PACKAGE_ZIP_FILE = $(PACKAGE_DIR)/breakout_lavalamp_ROMs_$(VERSION).zip
MKDIRS = $(OBJDIR) $(BINDIR) $(RESOBJSRC) $(PACKAGE_DIR) # See bottom of Makefile for directory auto-creation
OUTPUT_NAME = $(BINDIR)/$(PROJECTNAME).$(EXT)
ZIP_OUTPUT_NAME = $(EXT)/$(PROJECTNAME).$(EXT) # BUILD dir stripped off so it gets included as a folder in zip file
BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT)
CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c)))
ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s)))
OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o)
CSOURCES_CART = $(foreach dir,$(CART_TYPE_DIR),$(notdir $(wildcard $(dir)/*.c)))
OBJS += $(CSOURCES_CART:%.c=$(OBJDIR)/%.o)
OBJS += $(ASMSOURCES_CART:%.s=$(OBJDIR)/%.o)
# For png2asset: converting PNG source pngs -> .c -> .o
PNGS = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.png)))
PNGSRCS = $(PNGS:%.png=$(RESOBJSRC)/%.c)
PNGOBJS = $(PNGSRCS:$(RESOBJSRC)/%.c=$(OBJDIR)/%.o)
.PRECIOUS: $(PNGSRCS)
# .PRECIOUS: $(PNGSRCS)
CFLAGS += -I$(OBJDIR)
# Builds all targets sequentially
all: $(TARGETS)
# Use png2asset to convert the png into C formatted data
# -c ... : Set C output file
# Convert metasprite .pngs in res/ -> .c files in obj/<platform ext>/src/
.SECONDEXPANSION:
$(RESOBJSRC)/%.c: $(RESDIR)/%.png $$(wildcard $(RESDIR)/%.png.meta)
$(PNG2ASSET) $< `cat <$<.meta 2>/dev/null` -c $@
# Compile the pngs that were converted to .c files
# .c files in obj/<platform ext>/src/ -> .o files in obj/
$(OBJDIR)/%.o: $(RESOBJSRC)/%.c
$(LCC) $(LCCFLAGS) $(CFLAGS) -c -o $@ $<
# Dependencies (using output from -Wf-MMD -Wf-Wp-MP)
DEPS = $(OBJS:%.o=%.d)
-include $(DEPS)
# Compile .c files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(LCC) $(LCCFLAGS) $(CFLAGS) -c -o $@ $<
# Compile .c files in "res/" to .o object files
$(OBJDIR)/%.o: $(RESDIR)/%.c
$(LCC) $(LCCFLAGS) $(CFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.s
$(LCC) $(LCCFLAGS) $(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) $(LCCFLAGS) $(CFLAGS) -S -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 $@ $<
# Convert and build png image data first so they're available when compiling the main sources
$(OBJS): $(PNGOBJS)
# Link the compiled object files into a .gb ROM file
$(BINS): $(OBJS)
$(LCC) $(LCCFLAGS) $(CFLAGS) -o $(OUTPUT_NAME) $(PNGOBJS) $(OBJS)
# Optional Packaging
# - at start of line ignores error code for zip, which returns non-success if file was already "up to date"
# -j removes paths
ifdef ADD_ZIP
-cd $(BUILD_DIR); $(ZIP) -u ../$(PACKAGE_ZIP_FILE) $(ZIP_OUTPUT_NAME)
endif
clean:
@echo Cleaning
@for target in $(TARGETS); do \
$(MAKE) $$target-clean; \
done
carts:
# ${MAKE} CART_TYPE=31k_1kflash
${MAKE} CART_TYPE=mbc5
${MAKE} CART_TYPE=32k_nosave
carts-clean:
# ${MAKE} CART_TYPE=31k_1kflash clean
${MAKE} CART_TYPE=mbc5 clean
${MAKE} CART_TYPE=32k_nosave clean
package: zip-carts
zip-carts:
# ${MAKE} ADD_ZIP=YES CART_TYPE=31k_1kflash
${MAKE} ADD_ZIP=YES CART_TYPE=mbc5
${MAKE} ADD_ZIP=YES CART_TYPE=32k_nosave
-$(ZIP) -u $(PACKAGE_ZIP_FILE) README.md
# -j junk path
-$(ZIP) -j -u $(PACKAGE_ZIP_FILE) info/Which\ ROM\ File\ To\ Use.txt
# -$(ZIP) -j -u $(PACKAGE_ZIP_FILE) info/Changelog.md
# 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