-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
executable file
·145 lines (105 loc) · 3.13 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
NAME := redplusplus
VERSION := 4.0.0-beta
TITLE := POKEMONRPP
MCODE := PRPP
ROMVERSION := 0x40
FILLER = 0x00
ifneq ($(wildcard rgbds/.*),)
RGBDS_DIR = rgbds/
else
RGBDS_DIR =
endif
RGBASM_FLAGS =
RGBLINK_FLAGS = -n $(ROM_NAME).sym -m $(ROM_NAME).map -l contents/contents.link -p $(FILLER)
RGBFIX_FLAGS = -Cjv -t $(TITLE) -i $(MCODE) -n $(ROMVERSION) -p $(FILLER) -k 01 -l 0x33 -m 0x10 -r 3
CFLAGS = -O3 -std=c11 -Wall -Wextra -pedantic
ifeq ($(filter debug,$(MAKECMDGOALS)),debug)
RGBASM_FLAGS += -DDEBUG
endif
ifeq ($(filter noir,$(MAKECMDGOALS)),noir)
RGBASM_FLAGS += -DNOIR
endif
ifeq ($(filter monochrome,$(MAKECMDGOALS)),monochrome)
RGBASM_FLAGS += -DMONOCHROME
endif
.SUFFIXES:
.PHONY: all clean rpp debug noir 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 = python
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)
rpp_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/tileset_data.o \
engine/credits.o \
engine/events.o \
gfx/pics.o \
gfx/sprites.o
all: rpp
rpp: FILLER = 0x00
rpp: ROM_NAME = $(NAME)-$(VERSION)
rpp: $(NAME)-$(VERSION).gbc
debug: rpp
noir: rpp
monochrome: rpp
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): $(LZ).c
$(CC) $(CFLAGS) -o $@ $<
$(SCAN_INCLUDES): $(SCAN_INCLUDES).c
$(CC) $(CFLAGS) -o $@ $<
clean:
$(RM) $(rpp_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym)
compare: rpp
$(MD5) -c $(roms_md5)
$(bank_ends_txt): rpp bankfree ; $(bank_ends) > $@
$(roms_md5): rpp ; $(MD5) $(NAME)-$(VERSION).gbc > $@
$(sorted_sym): rpp ; tail -n +3 $(NAME)-$(VERSION).sym | sort -o $@
%.2bpp.trimfont: %.2bpp
# skip the first 112 tiles (= 7168 px = 14336 bits = 1792 bytes),
# take the next 16 tiles (= 1024 px = 2048 bits = 256 bytes)
tail -c +1793 $< | head -c 256 > $@
%.o: dep = $(shell $(SCAN_INCLUDES) $(@D)/$*.asm)
%.o: %.asm $$(dep)
$(RGBDS_DIR)rgbasm $(RGBASM_FLAGS) -o $@ $<
.gbc:
%.gbc: $(rpp_obj)
$(RGBDS_DIR)rgblink $(RGBLINK_FLAGS) -o $@ $^
$(RGBDS_DIR)rgbfix $(RGBFIX_FLAGS) $@
%.2bpp: %.png ; $(GFX) 2bpp $<
%.1bpp: %.png ; $(GFX) 1bpp $<
%.pal: %.2bpp
gfx/pokemon/%/normal.pal 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 '$@')
%.blk: ; $(error ERROR: Cannot find '$@')
%.ablk: ; $(error ERROR: Cannot find '$@')
%.tilemap: ; $(error ERROR: Cannot find '$@')