diff options
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.mk | 284 |
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 | ||
8 | OPT := $(USE_OPT) | ||
9 | COPT := $(USE_COPT) | ||
10 | CPPOPT := $(USE_CPPOPT) | ||
11 | |||
12 | # Garbage collection | ||
13 | ifeq ($(USE_LINK_GC),yes) | ||
14 | OPT += -ffunction-sections -fdata-sections -fno-common | ||
15 | LDOPT := ,--gc-sections | ||
16 | else | ||
17 | LDOPT := | ||
18 | endif | ||
19 | |||
20 | # Linker extra options | ||
21 | ifneq ($(USE_LDOPT),) | ||
22 | LDOPT := $(LDOPT),$(USE_LDOPT) | ||
23 | endif | ||
24 | |||
25 | # Link time optimizations | ||
26 | ifeq ($(USE_LTO),yes) | ||
27 | OPT += -flto | ||
28 | endif | ||
29 | |||
30 | # FPU options default (Cortex-M4 and Cortex-M7 single precision). | ||
31 | ifeq ($(USE_FPU_OPT),) | ||
32 | USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16 | ||
33 | endif | ||
34 | |||
35 | # FPU-related options | ||
36 | ifeq ($(USE_FPU),) | ||
37 | USE_FPU = no | ||
38 | endif | ||
39 | ifneq ($(USE_FPU),no) | ||
40 | OPT += $(USE_FPU_OPT) | ||
41 | DDEFS += -DCORTEX_USE_FPU=TRUE | ||
42 | DADEFS += -DCORTEX_USE_FPU=TRUE | ||
43 | else | ||
44 | OPT += -mfloat-abi=soft | ||
45 | DDEFS += -DCORTEX_USE_FPU=FALSE | ||
46 | DADEFS += -DCORTEX_USE_FPU=FALSE | ||
47 | endif | ||
48 | |||
49 | # Process stack size | ||
50 | ifeq ($(USE_PROCESS_STACKSIZE),) | ||
51 | LDOPT := $(LDOPT),--defsym=__process_stack_size__=0x400 | ||
52 | else | ||
53 | LDOPT := $(LDOPT),--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE) | ||
54 | endif | ||
55 | |||
56 | # Exceptions stack size | ||
57 | ifeq ($(USE_EXCEPTIONS_STACKSIZE),) | ||
58 | LDOPT := $(LDOPT),--defsym=__main_stack_size__=0x400 | ||
59 | else | ||
60 | LDOPT := $(LDOPT),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE) | ||
61 | endif | ||
62 | |||
63 | # Output directory and files | ||
64 | ifeq ($(BUILDDIR),) | ||
65 | BUILDDIR = build | ||
66 | endif | ||
67 | ifeq ($(BUILDDIR),.) | ||
68 | BUILDDIR = build | ||
69 | endif | ||
70 | |||
71 | # Dependencies directory | ||
72 | ifeq ($(DEPDIR),) | ||
73 | DEPDIR = .dep | ||
74 | endif | ||
75 | ifeq ($(DEPDIR),.) | ||
76 | DEPDIR = .dep | ||
77 | endif | ||
78 | |||
79 | OUTFILES := $(BUILDDIR)/$(PROJECT).elf \ | ||
80 | $(BUILDDIR)/$(PROJECT).hex \ | ||
81 | $(BUILDDIR)/$(PROJECT).bin \ | ||
82 | $(BUILDDIR)/$(PROJECT).dmp \ | ||
83 | $(BUILDDIR)/$(PROJECT).list | ||
84 | |||
85 | ifdef SREC | ||
86 | OUTFILES += $(BUILDDIR)/$(PROJECT).srec | ||
87 | endif | ||
88 | |||
89 | # Source files groups and paths | ||
90 | TCSRC += $(CSRC) | ||
91 | TCPPSRC += $(CPPSRC) | ||
92 | TSRC := $(TCSRC) $(TCPPSRC) | ||
93 | SRCPATHS := $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(TSRC))) | ||
94 | |||
95 | # Various directories | ||
96 | OBJDIR := $(BUILDDIR)/obj | ||
97 | LSTDIR := $(BUILDDIR)/lst | ||
98 | |||
99 | # Object files groups | ||
100 | TCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o))) | ||
101 | TCPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o))) | ||
102 | ASMOBJS := $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o))) | ||
103 | ASMXOBJS := $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o))) | ||
104 | OBJS := $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS) | ||
105 | |||
106 | # Paths | ||
107 | IINCDIR := $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR)) | ||
108 | LLIBDIR := $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) | ||
109 | |||
110 | # Macros | ||
111 | DEFS := $(DDEFS) $(UDEFS) | ||
112 | ADEFS := $(DADEFS) $(UADEFS) | ||
113 | |||
114 | # Libs | ||
115 | LIBS := $(DLIBS) $(ULIBS) | ||
116 | |||
117 | # Various settings | ||
118 | MCFLAGS := -mcpu=$(MCU) -mthumb | ||
119 | ODFLAGS = -x --syms | ||
120 | ASFLAGS = $(MCFLAGS) $(OPT) $(ADEFS) | ||
121 | ASXFLAGS = $(MCFLAGS) $(OPT) $(ADEFS) | ||
122 | CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) $(DEFS) | ||
123 | CPPFLAGS = $(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) | ||
128 | LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(STARTUPLD),--script=$(LDSCRIPT)$(LDOPT) | ||
129 | |||
130 | # Generate dependency information | ||
131 | ASFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
132 | ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
133 | CFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
134 | CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
135 | |||
136 | # Paths where to search for sources | ||
137 | VPATH = $(SRCPATHS) | ||
138 | |||
139 | # | ||
140 | # Makefile rules | ||
141 | # | ||
142 | |||
143 | all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK | ||
144 | |||
145 | PRE_MAKE_ALL_RULE_HOOK: | ||
146 | |||
147 | POST_MAKE_ALL_RULE_HOOK: | ||
148 | |||
149 | $(OBJS): | PRE_MAKE_ALL_RULE_HOOK $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(DEPDIR) | ||
150 | |||
151 | $(BUILDDIR): | ||
152 | ifneq ($(USE_VERBOSE_COMPILE),yes) | ||
153 | @echo Compiler Options | ||
154 | @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o | ||
155 | @echo | ||
156 | endif | ||
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) | ||
169 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
170 | @echo | ||
171 | $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@ | ||
172 | else | ||
173 | @echo Compiling $(<F) | ||
174 | @$(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) $< -o $@ | ||
175 | endif | ||
176 | |||
177 | $(TCOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST) | ||
178 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
179 | @echo | ||
180 | $(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@ | ||
181 | else | ||
182 | @echo Compiling $(<F) | ||
183 | @$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@ | ||
184 | endif | ||
185 | |||
186 | $(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST) | ||
187 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
188 | @echo | ||
189 | $(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@ | ||
190 | else | ||
191 | @echo Compiling $(<F) | ||
192 | @$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@ | ||
193 | endif | ||
194 | |||
195 | $(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST) | ||
196 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
197 | @echo | ||
198 | $(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
199 | else | ||
200 | @echo Compiling $(<F) | ||
201 | @$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
202 | endif | ||
203 | |||
204 | $(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT) | ||
205 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
206 | @echo | ||
207 | $(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ | ||
208 | else | ||
209 | @echo Linking $@ | ||
210 | @$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ | ||
211 | endif | ||
212 | |||
213 | %.hex: %.elf | ||
214 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
215 | $(HEX) $< $@ | ||
216 | else | ||
217 | @echo Creating $@ | ||
218 | @$(HEX) $< $@ | ||
219 | endif | ||
220 | |||
221 | %.bin: %.elf | ||
222 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
223 | $(BIN) $< $@ | ||
224 | else | ||
225 | @echo Creating $@ | ||
226 | @$(BIN) $< $@ | ||
227 | endif | ||
228 | |||
229 | %.srec: %.elf | ||
230 | ifdef SREC | ||
231 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
232 | $(SREC) $< $@ | ||
233 | else | ||
234 | @echo Creating $@ | ||
235 | @$(SREC) $< $@ | ||
236 | endif | ||
237 | endif | ||
238 | |||
239 | %.dmp: %.elf | ||
240 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
241 | $(OD) $(ODFLAGS) $< > $@ | ||
242 | $(SZ) $< | ||
243 | else | ||
244 | @echo Creating $@ | ||
245 | @$(OD) $(ODFLAGS) $< > $@ | ||
246 | @echo | ||
247 | @$(SZ) $< | ||
248 | endif | ||
249 | |||
250 | %.list: %.elf | ||
251 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
252 | $(OD) -S $< > $@ | ||
253 | else | ||
254 | @echo Creating $@ | ||
255 | @$(OD) -S $< > $@ | ||
256 | @echo | ||
257 | @echo Done | ||
258 | endif | ||
259 | |||
260 | lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a | ||
261 | |||
262 | $(BUILDDIR)/lib$(PROJECT).a: $(OBJS) | ||
263 | @$(AR) -r $@ $^ | ||
264 | @echo | ||
265 | @echo Done | ||
266 | |||
267 | clean: 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 | |||
277 | CLEAN_RULE_HOOK: | ||
278 | |||
279 | # | ||
280 | # Include the dependency files, should be the last of the makefile | ||
281 | # | ||
282 | -include $(wildcard $(DEPDIR)/*) | ||
283 | |||
284 | # *** EOF *** | ||