diff options
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.mk | 352 |
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 | ||
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 | # Undefined state stack size | ||
31 | ifeq ($(USE_UND_STACKSIZE),) | ||
32 | LDOPT := $(LDOPT),--defsym=__und_stack_size__=8 | ||
33 | else | ||
34 | LDOPT := $(LDOPT),--defsym=__und_stack_size__=$(USE_UND_STACKSIZE) | ||
35 | endif | ||
36 | |||
37 | # Abort stack size | ||
38 | ifeq ($(USE_ABT_STACKSIZE),) | ||
39 | LDOPT := $(LDOPT),--defsym=__abt_stack_size__=8 | ||
40 | else | ||
41 | LDOPT := $(LDOPT),--defsym=__abt_stack_size__=$(USE_ABT_STACKSIZE) | ||
42 | endif | ||
43 | |||
44 | # FIQ stack size | ||
45 | ifeq ($(USE_FIQ_STACKSIZE),) | ||
46 | LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=64 | ||
47 | else | ||
48 | LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=$(USE_FIQ_STACKSIZE) | ||
49 | endif | ||
50 | |||
51 | # IRQ stack size | ||
52 | ifeq ($(USE_IRQ_STACKSIZE),) | ||
53 | LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400 | ||
54 | else | ||
55 | LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_IRQ_STACKSIZE) | ||
56 | endif | ||
57 | |||
58 | # Supervisor stack size | ||
59 | ifeq ($(USE_SUPERVISOR_STACKSIZE),) | ||
60 | LDOPT := $(LDOPT),--defsym=__svc_stack_size__=8 | ||
61 | else | ||
62 | LDOPT := $(LDOPT),--defsym=__svc_stack_size__=$(USE_SUPERVISOR_STACKSIZE) | ||
63 | endif | ||
64 | |||
65 | # System stack size | ||
66 | ifeq ($(USE_SYSTEM_STACKSIZE),) | ||
67 | LDOPT := $(LDOPT),--defsym=__sys_stack_size__=0x400 | ||
68 | else | ||
69 | LDOPT := $(LDOPT),--defsym=__sys_stack_size__=$(USE_SYSTEM_STACKSIZE) | ||
70 | endif | ||
71 | |||
72 | # Output directory and files | ||
73 | ifeq ($(BUILDDIR),) | ||
74 | BUILDDIR = build | ||
75 | endif | ||
76 | ifeq ($(BUILDDIR),.) | ||
77 | BUILDDIR = build | ||
78 | endif | ||
79 | |||
80 | # Dependencies directory | ||
81 | ifeq ($(DEPDIR),) | ||
82 | DEPDIR = .dep | ||
83 | endif | ||
84 | ifeq ($(DEPDIR),.) | ||
85 | DEPDIR = .dep | ||
86 | endif | ||
87 | |||
88 | OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \ | ||
89 | $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp \ | ||
90 | $(BUILDDIR)/$(PROJECT).list | ||
91 | |||
92 | # Source files groups and paths | ||
93 | ifeq ($(USE_THUMB),yes) | ||
94 | TCSRC += $(CSRC) | ||
95 | TCPPSRC += $(CPPSRC) | ||
96 | else | ||
97 | ACSRC += $(CSRC) | ||
98 | ACPPSRC += $(CPPSRC) | ||
99 | endif | ||
100 | ASRC = $(ACSRC) $(ACPPSRC) | ||
101 | TSRC = $(TCSRC) $(TCPPSRC) | ||
102 | SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC))) | ||
103 | |||
104 | # Various directories | ||
105 | OBJDIR = $(BUILDDIR)/obj | ||
106 | LSTDIR = $(BUILDDIR)/lst | ||
107 | |||
108 | # Object files groups | ||
109 | ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o))) | ||
110 | #ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o))) | ||
111 | ACPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cpp, %.o, $(filter %.cpp, $(TCPPSRC))))) | ||
112 | ACCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cc, %.o, $(filter %.cc, $(TCPPSRC))))) | ||
113 | TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o))) | ||
114 | #TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o))) | ||
115 | TCPPOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cpp, %.o, $(filter %.cpp, $(TCPPSRC))))) | ||
116 | TCCOBJS := $(addprefix $(OBJDIR)/, $(notdir $(patsubst %.cc, %.o, $(filter %.cc, $(TCPPSRC))))) | ||
117 | ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o))) | ||
118 | ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o))) | ||
119 | #OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS) | ||
120 | OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(ACCOBJS) $(TCPPOBJS) $(TCOBJS) | ||
121 | |||
122 | # Paths | ||
123 | IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR)) | ||
124 | LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) | ||
125 | |||
126 | # Macros | ||
127 | DEFS = $(DDEFS) $(UDEFS) | ||
128 | ADEFS = $(DADEFS) $(UADEFS) | ||
129 | |||
130 | # Libs | ||
131 | LIBS = $(DLIBS) $(ULIBS) | ||
132 | |||
133 | # Various settings | ||
134 | MCFLAGS = -mcpu=$(MCU) | ||
135 | ODFLAGS = -x --syms | ||
136 | ASFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS) | ||
137 | ASXFLAGS = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS) | ||
138 | CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS) | ||
139 | CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS) | ||
140 | LDFLAGS = $(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. | ||
143 | ifneq ($(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 | ||
163 | else | ||
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 | ||
170 | endif | ||
171 | |||
172 | # Generate dependency information | ||
173 | ASFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
174 | ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
175 | CFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
176 | CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d | ||
177 | |||
178 | # Paths where to search for sources | ||
179 | VPATH = $(SRCPATHS) | ||
180 | |||
181 | # | ||
182 | # Makefile rules | ||
183 | # | ||
184 | |||
185 | all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK | ||
186 | |||
187 | PRE_MAKE_ALL_RULE_HOOK: | ||
188 | |||
189 | POST_MAKE_ALL_RULE_HOOK: | ||
190 | |||
191 | $(OBJS): | PRE_MAKE_ALL_RULE_HOOK $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(DEPDIR) | ||
192 | |||
193 | $(BUILDDIR): | ||
194 | ifneq ($(USE_VERBOSE_COMPILE),yes) | ||
195 | @echo Compiler Options | ||
196 | @echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o | ||
197 | @echo | ||
198 | endif | ||
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) | ||
211 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
212 | @echo | ||
213 | $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
214 | else | ||
215 | @echo Compiling $(<F) | ||
216 | @$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
217 | endif | ||
218 | |||
219 | $(TCPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST) | ||
220 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
221 | @echo | ||
222 | $(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
223 | else | ||
224 | @echo Compiling $(<F) | ||
225 | @$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
226 | endif | ||
227 | |||
228 | $(ACCOBJS) : $(OBJDIR)/%.o : %.cc $(MAKEFILE_LIST) | ||
229 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
230 | @echo | ||
231 | $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
232 | else | ||
233 | @echo Compiling $(<F) | ||
234 | @$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
235 | endif | ||
236 | |||
237 | $(TCCOBJS) : $(OBJDIR)/%.o : %.cc $(MAKEFILE_LIST) | ||
238 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
239 | @echo | ||
240 | $(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
241 | else | ||
242 | @echo Compiling $(<F) | ||
243 | @$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
244 | endif | ||
245 | |||
246 | $(ACOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST) | ||
247 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
248 | @echo | ||
249 | $(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
250 | else | ||
251 | @echo Compiling $(<F) | ||
252 | @$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@ | ||
253 | endif | ||
254 | |||
255 | $(TCOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST) | ||
256 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
257 | @echo | ||
258 | $(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
259 | else | ||
260 | @echo Compiling $(<F) | ||
261 | @$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
262 | endif | ||
263 | |||
264 | $(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST) | ||
265 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
266 | @echo | ||
267 | $(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@ | ||
268 | else | ||
269 | @echo Compiling $(<F) | ||
270 | @$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@ | ||
271 | endif | ||
272 | |||
273 | $(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST) | ||
274 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
275 | @echo | ||
276 | $(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
277 | else | ||
278 | @echo Compiling $(<F) | ||
279 | @$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@ | ||
280 | endif | ||
281 | |||
282 | $(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT) | ||
283 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
284 | @echo | ||
285 | $(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ | ||
286 | else | ||
287 | @echo Linking $@ | ||
288 | @$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ | ||
289 | endif | ||
290 | |||
291 | %.hex: %.elf | ||
292 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
293 | $(HEX) $< $@ | ||
294 | else | ||
295 | @echo Creating $@ | ||
296 | @$(HEX) $< $@ | ||
297 | endif | ||
298 | |||
299 | %.bin: %.elf | ||
300 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
301 | $(BIN) $< $@ | ||
302 | else | ||
303 | @echo Creating $@ | ||
304 | @$(BIN) $< $@ | ||
305 | endif | ||
306 | |||
307 | %.dmp: %.elf | ||
308 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
309 | $(OD) $(ODFLAGS) $< > $@ | ||
310 | $(SZ) $< | ||
311 | else | ||
312 | @echo Creating $@ | ||
313 | @$(OD) $(ODFLAGS) $< > $@ | ||
314 | @echo | ||
315 | @$(SZ) $< | ||
316 | endif | ||
317 | |||
318 | %.list: %.elf | ||
319 | ifeq ($(USE_VERBOSE_COMPILE),yes) | ||
320 | $(OD) -S $< > $@ | ||
321 | else | ||
322 | @echo Creating $@ | ||
323 | @$(OD) -S $< > $@ | ||
324 | @echo | ||
325 | @echo Done | ||
326 | endif | ||
327 | |||
328 | lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a | ||
329 | |||
330 | $(BUILDDIR)/lib$(PROJECT).a: $(OBJS) | ||
331 | @$(AR) -r $@ $^ | ||
332 | @echo | ||
333 | @echo Done | ||
334 | |||
335 | clean: 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 | |||
345 | CLEAN_RULE_HOOK: | ||
346 | |||
347 | # | ||
348 | # Include the dependency files, should be the last of the makefile | ||
349 | # | ||
350 | -include $(wildcard $(DEPDIR)/*) | ||
351 | |||
352 | # *** EOF *** | ||