-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
133 lines (100 loc) · 3.76 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
# TODO: Refactor rule dependencies.
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
# Enabled by `make modern`
MODERN ?= 0
# Build target
NAME := rmz3
ROM := $(NAME).gba
ELF := $(NAME).elf
# Tools
TOOL = $(DEVKITARM)/bin
ifeq ($(MODERN),1)
AGBCC := $(TOOL)/arm-none-eabi-gcc
else
AGBCC := tools/agbcc/bin/agbcc$(EXE)
endif
AS = tools/binutils/bin/arm-none-eabi-as
LD = $(TOOL)/arm-none-eabi-ld
OBJCOPY = $(TOOL)/arm-none-eabi-objcopy
OBJDUMP := $(TOOL)/arm-none-eabi-objdump
# Flags
ARCH := -mcpu=arm7tdmi -march=armv4t -mthumb
CFLAGS := -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fshort-enums
ASFLAGS := $(ARCH) -mthumb-interwork -g --agbasm-colon-defined-global-labels --agbasm-multiline-macros --agbasm-charmap --agbasm-no-gba-thumb-after-label-disasm-fix
ifeq ($(MODERN),1)
CPPFLAGS := -I $(DEVKITARM)/arm-none-eabi/include -iquote include -DMODERN=$(MODERN)
CFLAGS += $(ARCH) $(CPPFLAGS) -Wno-pointer-to-int-cast -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-address-of-packed-member
LIBPATH := -L $(shell dirname $(shell $(AGBCC) --print-file-name=libgcc.a)) -L $(shell dirname $(shell $(AGBCC) --print-file-name=libc.a))
else
CPPFLAGS := -I tools/agbcc -I tools/agbcc/include -iquote include -nostdinc -DMODERN=$(MODERN)
CFLAGS += -fhex-asm
LIBPATH := -L tools/agbcc/lib
endif
LDFLAGS := $(LIBPATH) -lgcc -lc
ASFILE := $(wildcard asm/*.s) $(wildcard asm/*/*.s) $(shell find sound/songs -type f -name '*.s') src/libs/m4a_1.s data/tilesets/offsets.s sprites/dynamic/table.s sprites/dynamic/anim.s sprites/static/anim.s
ASOBJFILE := $(ASFILE:.s=.o)
CFILE := $(shell find src -type f -name '*.c')
COBJFILE := $(CFILE:.c=.o)
ifneq ($(MODERN),1)
# Special configurations required for lib files
src/mmbn4.o: CFLAGS += -mno-thumb-interwork
src/libs/agb_sram.o: CFLAGS := -O -mthumb-interwork
src/libs/m4a.o: AGBCC := tools/agbcc/bin/old_agbcc$(EXE)
endif
ifeq ($(MODERN),1)
LDSCRIPT := ld_script_modern.ld
else
LDSCRIPT := ld_script.ld
endif
.PHONY: all check compare clean clean-code
all: $(ROM) compare
check: $(ROM) compare
# This is a build method for romhacks and builds with gcc specified by the user.
modern: ; @$(MAKE) $(ROM) -j8 MODERN=1
compare: $(ROM)
@sha1sum -c $(NAME).sha1
clean: clean-src clean-graphics
@rm -f $(ELF) $(ASOBJFILE) $(COBJFILE)
clean-code: clean-src
@rm -f $(ELF) $(ASOBJFILE) $(COBJFILE) $(shell find asm -type f -name '*.o') $(shell find src -type f -name '*.o') $(shell find sound/songs -type f -name '*.o')
$(ROM): $(ELF)
@$(OBJCOPY) -O binary $< $@
$(ELF): %.elf: $(ASOBJFILE) $(COBJFILE) midi ld_script.ld graphic-headers
@$(LD) -T $(LDSCRIPT) -Map $*.map -o $@ $(ASOBJFILE) $(COBJFILE) $(GFX_HDR) $(LDFLAGS)
$(COBJFILE): %.o: %.c graphics stage
ifeq ($(MODERN),1)
@$(AGBCC) $(CFLAGS) $< -c -o $@
else
@$(CPP) $(CPPFLAGS) $< | $(AGBCC) $(CFLAGS) -o $(subst .c,.s,$<)
@echo ".text\n\t.align\t2, 0\n" >> $(subst .c,.s,$<)
@$(AS) $(ASFLAGS) $(subst .c,.s,$<) -o $@
endif
$(ASOBJFILE): %.o: %.s string graphics sprite
$(CPP) $(CPPFLAGS) $< | $(AS) $(ASFLAGS) -o $@ -
include data/string/string.mk
include data/texts/texts.mk
include src/src.mk
#### Graphics Rules ####
GBAGFX := tools/gbagfx/gbagfx$(EXE)
include graphics_file_rules.mk
#### Graphic Headers Rules ####
GFX_JSON_CONVERTER := ./tools/dev/graphic_header.ts
include graphic_header_rules.mk
#### Audio Rules ####
MID := tools/mid2agb/mid2agb$(EXE)
include songs.mk
#### Text Rules ####
TEXTCOMP := tools/rmz-text-compiler$(EXE)
%.bin: %.txt ; @$(TEXTCOMP) -f $< -o $@
%.bin: %.zc ;@$(TEXTCOMP) -c --verbose -f $< -o $@
#### Sprite Rules ####
METASPRITE_JSON_CONVERTER := ./tools/dev/metasprite.ts
SEQUENCE_JSON_CONVERTER := ./tools/dev/sequence.ts
include sprite_rules.mk
#### Stage Rules ####
STAGE_JSON_CONVERTER := ./tools/dev/stage.ts
include stage_rules.mk