forked from not-alons/hmfomt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
145 lines (108 loc) · 3.34 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
.SUFFIXES:
# ==================
# = PROJECT CONFIG =
# ==================
BUILD_NAME := fomt
INCLUDE_DIRS := \
tools/agbcc/include \
tools/libagbc++ \
tools/libsix/include
SRC_DIR = src
ASM_DIR = asm
DATA_ASM_DIR = asm/data
BUILD_DIR = build
# ====================
# = TOOL DEFINITIONS =
# ====================
TOOLCHAIN ?= $(DEVKITARM)
ifneq (,$(TOOLCHAIN))
export PATH := $(TOOLCHAIN)/bin:$(PATH)
endif
PREFIX := arm-none-eabi-
export OBJCOPY := $(PREFIX)objcopy
export AS := $(PREFIX)as
export CPP := $(PREFIX)cpp
export LD := $(PREFIX)ld
export STRIP := $(PREFIX)strip
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
CC1 := tools/agbcc/bin/agbcc$(EXE)
CC1PLUS := tools/agbcc/bin/agbcp$(EXE)
OLD_CC1 := tools/agbcc/bin/old_agbcc$(EXE)
# ================
# = BUILD CONFIG =
# ================
INCFLAGS := $(foreach dir, $(INCLUDE_DIRS), -I "$(dir)")
CPPFLAGS := $(INCFLAGS) -iquote . -iquote include -Wno-trigraphs
CFLAGS := -g -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm
CXXFLAGS := -quiet -fno-exceptions -fno-rtti -fvtable-thunks $(CFLAGS)
ASFLAGS := $(INCFLAGS) -I . -I include -mcpu=arm7tdmi
ROM := $(BUILD_NAME).gba
ELF := $(ROM:.gba=.elf)
MAP := $(ROM:.gba=.map)
LDS := $(BUILD_NAME).lds
C_SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/rt/*.c)
C_OBJS := $(C_SRCS:%.c=$(BUILD_DIR)/%.o)
CXX_SRCS := $(wildcard $(SRC_DIR)/*.cc $(SRC_DIR)/rt/*.cc)
CXX_OBJS := $(CXX_SRCS:%.cc=$(BUILD_DIR)/%.o)
ASM_SRCS := $(wildcard $(SRC_DIR)/*.s $(ASM_DIR)/*.s)
ASM_OBJS := $(ASM_SRCS:%.s=$(BUILD_DIR)/%.o)
DATA_ASM_SRCS := $(wildcard $(DATA_ASM_DIR)/*.s)
DATA_ASM_OBJS := $(DATA_ASM_SRCS:%.s=$(BUILD_DIR)/%.o)
ALL_OBJS := $(C_OBJS) $(CXX_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS)
ALL_DEPS := $(ALL_OBJS:%.o=%.d)
SUBDIRS := $(sort $(dir $(ALL_OBJS)))
$(shell mkdir -p $(SUBDIRS))
# ===========
# = RECIPES =
# ===========
compare: $(ROM)
sha1sum -c $(BUILD_NAME).sha1
.PHONY: compare
# ROM from ELF
%.gba: %.elf
$(OBJCOPY) -O binary $< $@
# ELF
$(ELF): $(ALL_OBJS) $(LDS)
@echo "LD $(LDS) $(ALL_OBJS:$(BUILD_DIR)/%=%)"
@cd $(BUILD_DIR) && $(LD) -T ../$(LDS) -Map ../$(MAP) -L../tools/agbcc/lib -lgcc -lc $(ALL_OBJS:$(BUILD_DIR)/%=%) -o ../$@
@$(STRIP) -N .gcc2_compiled. $(ELF)
# C dependency file
$(BUILD_DIR)/%.d: %.c
@$(CPP) $(CPPFLAGS) $< -o $@ -MM -MG -MT $@ -MT $(BUILD_DIR)/$*.o
# C object
$(BUILD_DIR)/%.o: %.c $(BUILD_DIR)/%.d
@echo "CC $<"
@$(CPP) $(CPPFLAGS) $< | $(CC1) $(CFLAGS) -o $(BUILD_DIR)/$*.s
@tools/scripts/align_sections.sh $(BUILD_DIR)/$*.s
@$(AS) $(ASFLAGS) $(BUILD_DIR)/$*.s -o $@
# C++ dependency file
$(BUILD_DIR)/%.d: %.cc
@$(CPP) $(CPPFLAGS) $< -o $@ -MM -MG -MT $@ -MT $(BUILD_DIR)/$*.o
# C++ object
$(BUILD_DIR)/%.o: %.cc $(BUILD_DIR)/%.d
@echo "CP $<"
@$(CPP) $(CPPFLAGS) $< | ($(CC1PLUS) $(CXXFLAGS) -o $(BUILD_DIR)/$*.s || false)
@tools/scripts/align_sections.sh $(BUILD_DIR)/$*.s
@$(AS) $(ASFLAGS) $(BUILD_DIR)/$*.s -o $@
# 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
# overrides for matching
$(BUILD_DIR)/src/m4a.o: CC1 := $(OLD_CC1)
clean:
@echo "RM $(ROM) $(ELF) $(MAP) $(BUILD_DIR)"
@rm -f $(ROM) $(ELF) $(MAP)
@rm -r $(BUILD_DIR)/
.PHONY: clean
ifneq (clean,$(MAKECMDGOALS))
-include $(ALL_DEPS)
.PRECIOUS: $(BUILD_DIR)/%.d
endif