| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 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 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 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 |
|
| 114 |
standard-archs = $(sort $(foreach stagearch, \ |
| 115 |
$(patsubst %,ARCH-%-y,$(COREBOOT_STANDARD_STAGES)), \ |
| 116 |
$($(stagearch)))) |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 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 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
define define_class |
| 153 |
classes-y += $(1) |
| 154 |
$(eval $(call create_class_compiler,$(1),$(2))) |
| 155 |
endef |
| 156 |
|
| 157 |
|
| 158 |
|
| 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 |
|
| 172 |
ifneq ($(NOCOMPILE),1) |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
COMPILERFAIL:=0 |
| 177 |
IASLFAIL:=0 |
| 178 |
|
| 179 |
ifneq ($(CONFIG_ANY_TOOLCHAIN),y) |
| 180 |
|
| 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 |
|
| 193 |
|
| 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 |
| 201 |
|
| 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 |
|
| 208 |
|
| 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 |
|
| 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 |
| 236 |
$(error Halting the build) |
| 237 |
endif |
| 238 |
|
| 239 |
endif |
| 240 |
|
| 241 |
|
| 242 |
|
| 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 |
| 295 |
endif |