-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
151 lines (118 loc) · 4.71 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
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
# Configuration
TITLE := MARIO KART
GAME_CODE := AMKE
MAKER_CODE := 01
REVISION := 0
ROM := mksc.gba
# Tools
BIN_DIR := $(DEVKITARM)/bin
PREFIX := arm-none-eabi-
CPP := $(BIN_DIR)/./$(PREFIX)cpp$(EXE)
OBJCOPY := $(BIN_DIR)/./$(PREFIX)objcopy$(EXE)
LD := $(BIN_DIR)/./$(PREFIX)ld$(EXE)
AS := $(BIN_DIR)/./$(PREFIX)as$(EXE)
SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
FIX := gbafix
SHELL := /bin/bash -o pipefail
AGBCC := tools/agbcc/bin/old_agbcc$(EXE)
CC1 := tools/thumb-elf/lib/gcc-lib/thumb-elf/2.9-arm-000512/cc1$(EXE)
AIF2PCM := tools/aif2pcm/aif2pcm$(EXE)
# Flags
ASFLAGS := -mcpu=arm7tdmi -I include
CFLAGS := -mthumb-interwork -Wimplicit -Wparentheses -O2
CPPFLAGS := -I tools/agbcc -I tools/agbcc/include -I lib -iquote include -nostdinc
LDFLAGS = -L../tools/agbcc/lib -L../lib/libunk -lgcc -lc -lunk --just-symbols=../symbols.txt
# Files
ELF = $(ROM:.gba=.elf)
MAP = $(ROM:.gba=.map)
OBJ_DIR := build
C_SUBDIR = src
ASM_SUBDIR = asm
SOUND_SUBDIR = sound
DATA_SRC_SUBDIR = src/data
# DATA_ASM_SUBDIR = data
DATA_SUBDIR = data
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)
ASM_BUILDDIR = $(OBJ_DIR)/$(ASM_SUBDIR)
SOUND_BUILDDIR = $(OBJ_DIR)/$(SOUND_SUBDIR)
# DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR)
DATA_BUILDDIR = $(OBJ_DIR)/$(DATA_SUBDIR)
C_SRCS := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c)
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS))
C_DEPS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.d,$(C_SRCS))
ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(ASM_BUILDDIR)/%.o,$(ASM_SRCS))
SOUND_SRCS := $(wildcard $(SOUND_SUBDIR)/*.s $(SOUND_SUBDIR)/*/*.s $(SOUND_SUBDIR)/*/*/*.s)
SOUND_OBJS := $(patsubst $(SOUND_SUBDIR)/%.s,$(SOUND_BUILDDIR)/%.o,$(SOUND_SRCS))
SOUND_AIFS := $(wildcard $(SOUND_SUBDIR)/*.aif $(SOUND_SUBDIR)/*/*.aif $(SOUND_SUBDIR)/*/*/*.aif)
SOUND_AIF_OBJS := $(patsubst $(SOUND_SUBDIR)/%.aif,$(SOUND_BUILDDIR)/%.o,$(SOUND_AIFS))
DATA_BINS := $(wildcard $(DATA_SUBDIR)/*.bin)
DATA_OBJS := $(patsubst $(DATA_SUBDIR)/%.bin,$(DATA_BUILDDIR)/%.o,$(DATA_BINS))
# 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_OBJS) $(SOUND_OBJS) $(SOUND_AIF_OBJS)
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
SUBDIRS := $(sort $(dir $(OBJS)))
$(shell mkdir -p $(SUBDIRS))
define bin2o
bin2s -H $(@).h $< | $(AS) -o $(@)
endef
# Rules
.PHONY: tools libraries rom clean
rom: tools libraries $(ROM) compare
compare: $(ROM)
@$(SHA1) rom.sha1
libraries:
@$(MAKE) -C lib/libunk
clean:
$(MAKE) clean -C tools/aif2pcm
rm -f $(ROM) $(ELF) $(MAP)
rm -r build/*
$(MAKE) -C lib/libunk clean
tools:
@$(MAKE) -C tools/aif2pcm
$(OBJ_DIR)/src/agbbackup/%.o : src/agbbackup/%.c
@$(CPP) -MMD -MT $@ $(CPPFLAGS) $< -o $(OBJ_DIR)/src/agbbackup/$*.i
@$(AGBCC) $(OBJ_DIR)/src/agbbackup/$*.i $(CFLAGS) -O1 -o $(OBJ_DIR)/src/agbbackup/$*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $(OBJ_DIR)/src/agbbackup/$*.s
$(AS) $(ASFLAGS) -o $@ $(OBJ_DIR)/src/agbbackup/$*.s
$(C_BUILDDIR)/mp2000/%.o : $(C_SUBDIR)/mp2000/%.c
@$(CPP) -MMD -MT $@ $(CPPFLAGS) $< -o $(OBJ_DIR)/src/mp2000/$*.i
@$(AGBCC) $(OBJ_DIR)/src/mp2000/$*.i $(CFLAGS) -o $(OBJ_DIR)/src/mp2000/$*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $(OBJ_DIR)/src/mp2000/$*.s
$(AS) $(ASFLAGS) -o $@ $(OBJ_DIR)/src/mp2000/$*.s
$(C_BUILDDIR)/%.O3.o : $(C_SUBDIR)/%.O3.c
@$(CPP) -MMD -MT $@ $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
@$(CC1) $(C_BUILDDIR)/$*.i $(CFLAGS) -O3 -o $(C_BUILDDIR)/$*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s
@sed -i -e 's/\.align\t2/\.align\t2, 0/' $(C_BUILDDIR)/$*.s
$(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s
$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c
@$(CPP) -MMD -MT $@ $(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
@sed -i -e 's/\.align\t2/\.align\t2, 0/' $(C_BUILDDIR)/$*.s
$(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s
$(SOUND_BUILDDIR)/%.o: $(SOUND_SUBDIR)/%.aif
$(AIF2PCM) $< $(patsubst %.o,%,$@)
bin2s -H $(@).h $(patsubst %.o,%,$@) | $(AS) -o $(@)
$(SOUND_BUILDDIR)/%.o: $(SOUND_SUBDIR)/%.s
$(AS) $(ASFLAGS) -o $@ $<
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s
$(AS) $(ASFLAGS) -o $@ $<
$(DATA_BUILDDIR)/%.o : $(DATA_SUBDIR)/%.bin
@echo $(notdir $<)
@$(bin2o)
$(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
show:
echo $(ASM_SRCS)
-include $(C_DEPS)