-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
204 lines (147 loc) · 7.61 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
SHELL := /bin/bash
# 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 = ../../../gbdk-2020/build/gbdk/
endif
GBDK_HOME_UNIX := $(subst ',,$(subst \,/,'$(GBDK_HOME)'))
ifndef PYTHON
PYTHON = python
endif
LCC = $(GBDK_HOME_UNIX)/bin/lcc
PNG2ASSET = $(GBDK_HOME_UNIX)/bin/png2asset
# 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 sms gg
#TARGETS = gb gbc pocket sms gg megaduck
#TARGETS = gb gbc
TARGETS = gbc megaduck
LIBRARIES =
# Configure platform specific LCC flags here:
LCCFLAGS_gb = $(LIBRARIES) -Wm-ys -Wl-yt0xFC -Wm-yn"$(PROJECTNAME)"
LCCFLAGS_gbc = $(LIBRARIES) -Wm-ys -Wm-yc -Wl-yt0xFC -Wm-yn"$(PROJECTNAME)"
LCCFLAGS_duck = $(LIBRARIES) -Wl-yt0xFC
LCCFLAGS_sms =
LCCFLAGS_gg =
LCCFLAGS += -m$(PORT):$(PLAT) $(LCCFLAGS_$(EXT)) -Wm-yS # This adds the current platform specific LCC Flags
LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya16 -autobank -Wb-ext=.rel
# LCCFLAGS += -debug # Uncomment to enable debug output
# LCCFLAGS += -v # Uncomment for lcc verbose output
CFLAGS = -Iinclude -Iinclude/$(PORT) -Iinclude/$(PLAT) -I$(RESDIR) -Iobj/$(EXT) -Wf'--disable-warning 110'
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
VERSION = $(shell cat version)
COMMIT = $(shell git rev-parse --short HEAD)
CFLAGS += -DBRANCH=$(BRANCH) -DVERSION=$(VERSION) -DCOMMIT=$(COMMIT)
# Optimization
#CFLAGS += -Wf'--max-allocs-per-node 50000'
# You can set the name of the ROM file here
PROJECTNAME = photo
# EXT?=gb # Only sets extension to default (game boy .gb) if not populated
SRCDIR = src
SRCPORT = src/$(PORT)
SRCPLAT = src/$(PLAT)
OBJDIR = obj/$(EXT)
RESDIR = res
BINDIR = build/$(EXT)
MKDIRS = $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation
# list of files that are always built
ALWAYS = $(SRCDIR)/menu_debug.c $(SRCDIR)/menu_main.c $(SRCDIR)/state_logo.c
# binaries list
BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT)
# resources
VGM_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/audio/$(PLAT)/sounds/*.vgm)))
FX_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/audio/$(PLAT)/sounds/*.sav)))
UGE_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/audio/$(PLAT)/music/*.uge)))
WAV_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/audio/$(PLAT)/waveforms/*.wav)))
FONT_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/gfx/$(PLAT)/fonts/*.png)))
SPR_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/gfx/$(PLAT)/sprites/*.png)))
BKG_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/gfx/$(PLAT)/backgrounds/*.png)))
DATA_RES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/data/*.bin)))
# C and ASM sources
CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(SRCPLAT),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(SRCPORT),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/audio/$(PLAT)/*.c))) $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/menus/*.c))) $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/overlays/*.c)))
ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) $(foreach dir,$(SRCPLAT),$(notdir $(wildcard $(dir)/*.s))) $(foreach dir,$(SRCPORT),$(notdir $(wildcard $(dir)/*.s)))
OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o)
RESOBJ = $(VGM_RES:%.vgm=$(OBJDIR)/%.o) $(WAV_RES:%.wav=$(OBJDIR)/%.o) $(FX_RES:%.sav=$(OBJDIR)/%.o) $(UGE_RES:%.uge=$(OBJDIR)/%.o) $(FONT_RES:%.png=$(OBJDIR)/%.o) $(SPR_RES:%.png=$(OBJDIR)/%.o) $(BKG_RES:%.png=$(OBJDIR)/%.o) $(DATA_RES:%.bin=$(OBJDIR)/%.o)
DEPENDANT = $(CSOURCES:%.c=$(OBJDIR)/%.o)
# Builds all targets sequentially
all: $(TARGETS) remote
# Dependencies
DEPS = $(DEPENDANT:%.o=%.d)
-include $(DEPS)
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/audio/$(PLAT)/sounds/%.vgm $$(wildcard $(RESDIR)/audio/$(PLAT)/sounds/%.vgm.meta)
$(PYTHON) utils/vgm2data.py -5 -w -3 -d 4 `cat <$<.meta 2>/dev/null` -o $@ $<
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/audio/$(PLAT)/sounds/%.sav $$(wildcard $(RESDIR)/audio/$(PLAT)/sounds/%.sav.meta)
$(PYTHON) utils/fxhammer2data.py -d 4 -c `cat <$<.meta 2>/dev/null` -o $@ $<
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/audio/$(PLAT)/music/%.uge $$(wildcard $(RESDIR)/audio/$(PLAT)/music/%.uge.meta)
utils/uge2source $< `cat <$<.meta 2>/dev/null` $(basename $(notdir $<)) $@
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/audio/$(PLAT)/waveforms/%.wav $$(wildcard $(RESDIR)/audio/$(PLAT)/waveforms/%.wav.meta)
$(PYTHON) utils/wav2data.py `cat <$<.meta 2>/dev/null` -o $@ $<
.SECONDEXPANSION:
$(OBJDIR)/%.o: $(RESDIR)/data/%.bin $$(wildcard $(RESDIR)/data/%.bin.meta)
$(PYTHON) utils/bin2obj.py `cat <$<.meta 2>/dev/null` -o $@ $<
$(OBJDIR)/%.o: $(RESDIR)/audio/$(PLAT)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/gfx/$(PLAT)/fonts/%.png $$(wildcard $(RESDIR)/gfx/$(PLAT)/fonts/%.png.meta)
$(PYTHON) utils/png2font.py `cat <$<.meta 2>/dev/null` -o $@ $<
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/gfx/$(PLAT)/sprites/%.png $$(wildcard $(RESDIR)/gfx/$(PLAT)/sprites/%.png.meta)
$(PNG2ASSET) $< -c $@ `cat <$<.meta 2>/dev/null`
.SECONDEXPANSION:
$(OBJDIR)/%.c: $(RESDIR)/gfx/$(PLAT)/backgrounds/%.png $$(wildcard $(RESDIR)/gfx/$(PLAT)/backgrounds/%.png.meta)
$(PNG2ASSET) $< -c $@ -map `cat <$<.meta 2>/dev/null`
#always rebuild
.PHONY: $(ALWAYS) remote
# rule for the autogenerated files
$(OBJDIR)/%.o: $(OBJDIR)/%.c
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "res/" to .o object files
$(OBJDIR)/%.o: $(RESDIR)/%.c
$(LCC) -Wf-MMD $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(LCC) -Wf-MMD $(CFLAGS) $(filter -Wf-ba%, $(subst .d,-Wf-ba,$(suffix $(<:%.c=%)))) -c -o $@ $<
# Compile .c files in "src/menus/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/menus/%.c
$(LCC) -Wf-MMD $(CFLAGS) $(filter -Wf-ba%, $(subst .d,-Wf-ba,$(suffix $(<:%.c=%)))) -c -o $@ $<
# Compile .c files in "src/overlays/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/overlays/%.c
$(LCC) -Wf-MMD $(CFLAGS) $(filter -Wf-ba%, $(subst .d,-Wf-ba,$(suffix $(<:%.c=%)))) -c -o $@ $<
# Compile .s assembly files in "src/" to .o object files
$(OBJDIR)/%.o: $(SRCDIR)/%.s
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/<platform>/" to .o object files
$(OBJDIR)/%.o: $(SRCPLAT)/%.c
$(LCC) -Wf-MMD $(CFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/<platform>/" to .o object files
$(OBJDIR)/%.o: $(SRCPLAT)/%.s
$(LCC) $(CFLAGS) -c -o $@ $<
# Compile .c files in "src/<target>/" to .o object files
$(OBJDIR)/%.o: $(SRCPORT)/%.c
$(LCC) -Wf-MMD $(CFLAGS) -c -o $@ $<
# Compile .s assembly files in "src/<target>/" to .o object files
$(OBJDIR)/%.o: $(SRCPORT)/%.s
$(LCC) $(CFLAGS) -c -o $@ $<
# Link the compiled object files into a .gb ROM file
$(BINS): $(RESOBJ) $(OBJS)
$(LCC) $(LCCFLAGS) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $^
cp assets/photo.sav $(BINDIR)/photo.sav
remote:
$(MAKE) -C remote
clean:
@echo Cleaning
@for target in $(TARGETS); do \
$(MAKE) $$target-clean; \
done
$(MAKE) -C remote clean
# 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