-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
139 lines (116 loc) · 2.8 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
# Disable built-in rules
.SUFFIXES:
TARGET = mf_us.gba
BASEROM = mf_us_baserom.gba
SHA1FILE = mf.sha1
ELF = $(TARGET:.gba=.elf)
MAP = $(TARGET:.gba=.map)
DUMPS = $(BASEROM:.gba=.dump) $(TARGET:.gba=.dump)
# ROM header
GAME_TITLE = METROID4USA
GAME_CODE = AMTE
MAKER_CODE = 01
GAME_REVISION = 00
# Binaries
CPP = cpp
TOOLCHAIN ?= arm-none-eabi-
AS = $(TOOLCHAIN)as
LD = $(TOOLCHAIN)ld
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
CC = agbcc
DIFF = diff -u
HOSTCC = cc
MKDIR = mkdir -p
RM = rm -f
SHA1SUM = sha1sum
TAIL = tail
# Tools
GBAFIX = tools/gbafix/gbafix
PYTHON = python3
EXTRACTOR = tools/extractor.py
PREPROC = tools/preproc/preproc
# Flags
ASFLAGS = -mcpu=arm7tdmi
CFLAGS = -Werror -O2 -mthumb-interwork -fhex-asm
CPPFLAGS = -nostdinc -Iinclude/
# Objects
CSRC = $(wildcard src/**.c) $(wildcard src/**/**.c) $(wildcard src/**/**/**.c)
.PRECIOUS: $(CSRC:.c=.s)
ASMSRC = $(CSRC:.c=.s) $(wildcard asm/*.s)
OBJ = $(ASMSRC:.s=.o)
# Enable verbose output
ifeq ($(V),1)
Q =
MSG = @:
else
Q = @
MSG = @echo " "
endif
.PHONY: all
all: $(TARGET)
.PHONY: check
check: all
$(MSG) SHA1SUM $(SHA1FILE)
$Q$(SHA1SUM) -c $(SHA1FILE)
.PHONY: dump
dump: $(DUMPS)
.PHONY: diff
diff: $(DUMPS)
$(MSG) DIFF $^
$Q$(DIFF) $^
.PHONY: clean
clean:
$(MSG) RM $(TARGET)
$Q$(RM) $(TARGET) $(ELF) $(MAP)
$(MSG) RM \*.dump
$Q$(RM) $(DUMPS)
$(MSG) RM \*.o
$Q$(RM) $(OBJ)
$(MSG) RM data/*.s
$Q$(RM) $(DATA)
$(MSG) RM src/\*\*/\*.s
$Q$(RM) $(CSRC:.c=.s)
$(MSG) RM $(GBAFIX)
$Q$(RM) $(GBAFIX)
$(MSG) RM data/
$Q$(RM) -r data
.PHONY: help
help:
@echo 'Targets:'
@echo ' all: build the ROM'
@echo ' check: checksum the ROM'
@echo ' dump: dump the ROMs'
@echo ' diff: compare the ROM with the original'
@echo ' clean: remove the ROM and intermediate files'
@echo ' help: show this message'
@echo ''
@echo 'Flags:'
@echo ' V=1: enable verbose output'
$(TARGET): $(ELF) $(GBAFIX)
$(MSG) OBJCOPY $@
$Q$(OBJCOPY) -O binary --gap-fill 0xff --pad-to 0x08800000 $< $@
$(MSG) GBAFIX $@
$Q$(GBAFIX) $@ -t$(GAME_TITLE) -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION)
$(ELF) $(MAP): $(OBJ) linker.ld
$(MSG) LD $@
$Q$(LD) $(LDFLAGS) -n -T linker.ld -Map=$(MAP) -o $@
%.dump: %.gba
$(MSG) OBJDUMP $@
$Q$(OBJDUMP) -D -bbinary -marm7tdmi -Mforce-thumb $< | $(TAIL) -n+3 >$@
#--stop-address 0x8c71c
%.o: %.s
$(MSG) AS $@
$Q$(AS) $(ASFLAGS) $< -o $@
%.s: %.c
$(MSG) CC $@
$Q$(PREPROC) $< | $(CPP) $(CPPFLAGS) | $(CC) -o $@ $(CFLAGS) && printf '\t.align 2, 0 @ dont insert nops\n' >> $@
src/sram/%.s: CFLAGS = -O1 -mthumb-interwork -fhex-asm
src/sram/%.s: src/sram/%.c
src/libgcc/%.s: CFLAGS = -O2 -fhex-asm
src/libgcc/%.s: src/libgcc/%.c
src/sprites_AI/%.s: CFLAGS = -O2 -mthumb-interwork -fhex-asm
src/sprites_AI/%.s: src/sram/%.c
tools/%: tools/%.c
$(MSG) HOSTCC $@
$Q$(HOSTCC) $< $(HOSTCFLAGS) $(HOSTCPPFLAGS) -o $@