-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
140 lines (97 loc) · 3.19 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
ROM := pokegold-spaceworld.gb
CORRECTEDROM := $(ROM:%.gb=%-correctheader.gb)
BASEROM := baserom.gb
DIRS := home engine data gfx audio maps scripts ram slack
FILES :=
BUILD := build
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
ASMFILES := $(call rwildcard, $(DIRS), *.asm) $(FILES)
OBJS := $(patsubst %.asm, $(BUILD)/%.o, $(ASMFILES))
OBJS += $(BUILD)/shim.o
### Build tools
ifeq (,$(shell which sha1sum))
SHA1 := shasum
else
SHA1 := sha1sum
endif
PYTHON := python3
RGBDS ?=
RGBASM ?= $(RGBDS)rgbasm
RGBFIX ?= $(RGBDS)rgbfix
RGBGFX ?= $(RGBDS)rgbgfx
RGBLINK ?= $(RGBDS)rgblink
RGBASMFLAGS := -E -i $(BUILD)/ -DGOLD
SCAN_INCLUDES := tools/scan_includes
MAKE_SHIM := tools/make_shim.py
tools/gfx :=
### Build targets
.SECONDEXPANSION:
.PHONY: all
all: $(ROM) $(CORRECTEDROM) compare
.PHONY: compare
compare: $(ROM) $(CORRECTEDROM)
@$(SHA1) -c roms.sha1
.PHONY: tools
tools tools/pkmncompress tools/gfx tools/scan_includes:
"$(MAKE)" -C tools/
# Remove files generated by the build process.
.PHONY: clean
clean:
rm -rf $(ROM) $(CORRECTEDROM) $(ROMS:.gb=.sym) $(ROMS:.gb=.map) $(BUILD)
"$(MAKE)" -C tools clean
# Remove generated files except for graphics.
.PHONY: tidy
tidy:
rm -rf $(ROM) $(CORRECTEDROM) $(ROMS:.gb=.sym) $(ROMS:.gb=.map) $(OBJS) $(BUILD)/shim.asm
# Visualize disassembly progress.
.PHONY: coverage
coverage: $(ROM:.gb=.map)
utils/coverage.py $<
### Build products
%.map: %.gb
$(CORRECTEDROM): %-correctheader.gb: %.gb
cp $< $@
cp $(<:.gb=.sym) $(@:.gb=.sym)
$(RGBFIX) -f hg -m 0x10 $@
$(ROM): poke%-spaceworld.gb: layout.link $(OBJS) | $(BASEROM)
$(RGBLINK) -d -n $(@:.gb=.sym) -m $(@:.gb=.map) -l layout.link -O $(BASEROM) -o $@ $(filter-out $<, $^)
$(RGBFIX) -f lh -k 01 -l 0x33 -m 0x03 -p 0 -r 3 -t "POKEMON2$(shell echo $* | cut -d _ -f 1 | tr '[:lower:]' '[:upper:]')" $@
$(BASEROM):
@echo "Please obtain a copy of Gold_debug.sgb and put it in this directory as $@"
@exit 1
$(BUILD)/shim.asm: shim.sym | $$(dir $$@)
$(MAKE_SHIM) $< > $@
### Misc file-specific graphics rules
include gfx/gfx.mk
include slack/slack.mk
### Catch-all build target rules
$(BUILD)/%.o: $(BUILD)/%.asm | $$(dir $$@)
$(RGBASM) $(RGBASMFLAGS) $(OUTPUT_OPTION) $<
$(BUILD)/%.o: %.asm | $$(dir $$@)
$(RGBASM) $(RGBASMFLAGS) $(OUTPUT_OPTION) $<
$(BUILD)/%.d: %.asm | $$(dir $$@) $(SCAN_INCLUDES)
@$(SCAN_INCLUDES) -b $(BUILD)/ -i $(BUILD)/ -i ./ -o $@ -t $(@:.d=.o) $<
.PRECIOUS: $(BUILD)/%.pic
$(BUILD)/%.pic: $(BUILD)/%.2bpp tools/pkmncompress | $$(dir $$@)
tools/pkmncompress $< $@
.PRECIOUS: $(BUILD)/%.2bpp
$(BUILD)/%.2bpp: %.png tools/gfx | $$(dir $$@)
$(RGBGFX) $(OUTPUT_OPTION) $<
tools/gfx $(tools/gfx) $(OUTPUT_OPTION) $@
.PRECIOUS: $(BUILD)/%.1bpp
$(BUILD)/%.1bpp: %.1bpp.png tools/gfx | $$(dir $$@)
$(RGBGFX) -d1 $(OUTPUT_OPTION) $<
tools/gfx $(tools/gfx) -d1 $(OUTPUT_OPTION) $@
.PRECIOUS: $(BUILD)/%.tilemap
$(BUILD)/%.tilemap: %.png | $$(dir $$@)
$(RGBGFX) -t $@ $<
.PRECIOUS: $(BUILD)/%.sgb.tilemap
$(BUILD)/%.sgb.tilemap: %.bin | $$(dir $$@)
tr < $< -d '\000' > $@
.PRECIOUS: %/
%/:
mkdir -p $@
### Scan .asm files for INCLUDE dependencies
ifeq (,$(filter clean tools,$(MAKECMDGOALS)))
-include $(patsubst %.o, %.d, $(OBJS))
endif