-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
112 lines (80 loc) · 2.75 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
BIN_DIR := $(DEVKITARM)/bin
PREFIX := arm-none-eabi-
ifeq ($(OS),Windows_NT)
WINE :=
EXE := .exe
else
WINE := .exe
EXE :=
endif
CPP := $(BIN_DIR)/./$(PREFIX)cpp$(EXE)
OBJCOPY := $(BIN_DIR)/./$(PREFIX)objcopy$(EXE)
LD := $(BIN_DIR)/./$(PREFIX)ld$(EXE)
AS := $(BIN_DIR)/./$(PREFIX)as$(EXE)
TITLE := BANJOKAZOOIE
GAME_CODE := BKZE
MAKER_CODE := 78
REVISION := 0
SHELL := /bin/bash -o pipefail
ROM := bkgr.gba
OBJ_DIR := build
ELF = $(ROM:.gba=.elf)
MAP = $(ROM:.gba=.map)
C_SUBDIR = src
ASM_SUBDIR = asm
DATA_SRC_SUBDIR = src/data
DATA_ASM_SUBDIR = data
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)
ASM_BUILDDIR = $(OBJ_DIR)/$(ASM_SUBDIR)
DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR)
ASFLAGS := -mcpu=arm7tdmi
CC1 := tools/agbcc/bin/./agbcc$(EXE)
CFLAGS := -O2 -mthumb-interwork -fhex-asm -fno-common -g -Wall -Werror
CPPFLAGS := -I tools/agbcc/include -nostdinc -undef -iquote include -Wno-trigraphs
LIBC := tools/agbcc/lib/libc.a
LIBGCC := tools/agbcc/lib/libgcc.a
LDFLAGS = -L../tools/agbcc/lib -lgcc -lc --just-symbols=../symbols.txt
SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
FIX := tools/gbafix/./gbafix
# Clear the default suffixes
.SUFFIXES:
# Don't delete intermediate files
.SECONDARY:
# Delete files that weren't built properly
.DELETE_ON_ERROR:
# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:
.PHONY: rom clean compare tidy
C_SRCS := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c)
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS))
ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(ASM_BUILDDIR)/%.o,$(ASM_SRCS))
DATA_ASM_SRCS := $(wildcard $(DATA_ASM_SUBDIR)/*.s)
DATA_ASM_OBJS := $(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o,$(DATA_ASM_SRCS))
OBJS := $(C_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS) $(SONG_OBJS) $(MID_OBJS)
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
SUBDIRS := $(sort $(dir $(OBJS)))
$(shell mkdir -p $(SUBDIRS))
rom: $(ROM) compare
compare: $(ROM)
@$(SHA1) rom.sha1
clean: tidy
tidy:
rm -f $(ROM) $(ELF) $(MAP)
rm -r build/*
$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c
@$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
@$(CC1) $(C_BUILDDIR)/$*.i $(CFLAGS) -o $(C_BUILDDIR)/$*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s
$(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s
$(AS) $(ASFLAGS) -o $@ $<
$(ELF): $(OBJS)
cd $(OBJ_DIR) && $(LD) -Map ../$(MAP) -T ../ld_script.ld -o ../$@ $(LDFLAGS) $(OBJS_REL)
$(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
echo:
echo $(CPP) $(CPPFLAGS) $(C_SUBDIR)/alloc.c -o $(C_BUILDDIR)/alloc.i
show:
$(BIN_DIR)