Debian Codegraph @

toolchain.mk

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0-only
2
3 # ccache integration
4 ifeq ($(CONFIG_CCACHE),y)
5
6 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
7 ifeq ($(CCACHE),)
8 $(error ccache selected, but not found in PATH)
9 endif
10
11 export CCACHE_COMPILERCHECK=mtime
12 export CCACHE_BASEDIR=$(top)
13 export CCACHE_STATSLOG=$(obj)/ccache.stats
14
15 $(foreach arch,$(ARCH_SUPPORTED), \
16 $(eval CC_$(arch):=$(CCACHE) $(CC_$(arch))))
17
18 HOSTCC:=$(CCACHE) $(HOSTCC)
19 HOSTCXX:=$(CCACHE) $(HOSTCXX)
20 endif
21
22 # clang-tidy integration
23 ifneq ($(CLANG_TIDY),)
24 CLANG_TIDY_CHECKS ?= -checks=*
25 CLANG_TIDY_ARGS ?= -extra-arg=-Wno-packed-not-aligned
26
27 $(foreach arch,$(ARCH_SUPPORTED), \
28 $(eval CC_$(arch):=CCC_CC="$(CC_$(arch))" $(CC) ))
29
30 HOSTCC:=CCC_CC="$(HOSTCC)" $(CC)
31 HOSTCXX:=CCC_CXX="$(HOSTCXX)" $(CXX)
32 endif
33
34 # include-what-you-use integration
35 ifeq ($(CONFIG_IWYU),y)
36
37 IWYU:=$(word 1,$(wildcard $(addsuffix /iwyu,$(subst :, ,$(PATH)))))
38 ifeq ($(IWYU),)
39 $(error include-what-you-use selected, but not found in PATH)
40 endif
41
42 $(foreach arch,$(ARCH_SUPPORTED), \
43 $(eval CC_$(arch):=$(IWYU) ))
44
45 CFLAGS_common := -Xiwyu --prefix_header_includes=remove -Xiwyu --no_comments -Xiwyu --no_fwd_decls $(CFLAGS_common)
46 NOCOMPILE := 1
47 endif
48
49 COREBOOT_STANDARD_STAGES := decompressor bootblock verstage romstage ramstage
50 MAP-decompressor := bootblock
51
52 ARCHDIR-i386 := x86
53 ARCHDIR-x86_32 := x86
54 ARCHDIR-x86_64 := x86
55 ARCHDIR-arm := arm
56 ARCHDIR-arm64 := arm64
57 ARCHDIR-riscv := riscv
58 ARCHDIR-ppc64 := ppc64
59
60 CFLAGS_arm +=
61 CFLAGS_arm64 +=
62 CFLAGS_riscv +=
63 CFLAGS_x86_32 +=
64 CFLAGS_x86_64 += -mcmodel=large -mno-red-zone
65 CFLAGS_ppc64 +=
66
67 GCC_ADAFLAGS_arm +=
68 GCC_ADAFLAGS_arm64 += -mgeneral-regs-only
69 GCC_ADAFLAGS_riscv +=
70 GCC_ADAFLAGS_x86_32 +=
71 GCC_ADAFLAGS_x86_64 += -mcmodel=large -mno-red-zone
72 GCC_ADAFLAGS_ppc64 +=
73
74 # Some boards only provide 2K stacks, so storing lots of data there leads to
75 # problems. Since C rules don't allow us to statically determine the maximum
76 # stack use, we use 1.5K as heuristic, assuming that we typically have lots
77 # of tiny stack frames and the odd large one.
78 #
79 # Store larger buffers in BSS, use static to share data in cache-as-ram
80 # on x86.
81 # Since GCCs detection of dynamic array bounds unfortunately seems to be
82 # very basic, you'll sometimes have to use a static upper bound for the
83 # size and an assert() to make sure it's honored (see gpio_base3_value()
84 # for an example).
85 # (If you absolutely need a larger stack frame and are 100% sure it cannot
86 # cause problems, you can whitelist it with #pragma diagnostic.)
87 ifeq ($(CONFIG_COMPILER_GCC),y)
88 CFLAGS_arm += -Wstack-usage=1536
89 CFLAGS_arm64 += -Wstack-usage=1536
90 CFLAGS_riscv += -Wstack-usage=1536
91 CFLAGS_ppc64 += -Wstack-usage=1536
92 endif
93
94 toolchain_to_dir = \
95 $(foreach arch,$(ARCH_SUPPORTED),\
96 $(eval CPPFLAGS_$(arch) += \
97 -Isrc/arch/$(ARCHDIR-$(arch))/include))
98
99 # set_stage_toolchain: Decides the toolchain to be used by every stage
100 # E.g.: If bootblock is x86_32, it sets ARCH-BOOTBLOCK-y = x86_32, whereas
101 # ARCH-BOOTBLOCK-n = armv7. Then, ARCH-BOOTBLOCK-y can be used anywhere to
102 # decide the compiler toolchain for bootblock stage
103 # This step is essential for initializing the toolchain for coreboot standard
104 # stages i.e. bootblock, romstage and ramstage, since it acts as the second
105 # parameter to create_class_compiler below in init_standard_toolchain
106 map_stage = $(strip $(if $(MAP-$(1)),$(MAP-$(1)),$(1)))
107 set_stage_toolchain= \
108 $(foreach arch,$(ARCH_SUPPORTED), \
109 $(eval ARCH-$(1)-$($(shell \
110 echo CONFIG_ARCH_$(call map_stage,$(1))_$(arch) | \
111 tr '[:lower:]' '[:upper:]')) := $(arch)))
112
113 # standard-archs: Tell which architectures are used by the standard stages.
114 standard-archs = $(sort $(foreach stagearch, \
115 $(patsubst %,ARCH-%-y,$(COREBOOT_STANDARD_STAGES)), \
116 $($(stagearch))))
117
118 # create_class_compiler: Used to create compiler tool set for
119 # special classes
120 # @1: special class
121 # @2: compiler set to be used
122 # e.g.: smm special class uses i386 as compiler set
123 define create_class_compiler
124 $(if $(2),,$(warning *** The toolchain architecture for $(1) is unknown.) \
125 $(warning CONFIG_ARCH_$(1)_* settings in $(DOTCONFIG):) \
126 $(error $(shell grep CONFIG_ARCH_$(1)_ $(DOTCONFIG))))
127 CC_$(1) := $(CC_$(2))
128 GCC_$(1) := $(GCC_CC_$(2))
129 LD_$(1) := $(LD_$(2))
130 NM_$(1) := $(NM_$(2))
131 AR_$(1) := $(AR_$(2))
132 GNATBIND_$(1) := $(GNATBIND_$(2))
133 OBJCOPY_$(1) := $(OBJCOPY_$(2))
134 OBJDUMP_$(1) := $(OBJDUMP_$(2))
135 STRIP_$(1) := $(STRIP_$(2))
136 READELF_$(1) := $(READELF_$(2))
137 CFLAGS_$(1) = $$(CFLAGS_common) $$(CFLAGS_$(2))
138 ADAFLAGS_$(1) = --RTS=$$(obj)/libgnat-$(2)/ $$(ADAFLAGS_common) $$(GCC_ADAFLAGS_$(2))
139 CPPFLAGS_$(1) = $$(CPPFLAGS_common) $$(CPPFLAGS_$(2)) -D__ARCH_$(2)__
140 COMPILER_RT_$(1) := $$(COMPILER_RT_$(2))
141 COMPILER_RT_FLAGS_$(1) := $$(COMPILER_RT_FLAGS_$(2))
142 LDFLAGS_$(1) = $$(LDFLAGS_common) $$(LDFLAGS_$(2))
143 endef
144
145 # define_class: Allows defining any program as dynamic class and compiler tool
146 # set for the same based on the architecture for which the program is to be
147 # compiled
148 # @1: program (class name)
149 # @2: architecture for which the program needs to be compiled
150 # IMP: Ensure that define_class is called before any .c or .S files are added to
151 # the class of the program. Check subdirs-y for order of subdirectory inclusions
152 define define_class
153 classes-y += $(1)
154 $(eval $(call create_class_compiler,$(1),$(2)))
155 endef
156
157 # initialize standard toolchain (CC,AS and others) for give stage
158 # @1 : stage for which the toolchain is to be initialized
159 init_standard_toolchain = \
160 $(eval $(call set_stage_toolchain,$(1))) \
161 $(eval $(call create_class_compiler,$(1),$(ARCH-$(1)-y)))
162
163 init_stages = \
164 $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
165 $(eval $(call init_standard_toolchain,$(stage))))
166
167 $(eval $(call toolchain_to_dir))
168
169 $(call init_stages)
170
171 # Test for coreboot toolchain (except when explicitly not requested)
172 ifneq ($(NOCOMPILE),1)
173 # Only run if we're doing a build (not for tests, kconfig, ...)
174 # rationale: gcc versions by Linux distributions tend to be quite messed up
175 # llvm/clang also needs patches supplied by the coreboot build
176 COMPILERFAIL:=0
177 IASLFAIL:=0
178
179 ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
180 # Verify that the coreboot toolchain is being used.
181 $(foreach arch,$(sort $(foreach stage,\
182 $(COREBOOT_STANDARD_STAGES),$(ARCH-$(stage)-y))), \
183 $(if $(shell if [ -n "$(CC_$(arch))" ]; then \
184 $(CC_$(arch)) -v 2>&1 | grep -q "coreboot toolchain" || \
185 echo not-coreboot; else echo not-coreboot; fi), \
186 $(eval COMPILERFAIL:=1)\
187 $(warning The coreboot toolchain for '$(arch)'\
188 architecture was not found.)\
189 $(if $(CC_$(arch)),\
190 $(warning $(CC_$(arch)) -v)\
191 $(warning $(shell $(CC_$(arch)) -v)))))
192 # If iasl doesn't match the current coreboot version, fail the test
193 # TODO: Figure out if iasl is even needed for the build.
194 $(if $(shell if [ -n "$(IASL)" ]; then \
195 $(IASL) -v 2>&1 | grep -q "coreboot toolchain" || \
196 echo not-coreboot; else echo not-coreboot; fi), \
197 $(eval COMPILERFAIL:=1)$(eval IASLFAIL:=1)\
198 $(warning The coreboot toolchain version of iasl \
199 '$(shell util/crossgcc/buildgcc -s iasl)' was not found))
200 else #$(CONFIG_ANY_TOOLCHAIN)
201 # If the coreboot toolchain isn't being used, verify that there is A toolchain
202 $(foreach arch,$(sort \
203 $(foreach stage,$(COREBOOT_STANDARD_STAGES),$(ARCH-$(stage)-y))), \
204 $(if $(CC_$(arch)),, $(eval COMPILERFAIL:=1) \
205 $(warning No compiler found for '$(arch)' architecture. \
206 Install one or use the coreboot toolchain?)) )
207 # If iasl isn't present, fail
208 # TODO: Figure out if iasl is even needed for the build.
209 $(if $(IASL),, $(eval COMPILERFAIL:=1)$(eval IASLFAIL:=1) \
210 $(warning iasl not found. \
211 Please install it or use the coreboot toolchain.))
212 endif
213
214 # If the compiler check failed, print out warnings
215 ifeq ($(COMPILERFAIL),1)
216 ifneq ($(XGCCPATH),)
217 $(warning )
218 $(warning Path to your toolchain is currently set to '$(XGCCPATH)')
219 endif
220 $(warning )
221 $(warning To build the entire coreboot toolchain: run 'make crossgcc')
222 ifeq ($(IASLFAIL),1)
223 $(warning To build just IASL: run 'make iasl')
224 endif #($(IASLFAIL),1)
225 $(warning For more toolchain build targets: run 'make help_toolchain')
226 $(warning )
227 ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
228 $(warning To try to use any toolchain in your path, \
229 run 'make menuconfig', then select)
230 $(warning the config option: 'General setup', \
231 and 'Allow building with any toolchain')
232 $(warning Note that this is NOT supported. \
233 Using it means you're on your own.)
234 $(warning )
235 endif #($(CONFIG_ANY_TOOLCHAIN),y)
236 $(error Halting the build)
237 endif #($(COMPILERFAIL),1)
238
239 endif #($(NOCOMPILE),1)
240
241 # Run the toolchain version checks if the requested target is 'test-toolchain'
242 # Checks the versions of GCC, binutils, clang, and IASL
243 ifneq ($(MAKECMDGOALS),)
244 ifneq ($(filter test-toolchain,$(MAKECMDGOALS)),)
245 $(foreach arch, $(ARCH_SUPPORTED), \
246 $(if $(shell if [ -n "$(GCC_CC_$(arch))" ]; then \
247 $(GCC_CC_$(arch)) --version 2>&1 | head -n1 | rev | \
248 cut -d ' ' -f 1 | rev | \
249 grep -q "$$(util/crossgcc/buildgcc -s gcc)" || \
250 echo not-current; fi), \
251 $(eval COMPILER_OUT_OF_DATE:=1) \
252 $(warning The coreboot toolchain version of gcc for '$(arch)' \
253 architecture is not the current version.) \
254 $(warning $(arch) gcc version from buildgcc: \
255 $(shell util/crossgcc/buildgcc -s gcc)) \
256 $(warning $(arch) version of gcc executable: \
257 $(shell $(GCC_CC_$(arch)) --version | head -n1 | \
258 rev | cut -d ' ' -f 1 | rev))) \
259 $(if $(shell if [ -n "$(CLANG_CC_$(arch))" ]; then \
260 $(CLANG_CC_$(arch)) --version 2>&1 | \
261 sed 's/.*clang version/clang version/' | \
262 head -n1 | cut -d ' ' -f 3 | \
263 grep -q "$(shell util/crossgcc/buildgcc -s clang)" || \
264 echo not-current; fi), \
265 $(eval COMPILER_OUT_OF_DATE:=1) \
266 $(warning The coreboot toolchain version of clang for \
267 '$(arch)' architecture is not the current version.) \
268 $(warning $(arch) clang version from buildgcc: \
269 $(shell util/crossgcc/buildgcc -s clang)) \
270 $(warning $(arch) version of clang executable: \
271 $(shell $(CLANG_CC_$(arch)) --version 2>&1 | \
272 sed 's/.*clang version/clang version/' | \
273 head -n1 | cut -d ' ' -f 3))) \
274 $(if $(shell if [ "$(OBJDUMP_$(arch))" != "invalidobjdump" ]; then \
275 $(OBJDUMP_$(arch)) -v 2>&1 | \
276 grep -q "$(shell util/crossgcc/buildgcc -s binutils)" || \
277 echo not-current; fi), \
278 $(eval COMPILER_OUT_OF_DATE:=1)\
279 $(warning The coreboot toolchain version of binutils for \
280 '$(arch)' architecture is not the current version.)) \
281 )
282 $(if $(shell if [ -n "$(IASL)" ]; then $(IASL) -v 2>&1 | \
283 grep -q "$(shell util/crossgcc/buildgcc -s iasl)" || \
284 echo not-coreboot; fi), \
285 $(eval COMPILER_OUT_OF_DATE:=1)\
286 $(warning The coreboot toolchain version of iasl \
287 is not the current version) \
288 $(warning $(arch) iasl version from buildgcc: \
289 $(shell util/crossgcc/buildgcc -s iasl)) \
290 $(warning $(arch) version of iasl executable: \
291 $(shell $(IASL) -v 2>&1 | \
292 grep ASL+ | rev | cut -f 1 -d ' ' | rev)))
293 $(eval UPDATED_SUBMODULES:=1)
294 endif #($(filter crossgcc_check%,$(MAKECMDGOALS)),)
295 endif #($(MAKECMDGOALS),)