aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk')
-rw-r--r--lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk352
1 files changed, 352 insertions, 0 deletions
diff --git a/lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk b/lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk
new file mode 100644
index 000000000..85cdbf31a
--- /dev/null
+++ b/lib/chibios/os/common/startup/ARM/compilers/GCC/rules.mk
@@ -0,0 +1,352 @@
1# ARM Cortex-Mx common makefile scripts and rules.
2
3##############################################################################
4# Processing options coming from the upper Makefile.
5#
6
7# Compiler options
8OPT = $(USE_OPT)
9COPT = $(USE_COPT)
10CPPOPT = $(USE_CPPOPT)
11
12# Garbage collection
13ifeq ($(USE_LINK_GC),yes)
14 OPT += -ffunction-sections -fdata-sections -fno-common
15 LDOPT := ,--gc-sections
16else
17 LDOPT :=
18endif
19
20# Linker extra options
21ifneq ($(USE_LDOPT),)
22 LDOPT := $(LDOPT),$(USE_LDOPT)
23endif
24
25# Link time optimizations
26ifeq ($(USE_LTO),yes)
27 OPT += -flto
28endif
29
30# Undefined state stack size
31ifeq ($(USE_UND_STACKSIZE),)
32 LDOPT := $(LDOPT),--defsym=__und_stack_size__=8
33else
34 LDOPT := $(LDOPT),--defsym=__und_stack_size__=$(USE_UND_STACKSIZE)
35endif
36
37# Abort stack size
38ifeq ($(USE_ABT_STACKSIZE),)
39 LDOPT := $(LDOPT),--defsym=__abt_stack_size__=8
40else
41 LDOPT := $(LDOPT),--defsym=__abt_stack_size__=$(USE_ABT_STACKSIZE)
42endif
43
44# FIQ stack size
45ifeq ($(USE_FIQ_STACKSIZE),)
46 LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=64
47else
48 LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=$(USE_FIQ_STACKSIZE)
49endif
50
51# IRQ stack size
52ifeq ($(USE_IRQ_STACKSIZE),)
53 LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400
54else
55 LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_IRQ_STACKSIZE)
56endif
57
58# Supervisor stack size
59ifeq ($(USE_SUPERVISOR_STACKSIZE),)
60 LDOPT := $(LDOPT),--defsym=__svc_stack_size__=8
61else
62 LDOPT := $(LDOPT),--defsym=__svc_stack_size__=$(USE_SUPERVISOR_STACKSIZE)
63endif
64
65# System stack size
66ifeq ($(USE_SYSTEM_STACKSIZE),)
67 LDOPT := $(LDOPT),--defsym=__sys_stack_size__=0x400
68else
69 LDOPT := $(LDOPT),--defsym=__sys_stack_size__=$(USE_SYSTEM_STACKSIZE)
70endif
71
72# Output directory and files
73ifeq ($(BUILDDIR),)
74 BUILDDIR = build
75endif
76ifeq ($(BUILDDIR),.)
77 BUILDDIR = build
78endif
79
80# Dependencies directory
81ifeq ($(DEPDIR),)
82 DEPDIR = .dep
83endif
84ifeq ($(DEPDIR),.)
85 DEPDIR = .dep
86endif
87
88OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \
89 $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp \
90 $(BUILDDIR)/$(PROJECT).list
91
92# Source files groups and paths
93ifeq ($(USE_THUMB),yes)
94 TCSRC += $(CSRC)
95 TCPPSRC += $(CPPSRC)
96else
97 ACSRC += $(CSRC)
98 ACPPSRC += $(CPPSRC)
99endif
100ASRC = $(ACSRC) $(ACPPSRC)
101TSRC = $(TCSRC) $(TCPPSRC)
102SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC)))
103
104# Various directories
105OBJDIR = $(BUILDDIR)/obj
106LSTDIR = $(BUILDDIR)/lst
107
108# Object files groups
109ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
110#ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
111ACPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cpp, %.o, $(filter %.cpp, $(TCPPSRC)))))
112ACCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cc, %.o, $(filter %.cc, $(TCPPSRC)))))
113TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
114#TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
115TCPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cpp, %.o, $(filter %.cpp, $(TCPPSRC)))))
116TCCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cc, %.o, $(filter %.cc, $(TCPPSRC)))))
117ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
118ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
119#OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)
120OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(ACCOBJS) $(TCPPOBJS) $(TCOBJS)
121
122# Paths
123IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
124LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
125
126# Macros
127DEFS = $(DDEFS) $(UDEFS)
128ADEFS = $(DADEFS) $(UADEFS)
129
130# Libs
131LIBS = $(DLIBS) $(ULIBS)
132
133# Various settings
134MCFLAGS = -mcpu=$(MCU)
135ODFLAGS = -x --syms
136ASFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
137ASXFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
138CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
139CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
140LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH)/ld,--script=$(LDSCRIPT)$(LDOPT)
141
142# Thumb interwork enabled only if needed because it kills performance.
143ifneq ($(strip $(TSRC)),)
144 CFLAGS += -DTHUMB_PRESENT
145 CPPFLAGS += -DTHUMB_PRESENT
146 ASFLAGS += -DTHUMB_PRESENT
147 ASXFLAGS += -DTHUMB_PRESENT
148 ifneq ($(strip $(ASRC)),)
149 # Mixed ARM and THUMB mode.
150 CFLAGS += -mthumb-interwork
151 CPPFLAGS += -mthumb-interwork
152 ASFLAGS += -mthumb-interwork
153 ASXFLAGS += -mthumb-interwork
154 LDFLAGS += -mthumb-interwork
155 else
156 # Pure THUMB mode, THUMB C code cannot be called by ARM asm code directly.
157 CFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
158 CPPFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
159 ASFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb
160 ASXFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb
161 LDFLAGS += -mno-thumb-interwork -mthumb
162 endif
163else
164 # Pure ARM mode
165 CFLAGS += -mno-thumb-interwork
166 CPPFLAGS += -mno-thumb-interwork
167 ASFLAGS += -mno-thumb-interwork
168 ASXFLAGS += -mno-thumb-interwork
169 LDFLAGS += -mno-thumb-interwork
170endif
171
172# Generate dependency information
173ASFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
174ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
175CFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
176CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
177
178# Paths where to search for sources
179VPATH = $(SRCPATHS)
180
181#
182# Makefile rules
183#
184
185all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
186
187PRE_MAKE_ALL_RULE_HOOK:
188
189POST_MAKE_ALL_RULE_HOOK:
190
191$(OBJS): | PRE_MAKE_ALL_RULE_HOOK $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(DEPDIR)
192
193$(BUILDDIR):
194ifneq ($(USE_VERBOSE_COMPILE),yes)
195 @echo Compiler Options
196 @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
197 @echo
198endif
199 @mkdir -p $(BUILDDIR)
200
201$(OBJDIR):
202 @mkdir -p $(OBJDIR)
203
204$(LSTDIR):
205 @mkdir -p $(LSTDIR)
206
207$(DEPDIR):
208 @mkdir -p $(DEPDIR)
209
210$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
211ifeq ($(USE_VERBOSE_COMPILE),yes)
212 @echo
213 $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
214else
215 @echo Compiling $(<F)
216 @$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
217endif
218
219$(TCPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
220ifeq ($(USE_VERBOSE_COMPILE),yes)
221 @echo
222 $(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
223else
224 @echo Compiling $(<F)
225 @$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
226endif
227
228$(ACCOBJS) : $(OBJDIR)/%.o : %.cc $(MAKEFILE_LIST)
229ifeq ($(USE_VERBOSE_COMPILE),yes)
230 @echo
231 $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
232else
233 @echo Compiling $(<F)
234 @$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
235endif
236
237$(TCCOBJS) : $(OBJDIR)/%.o : %.cc $(MAKEFILE_LIST)
238ifeq ($(USE_VERBOSE_COMPILE),yes)
239 @echo
240 $(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
241else
242 @echo Compiling $(<F)
243 @$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
244endif
245
246$(ACOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
247ifeq ($(USE_VERBOSE_COMPILE),yes)
248 @echo
249 $(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
250else
251 @echo Compiling $(<F)
252 @$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
253endif
254
255$(TCOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
256ifeq ($(USE_VERBOSE_COMPILE),yes)
257 @echo
258 $(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
259else
260 @echo Compiling $(<F)
261 @$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
262endif
263
264$(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST)
265ifeq ($(USE_VERBOSE_COMPILE),yes)
266 @echo
267 $(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
268else
269 @echo Compiling $(<F)
270 @$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
271endif
272
273$(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST)
274ifeq ($(USE_VERBOSE_COMPILE),yes)
275 @echo
276 $(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
277else
278 @echo Compiling $(<F)
279 @$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
280endif
281
282$(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT)
283ifeq ($(USE_VERBOSE_COMPILE),yes)
284 @echo
285 $(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
286else
287 @echo Linking $@
288 @$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
289endif
290
291%.hex: %.elf
292ifeq ($(USE_VERBOSE_COMPILE),yes)
293 $(HEX) $< $@
294else
295 @echo Creating $@
296 @$(HEX) $< $@
297endif
298
299%.bin: %.elf
300ifeq ($(USE_VERBOSE_COMPILE),yes)
301 $(BIN) $< $@
302else
303 @echo Creating $@
304 @$(BIN) $< $@
305endif
306
307%.dmp: %.elf
308ifeq ($(USE_VERBOSE_COMPILE),yes)
309 $(OD) $(ODFLAGS) $< > $@
310 $(SZ) $<
311else
312 @echo Creating $@
313 @$(OD) $(ODFLAGS) $< > $@
314 @echo
315 @$(SZ) $<
316endif
317
318%.list: %.elf
319ifeq ($(USE_VERBOSE_COMPILE),yes)
320 $(OD) -S $< > $@
321else
322 @echo Creating $@
323 @$(OD) -S $< > $@
324 @echo
325 @echo Done
326endif
327
328lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a
329
330$(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
331 @$(AR) -r $@ $^
332 @echo
333 @echo Done
334
335clean: CLEAN_RULE_HOOK
336 @echo Cleaning
337 @echo - $(DEPDIR)
338 @-rm -fR $(DEPDIR)/* $(BUILDDIR)/* 2>/dev/null
339 @-if [ -d "$(DEPDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(DEPDIR)) 2>/dev/null; fi
340 @echo - $(BUILDDIR)
341 @-if [ -d "$(BUILDDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(BUILDDIR)) 2>/dev/null; fi
342 @echo
343 @echo Done
344
345CLEAN_RULE_HOOK:
346
347#
348# Include the dependency files, should be the last of the makefile
349#
350-include $(wildcard $(DEPDIR)/*)
351
352# *** EOF ***