forked from pkmncoraldev/polishedcoral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
174 lines (128 loc) · 3.93 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
NAME := coral
VERSION := in-progress
TITLE := POKECORALV1
MCODE := PKCV
ROMVERSION := 0x30
FILLER = 0x00
ifneq ($(wildcard rgbds/.*),)
RGBDS_DIR = rgbds/
else
RGBDS_DIR =
endif
RGBASM_FLAGS = -Weverything
RGBLINK_FLAGS = -n $(ROM_NAME).sym -m $(ROM_NAME).map -l contents/contents.link -p $(FILLER)
RGBFIX_FLAGS = -csjv -t $(TITLE) -i $(MCODE) -n $(ROMVERSION) -p $(FILLER) -k 01 -l 0x33 -m 0x10 -r 3
CFLAGS = -g -O3 -march=native -std=c11 -Wall -Wextra -pedantic
ifeq ($(filter faithful,$(MAKECMDGOALS)),faithful)
RGBASM_FLAGS += -DFAITHFUL
endif
ifeq ($(filter nortc,$(MAKECMDGOALS)),nortc)
RGBASM_FLAGS += -DNO_RTC
endif
ifeq ($(filter monochrome,$(MAKECMDGOALS)),monochrome)
RGBASM_FLAGS += -DMONOCHROME
endif
ifeq ($(filter noir,$(MAKECMDGOALS)),noir)
RGBASM_FLAGS += -DNOIR
endif
ifeq ($(filter hgss,$(MAKECMDGOALS)),hgss)
RGBASM_FLAGS += -DHGSS
endif
ifeq ($(filter debug,$(MAKECMDGOALS)),debug)
RGBASM_FLAGS += -DDEBUG
endif
.SUFFIXES:
.PHONY: all clean crystal faithful nortc debug monochrome bankfree freespace compare tools
.SECONDEXPANSION:
.PRECIOUS: %.2bpp %.1bpp %.lz %.o
roms_md5 = roms.md5
bank_ends_txt = contents/bank_ends.txt
sorted_sym = contents/$(NAME).sym
PYTHON = python2
CC = gcc
RM = rm -f
GFX = $(PYTHON) gfx.py
MD5 = md5sum
LZ = tools/lzcomp
SCAN_INCLUDES = tools/scan_includes
bank_ends := $(PYTHON) contents/bank_ends.py $(NAME)-$(VERSION)
crystal_obj := \
main.o \
home.o \
ram.o \
audio.o \
audio/musicplayer.o \
data/pokemon/dex_entries.o \
data/pokemon/egg_moves.o \
data/pokemon/evos_attacks.o \
data/maps/map_data.o \
data/text/common.o \
data/tilesets.o \
engine/credits.o \
engine/events.o \
gfx/pics.o \
gfx/sprites.o
all: crystal
crystal: FILLER = 0x00
crystal: ROM_NAME = $(NAME)-$(VERSION)
crystal: $(NAME)-$(VERSION).gbc
faithful: crystal
nortc: crystal
monochrome: crystal
noir: crystal
hgss: crystal
debug: crystal
bankfree: FILLER = 0xff
bankfree: ROM_NAME = $(NAME)-$(VERSION)-0xff
bankfree: $(NAME)-$(VERSION)-0xff.gbc
freespace: $(bank_ends_txt) $(roms_md5) $(sorted_sym)
# Build tools when building the rom
ifeq ($(filter clean tools,$(MAKECMDGOALS)),)
Makefile: tools
endif
tools: $(LZ) $(SCAN_INCLUDES)
$(LZ): $(wildcard tools/lz/*.c) $(wildcard tools/lz/*.h)
$(CC) $(CFLAGS) -flto -o $@ tools/lz/*.c
$(SCAN_INCLUDES): $(SCAN_INCLUDES).c
$(CC) $(CFLAGS) -o $@ $<
clean:
$(RM) $(crystal_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym)
compare: crystal
$(MD5) -c $(roms_md5)
$(bank_ends_txt): crystal bankfree ; $(bank_ends) > $@
$(roms_md5): crystal ; $(MD5) $(NAME)-$(VERSION).gbc > $@
$(sorted_sym): crystal ; tail -n +3 $(NAME)-$(VERSION).sym | sort -o $@
# The dep rules have to be explicit or else missing files won't be reported.
# As a side effect, they're evaluated immediately instead of when the rule is invoked.
# It doesn't look like $(shell) can be deferred so there might not be a better way.
define DEP
$1: $2 $$(shell tools/scan_includes $2)
endef
ifeq (,$(filter clean tidy tools,$(MAKECMDGOALS)))
# Dependencies for shared objects objects
$(foreach obj, $(crystal_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
endif
%.o: %.asm
$(RGBDS_DIR)rgbasm $(RGBASM_FLAGS) -o $@ $<
.gbc:
%.gbc: $(crystal_obj)
$(RGBDS_DIR)rgblink $(RGBLINK_FLAGS) -o $@ $^
$(RGBDS_DIR)rgbfix $(RGBFIX_FLAGS) $@
%.2bpp.vram0: %.2bpp
tools/sub_2bpp.sh $< 128 > $@
%.2bpp.vram1: %.2bpp
tools/sub_2bpp.sh $< 128 128 > $@
%.2bpp.vram2: %.2bpp
tools/sub_2bpp.sh $< 256 128 > $@
%.2bpp: %.png ; $(GFX) 2bpp $<
%.1bpp: %.png ; $(GFX) 1bpp $<
gfx/pokemon/%/bitmask.asm gfx/pokemon/%/frames.asm: gfx/pokemon/%/front.2bpp
%.lz: % ; $(LZ) $< $@
%.pal: ; $(error ERROR: Cannot find '$@')
%.png: ; $(error ERROR: Cannot find '$@')
%.asm: ; $(error ERROR: Cannot find '$@')
%.bin: ; $(error ERROR: Cannot find '$@')
%.ablk: ; $(error ERROR: Cannot find '$@')
%.tilemap: ; $(error ERROR: Cannot find '$@')
#%.wav: ;
#%.ded: %.wav dedenc.py ; $(PYTHON) dedenc.py $< $@