This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
159 lines (120 loc) · 3.56 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
152
153
154
155
156
157
158
159
.SUFFIXES:
# ==================
# = PROJECT CONFIG =
# ==================
BUILD_NAME := fe6
SRC_DIR = src
ASM_DIR = asm
BUILD_DIR = build
# ====================
# = TOOL DEFINITIONS =
# ====================
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
UNAME_S := $(shell uname -s)
endif
TOOLCHAIN ?= $(DEVKITARM)
AGBCC_HOME ?= tools/agbcc
ifneq (,$(TOOLCHAIN))
export PATH := $(TOOLCHAIN)/bin:$(PATH)
endif
PREFIX := arm-none-eabi-
ifeq ($(UNAME_S),Darwin)
ifneq (,$(TOOLCHAIN))
PREFIX := $(TOOLCHAIN)/bin/$(PREFIX)
endif
SHASUM ?= shasum
endif
export OBJCOPY := $(PREFIX)objcopy
export AS := $(PREFIX)as
export CPP := $(PREFIX)cpp
export LD := $(PREFIX)ld
export STRIP := $(PREFIX)strip
CC1 := $(AGBCC_HOME)/bin/old_agbcc$(EXE)
CC1_NEW := $(AGBCC_HOME)/bin/agbcc$(EXE)
SHASUM ?= sha1sum
# ================
# = BUILD CONFIG =
# ================
CPPFLAGS := -I $(AGBCC_HOME)/include -I include -I . -nostdinc -undef
CFLAGS := -g -mthumb-interwork -Wimplicit -Wparentheses -Werror -fhex-asm -ffix-debug-line -O2
ASFLAGS := -mcpu=arm7tdmi -I asm/include -I include
LDS := $(BUILD_NAME).lds
ROM := $(BUILD_NAME).gba
ELF := $(ROM:%.gba=%.elf)
MAP := $(ROM:%.gba=%.map)
C_SRCS := $(wildcard $(SRC_DIR)/*.c)
C_OBJS := $(C_SRCS:%.c=$(BUILD_DIR)/%.o)
ASM_SRCS := $(wildcard $(SRC_DIR)/*.s) $(wildcard $(ASM_DIR)/*.s)
ASM_OBJS := $(ASM_SRCS:%.s=$(BUILD_DIR)/%.o)
DATA_SRCS := $(wildcard data/*.s)
DATA_OBJS := $(DATA_SRCS:%.s=$(BUILD_DIR)/%.o)
ALL_OBJS := $(C_OBJS) $(ASM_OBJS) $(DATA_OBJS)
ALL_DEPS := $(ALL_OBJS:%.o=%.d)
SUBDIRS := $(sort $(dir $(ALL_OBJS)))
$(shell mkdir -p $(SUBDIRS))
# ===========
# = RECIPES =
# ===========
compare: $(ROM)
$(SHASUM) -c fe6.sha1
.PHONY: compare
clean:
@echo "RM $(ROM) $(ELF) $(MAP) $(BUILD_DIR)/"
@rm -f $(ROM) $(ELF) $(MAP)
@rm -fr $(BUILD_DIR)/
.PHONY: clean
%.gba: %.elf
$(OBJCOPY) --strip-debug -O binary $< $@
$(ELF): $(ALL_OBJS) $(LDS)
@echo "LD $(LDS) $(ALL_OBJS:$(BUILD_DIR)/%=%)"
@cd $(BUILD_DIR) && $(LD) -T ../$(LDS) -Map ../$(MAP) -L../tools/agbcc/lib $(ALL_OBJS:$(BUILD_DIR)/%=%) -lc -lgcc -o ../$@
# C dependency file
$(BUILD_DIR)/%.d: %.c
@$(CPP) $(CPPFLAGS) $< -o $@ -MM -MG -MT $@ -MT $(BUILD_DIR)/$*.o
# C object
$(BUILD_DIR)/%.o: %.c
@echo "CC $<"
@$(CPP) $(CPPFLAGS) $< | iconv -f UTF-8 -t CP932 | $(CC1) $(CFLAGS) -o $(BUILD_DIR)/$*.s
@echo ".text\n\t.align\t2, 0\n" >> $(BUILD_DIR)/$*.s
@$(AS) $(ASFLAGS) $(BUILD_DIR)/$*.s -o $@
@$(STRIP) -N .gcc2_compiled. $@
# ASM dependency file (dummy, generated with the object)
$(BUILD_DIR)/%.d: $(BUILD_DIR)/%.o
@touch $@
# ASM object
$(BUILD_DIR)/%.o: %.s
@echo "AS $<"
@$(AS) $(ASFLAGS) $< -o $@ --MD $(BUILD_DIR)/$*.d
ifneq (clean,$(MAKECMDGOALS))
-include $(ALL_DEPS)
.PRECIOUS: $(BUILD_DIR)/%.d
endif
# ======================
# = CFLAGS overrides =
# ======================
%/main.o: CFLAGS += -mtpcs-frame
%/irq.o: CFLAGS += -O0
%/random.o: CFLAGS += -O0
%/hardware.o: CFLAGS += -O0
%/move.o: CFLAGS += -O0
%/oam.o: CFLAGS += -O0
%/sound.o: CFLAGS += -O0
%/ramfunc.o: CFLAGS += -O0
%/proc.o: CFLAGS += -O0
%/icon.o: CFLAGS += -O0
%/debugtext.o: CFLAGS += -O0
%/text.o: CFLAGS += -O0
%/banim_sprite.o: CFLAGS += -O0
%/sprite.o: CFLAGS += -O0
%/face.o: CFLAGS += -O0
%/talk.o: CFLAGS += -O0
%/event.o: CFLAGS += -O0
%/spriteanim.o: CFLAGS += -O0
%/gamecontroller.o: CFLAGS += -O0
%/msg.o: CFLAGS += -O0
%/mu.o: CFLAGS += -O0
%/manim.o: CFLAGS += -O0
%/gbasram.o: CFLAGS += -O1