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