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