aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk')
-rw-r--r--lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk284
1 files changed, 284 insertions, 0 deletions
diff --git a/lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk b/lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk
new file mode 100644
index 000000000..bc0cd5c6f
--- /dev/null
+++ b/lib/chibios/os/common/startup/ARMCMx/compilers/LLVM/mk/rules.mk
@@ -0,0 +1,284 @@
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# FPU options default (Cortex-M4 and Cortex-M7 single precision).
31ifeq ($(USE_FPU_OPT),)
32 USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
33endif
34
35# FPU-related options
36ifeq ($(USE_FPU),)
37 USE_FPU = no
38endif
39ifneq ($(USE_FPU),no)
40 OPT += $(USE_FPU_OPT)
41 DDEFS += -DCORTEX_USE_FPU=TRUE
42 DADEFS += -DCORTEX_USE_FPU=TRUE
43else
44 OPT += -mfloat-abi=soft
45 DDEFS += -DCORTEX_USE_FPU=FALSE
46 DADEFS += -DCORTEX_USE_FPU=FALSE
47endif
48
49# Process stack size
50ifeq ($(USE_PROCESS_STACKSIZE),)
51 LDOPT := $(LDOPT),--defsym=__process_stack_size__=0x400
52else
53 LDOPT := $(LDOPT),--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
54endif
55
56# Exceptions stack size
57ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
58 LDOPT := $(LDOPT),--defsym=__main_stack_size__=0x400
59else
60 LDOPT := $(LDOPT),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
61endif
62
63# Output directory and files
64ifeq ($(BUILDDIR),)
65 BUILDDIR = build
66endif
67ifeq ($(BUILDDIR),.)
68 BUILDDIR = build
69endif
70
71# Dependencies directory
72ifeq ($(DEPDIR),)
73 DEPDIR = .dep
74endif
75ifeq ($(DEPDIR),.)
76 DEPDIR = .dep
77endif
78
79OUTFILES := $(BUILDDIR)/$(PROJECT).elf \
80 $(BUILDDIR)/$(PROJECT).hex \
81 $(BUILDDIR)/$(PROJECT).bin \
82 $(BUILDDIR)/$(PROJECT).dmp \
83 $(BUILDDIR)/$(PROJECT).list
84
85ifdef SREC
86 OUTFILES += $(BUILDDIR)/$(PROJECT).srec
87endif
88
89# Source files groups and paths
90TCSRC += $(CSRC)
91TCPPSRC += $(CPPSRC)
92TSRC := $(TCSRC) $(TCPPSRC)
93SRCPATHS := $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(TSRC)))
94
95# Various directories
96OBJDIR := $(BUILDDIR)/obj
97LSTDIR := $(BUILDDIR)/lst
98
99# Object files groups
100TCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
101TCPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
102ASMOBJS := $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
103ASMXOBJS := $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
104OBJS := $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)
105
106# Paths
107IINCDIR := $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
108LLIBDIR := $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
109
110# Macros
111DEFS := $(DDEFS) $(UDEFS)
112ADEFS := $(DADEFS) $(UADEFS)
113
114# Libs
115LIBS := $(DLIBS) $(ULIBS)
116
117# Various settings
118MCFLAGS := -mcpu=$(MCU) -mthumb
119ODFLAGS = -x --syms
120ASFLAGS = $(MCFLAGS) $(OPT) $(ADEFS)
121ASXFLAGS = $(MCFLAGS) $(OPT) $(ADEFS)
122CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) $(DEFS)
123CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) $(DEFS)
124#ASFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
125#ASXFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
126#CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
127#CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
128LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(STARTUPLD),--script=$(LDSCRIPT)$(LDOPT)
129
130# Generate dependency information
131ASFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
132ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
133CFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
134CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
135
136# Paths where to search for sources
137VPATH = $(SRCPATHS)
138
139#
140# Makefile rules
141#
142
143all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
144
145PRE_MAKE_ALL_RULE_HOOK:
146
147POST_MAKE_ALL_RULE_HOOK:
148
149$(OBJS): | PRE_MAKE_ALL_RULE_HOOK $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(DEPDIR)
150
151$(BUILDDIR):
152ifneq ($(USE_VERBOSE_COMPILE),yes)
153 @echo Compiler Options
154 @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
155 @echo
156endif
157 @mkdir -p $(BUILDDIR)
158
159$(OBJDIR):
160 @mkdir -p $(OBJDIR)
161
162$(LSTDIR):
163 @mkdir -p $(LSTDIR)
164
165$(DEPDIR):
166 @mkdir -p $(DEPDIR)
167
168$(TCPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
169ifeq ($(USE_VERBOSE_COMPILE),yes)
170 @echo
171 $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
172else
173 @echo Compiling $(<F)
174 @$(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@
175endif
176
177$(TCOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
178ifeq ($(USE_VERBOSE_COMPILE),yes)
179 @echo
180 $(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
181else
182 @echo Compiling $(<F)
183 @$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
184endif
185
186$(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST)
187ifeq ($(USE_VERBOSE_COMPILE),yes)
188 @echo
189 $(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
190else
191 @echo Compiling $(<F)
192 @$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
193endif
194
195$(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST)
196ifeq ($(USE_VERBOSE_COMPILE),yes)
197 @echo
198 $(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
199else
200 @echo Compiling $(<F)
201 @$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
202endif
203
204$(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT)
205ifeq ($(USE_VERBOSE_COMPILE),yes)
206 @echo
207 $(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
208else
209 @echo Linking $@
210 @$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
211endif
212
213%.hex: %.elf
214ifeq ($(USE_VERBOSE_COMPILE),yes)
215 $(HEX) $< $@
216else
217 @echo Creating $@
218 @$(HEX) $< $@
219endif
220
221%.bin: %.elf
222ifeq ($(USE_VERBOSE_COMPILE),yes)
223 $(BIN) $< $@
224else
225 @echo Creating $@
226 @$(BIN) $< $@
227endif
228
229%.srec: %.elf
230ifdef SREC
231 ifeq ($(USE_VERBOSE_COMPILE),yes)
232 $(SREC) $< $@
233 else
234 @echo Creating $@
235 @$(SREC) $< $@
236 endif
237endif
238
239%.dmp: %.elf
240ifeq ($(USE_VERBOSE_COMPILE),yes)
241 $(OD) $(ODFLAGS) $< > $@
242 $(SZ) $<
243else
244 @echo Creating $@
245 @$(OD) $(ODFLAGS) $< > $@
246 @echo
247 @$(SZ) $<
248endif
249
250%.list: %.elf
251ifeq ($(USE_VERBOSE_COMPILE),yes)
252 $(OD) -S $< > $@
253else
254 @echo Creating $@
255 @$(OD) -S $< > $@
256 @echo
257 @echo Done
258endif
259
260lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a
261
262$(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
263 @$(AR) -r $@ $^
264 @echo
265 @echo Done
266
267clean: CLEAN_RULE_HOOK
268 @echo Cleaning
269 @echo - $(DEPDIR)
270 @-rm -fR $(DEPDIR)/* $(BUILDDIR)/* 2>/dev/null
271 @-if [ -d "$(DEPDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(DEPDIR)) 2>/dev/null; fi
272 @echo - $(BUILDDIR)
273 @-if [ -d "$(BUILDDIR)" ]; then rmdir -p --ignore-fail-on-non-empty $(subst ./,,$(BUILDDIR)) 2>/dev/null; fi
274 @echo
275 @echo Done
276
277CLEAN_RULE_HOOK:
278
279#
280# Include the dependency files, should be the last of the makefile
281#
282-include $(wildcard $(DEPDIR)/*)
283
284# *** EOF ***