-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
202 lines (139 loc) · 5.01 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# ---------------------------------------------------------------------
# SETUP
# ---------------------------------------------------------------------
# --- No implicit rules ---
.SUFFIXES:
# --- Main path ---
export PATH := $(DEVKITARM)/bin:$(PATH)
# --- tonc lib location ---
TONCLIB := $(DEVKITARM)/../libtonc
# --- flow control ---
# Turn on/off flow control. For example for when either the
# link cable doesn't have SD, SC wires or when the USB serial cable doesn't have
# CTS/RTS wires. See README.md for more info.
FLOW_CONTROL=0
# ---------------------------------------------------------------------
# PROJECT DETAILS
# ---------------------------------------------------------------------
# PROJ : Base project name
# TITLE : Title for ROM header (12 characters)
# LIBS : Libraries to use, formatted as list for linker flags
# BUILD : Directory for build process temporaries. Should NOT be empty!
# SRCDIRS : List of source file directories
# INCDIRS : List of header file directories
# LIBDIRS : List of library directories
# General note: use . for the current dir, don't leave them empty.
export PROJ ?= $(notdir $(CURDIR))
TITLE := $(PROJ)
LIBS := -ltonc
BUILD := build
SRCDIRS := source
INCDIRS := include
LIBDIRS := $(TONCLIB)
# --- Tonc paths ---
# If not defined as environment var, assumed to be current dir
export TONCCODE ?= $(CURDIR)
include $(TONCCODE)/tonc_rules
# --- switches ---
bMB := 0 # Multiboot build
bTEMPS := 0 # Save gcc temporaries (.i and .s files)
bDEBUG2 := 0 # Generate debug info (bDEBUG2? Not a full DEBUG flag. Yet)
# ---------------------------------------------------------------------
# BUILD FLAGS
# ---------------------------------------------------------------------
# This is probably where you can stop editing
# --- Architecture ---
ARCH := -mthumb-interwork -mthumb
RARCH := -mthumb-interwork -mthumb
IARCH := -mthumb-interwork -marm -mlong-calls
# --- Main flags ---
CFLAGS := -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) -O2
CFLAGS += -Wall
CFLAGS += $(INCLUDE)
CFLAGS += -ffast-math -fno-strict-aliasing
CFLAGS += -DFLOW_CONTROL=$(FLOW_CONTROL)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := $(ARCH)
LDFLAGS := $(ARCH) -Wl,-Map,$(PROJ).map
# --- switched additions ----------------------------------------------
# --- Multiboot ? ---
ifeq ($(strip $(bMB)), 1)
TARGET := $(PROJ).mb
else
TARGET := $(PROJ)
endif
# --- Save temporary files ? ---
ifeq ($(strip $(bTEMPS)), 1)
CFLAGS += -save-temps
endif
# --- Debug info ? ---
ifeq ($(strip $(bDEBUG2)), 1)
CFLAGS += -g
LDFLAGS += -g
endif
# ---------------------------------------------------------------------
# BUILD PROCEDURE
# ---------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
# Still in main dir:
# * Define/export some extra variables
# * Invoke this file again from the build dir
# PONDER: what happens if BUILD == "" ?
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := \
$(foreach dir, $(SRCDIRS) , $(CURDIR)/$(dir)) \
$(foreach dir, $(DATADIRS), $(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
export LIBDIR := $(DEPSDIR)/libuart
export LIBUART := $(LIBDIR)/lib/libuart.a
# --- List source and data files ---
CFILES := $(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir, $(DATADIRS), $(notdir $(wildcard $(dir)/*.*)))
# --- Set linker depending on C++ file existence ---
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
# --- Define object file list ---
export OFILES := \
$(addsuffix .o, $(BINFILES)) \
$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) \
$(SFILES:.s=.o)
export UARTFILES := uart.iwram.o circular_buffer.iwram.o
# --- Create include and library search paths ---
export INCLUDE := \
$(foreach dir,$(INCDIRS),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := -L$(CURDIR) $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
# --- More targets ----------------------------------------------------
.PHONY: $(BUILD) clean
# --- Create $(BUILD) if necessary, and run this makefile from there ---
$(BUILD):
@[ -d $(LIBDIR)/lib ] || mkdir -p $(LIBDIR)/lib
@[ -d $(LIBDIR)/include ] || mkdir -p $(LIBDIR)/include
@cp $(CURDIR)/source/uart.h $(CURDIR)/source/circular_buffer.h $(LIBDIR)/include
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
all : $(BUILD)
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
else # If we're here, we should be in the BUILD dir
DEPENDS := $(OFILES:.o=.d)
# --- Main targets ----
$(OUTPUT).gba : $(OUTPUT).elf $(LIBUART)
$(OUTPUT).elf : $(OFILES)
-include $(DEPENDS)
# --- Lib rules ----
$(LIBUART): $(UARTFILES)
%.a : $(OFILES)
@echo Building $@
@rm -f $@
@$(AR) -crs $@ $^
$(PREFIX)nm -Sn $@ > $(basename $(notdir $@)).map
endif # End BUILD switch
# EOF