build: skip toolchain detection for some targets

Most developers run the `clean`, `checkpatch` and other similar targets
without specifying any other additional build options. When combined
with a flow where the developer passes `CROSS_COMPILE` or `CC`
explicitly, and where the default-configured tools are not on the PATH,
these targets will warn about unrecognized toolchain tools.

This change is a workaround for this whereby the toolchain makefile is
not expanded unless a target *not* named `*clean`, `check*` `doc` or
`*tool` has been specified.

Change-Id: I2f2a275964b65253df07c2207043217b14f615fe
Signed-off-by: Chris Kay <chris.kay@arm.com>
This commit is contained in:
Chris Kay 2024-05-14 13:08:31 +00:00
parent 85ea97f972
commit 291e718229
4 changed files with 300 additions and 279 deletions

View file

@ -35,6 +35,17 @@ include ${MAKE_HELPERS_DIRECTORY}defaults.mk
# Configure the toolchains used to build TF-A and its tools # Configure the toolchains used to build TF-A and its tools
################################################################################ ################################################################################
#
# The clean and check targets do not behave correctly if the user's environment
# does not appropriately configure a toolchain. While we try to find a permanent
# solution to this, do not try to detect any toolchains if we are building
# exclusively with targets which do not use any toolchain tools.
#
ifeq ($(filter-out check% %clean doc %tool,$(or $(MAKECMDGOALS),all)),)
toolchains :=
endif
include ${MAKE_HELPERS_DIRECTORY}toolchain.mk include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
# Assertions enabled for DEBUG builds by default # Assertions enabled for DEBUG builds by default
@ -299,7 +310,7 @@ ifeq (${SANITIZE_UB},trap)
-fsanitize-undefined-trap-on-error -fsanitize-undefined-trap-on-error
endif #(${SANITIZE_UB},trap) endif #(${SANITIZE_UB},trap)
GCC_V_OUTPUT := $(shell $($(ARCH)-cc) -v 2>&1) GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
TF_LDFLAGS += -z noexecstack TF_LDFLAGS += -z noexecstack

View file

@ -4,7 +4,11 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
ifeq ($(filter-out clean,$(or $(MAKECMDGOALS),all)),)
toolchains :=
else
toolchains := aarch64 toolchains := aarch64
endif
include ../../make_helpers/toolchain.mk include ../../make_helpers/toolchain.mk

View file

@ -21,7 +21,7 @@
# armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a # armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
# [...] # [...]
# #
GCC_MARCH_OUTPUT := $(shell $($(ARCH)-cc) -march=foo -Q --help=target -v 2>&1) GCC_MARCH_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -march=foo -Q --help=target -v 2>&1))
# This function is used to find the best march value supported by the given compiler. # This function is used to find the best march value supported by the given compiler.
# We try to use `GCC_MARCH_OUTPUT` which has verbose message with supported march values we filter that # We try to use `GCC_MARCH_OUTPUT` which has verbose message with supported march values we filter that

View file

@ -8,13 +8,16 @@
# TF-A uses three toolchains: # TF-A uses three toolchains:
# #
# - The host toolchain (`host`) for building native tools # - The host toolchain (`host`) for building native tools
#  - The AArch32 toolchain (`aarch32`) for building Arm AArch32 images # - The AArch32 toolchain (`aarch32`) for building Arm AArch32 images
# - The AArch64 toolchain (`aarch64`) for building Arm AArch64 images # - The AArch64 toolchain (`aarch64`) for building Arm AArch64 images
# #
# In the main Makefile only one of the two Arm toolchains is enabled in any # In the main Makefile only one of the two Arm toolchains is enabled in any
# given build, but individual tools and libraries may need access to both. # given build, but individual tools and libraries may need access to both.
# #
ifndef toolchain-mk
toolchain-mk := $(lastword $(MAKEFILE_LIST))
toolchains ?= host $(ARCH) toolchains ?= host $(ARCH)
include $(dir $(lastword $(MAKEFILE_LIST)))build_env.mk include $(dir $(lastword $(MAKEFILE_LIST)))build_env.mk
@ -26,8 +29,8 @@ include $(addprefix $(dir $(lastword $(MAKEFILE_LIST)))toolchains/, \
# #
# Configure tool classes that we recognize. # Configure tool classes that we recognize.
# #
# In the context of this build system, a tool class identifies a specific role # In the context of this build system, a tool class identifies a
# or type of tool in the toolchain. # specific role or type of tool in the toolchain.
# #
tool-classes := cc tool-classes := cc
@ -57,12 +60,12 @@ tool-class-name-dtc := device tree compiler
# #
# Configure tools that we recognize. # Configure tools that we recognize.
# #
# Here we declare the list of specific toolchain tools that we know how to # Here we declare the list of specific toolchain tools that we know how
# interact with. We don't organize these into tool classes yet - that happens # to interact with. We don't organize these into tool classes yet - that
# further down. # happens further down.
# #
# Arm® Compiler for Embedded # Arm® Compiler for Embedded
tools := arm-clang tools := arm-clang
tool-name-arm-clang := Arm® Compiler for Embedded `armclang` tool-name-arm-clang := Arm® Compiler for Embedded `armclang`
@ -114,10 +117,10 @@ tool-name-generic-dtc := Device Tree Compiler (`dtc`)
# #
# Assign tools to tool classes. # Assign tools to tool classes.
# #
# Multifunctional tools, i.e. tools which can perform multiple roles in a # Multifunctional tools, i.e. tools which can perform multiple roles in
# toolchain, may be specified in multiple tool class lists. For example, a C # a toolchain, may be specified in multiple tool class lists. For
# compiler which can also perform the role of a linker may be placed in both # example, a C compiler which can also perform the role of a linker may
# `tools-cc` and `tools-ld`. # be placed in both `tools-cc` and `tools-ld`.
# #
# C-related tools # C-related tools
@ -150,14 +153,15 @@ $(foreach tool-class,$(tool-classes), \
# #
# Default tools for each toolchain. # Default tools for each toolchain.
# #
# Toolchains can specify a default path to any given tool with a tool class. # Toolchains can specify a default path to any given tool with a tool
# These values are used in the absence of user-specified values, and are # class. These values are used in the absence of user-specified values,
# configured by the makefile for each toolchain using variables of the form: # and are configured by the makefile for each toolchain using variables
# of the form:
# #
# - $(toolchain)-$(tool-class)-default # - $(toolchain)-$(tool-class)-default
# #
# For example, the default C compiler for the AArch32 and AArch64 toolchains # For example, the default C compiler for the AArch32 and AArch64
# could be configured with: # toolchains could be configured with:
# #
# - aarch32-cc-default # - aarch32-cc-default
# - aarch64-cc-default # - aarch64-cc-default
@ -185,34 +189,34 @@ $(foreach toolchain,$(toolchains), \
# #
# Helper functions to identify toolchain tools. # Helper functions to identify toolchain tools.
# #
# The functions defined in this section return a tool identifier when given a # The functions defined in this section return a tool identifier when
# path to a binary. We generally check a help or version string to more reliably # given a path to a binary. We generally check a help or version string
# identify tools than by looking at the path alone (e.g. `gcc` on macOS is # to more reliably identify tools than by looking at the path alone
# actually Apple Clang). # (e.g. `gcc` on macOS is actually Apple Clang).
# #
# Each tool-guessing function (`guess-tool-$(tool)`) takes a single argument # Each tool-guessing function (`guess-tool-$(tool)`) takes a single
# giving the path to the tool to guess, and returns a non-empty value if the # argument giving the path to the tool to guess, and returns a non-empty
# tool corresponds to the tool identifier `$(tool)`: # value if the tool corresponds to the tool identifier `$(tool)`:
# #
# $(call guess-tool-llvm-clang,aarch64-none-elf-gcc) # <empty> # $(call guess-tool-llvm-clang,aarch64-none-elf-gcc) # <empty>
# $(call guess-tool-gnu-gcc,aarch64-none-elf-gcc) # <non-empty> # $(call guess-tool-gnu-gcc,aarch64-none-elf-gcc) # <non-empty>
# #
# The `guess-tool` function tries to find the corresponding tool identifier # The `guess-tool` function tries to find the corresponding tool
# for a tool given its path. It takes two arguments: # identifier for a tool given its path. It takes two arguments:
# #
# - $(1): a list of candidate tool identifiers to check # - $(1): a list of candidate tool identifiers to check
# - $(2): the path to the tool to identify # - $(2): the path to the tool to identify
# #
# If any of the guess functions corresponding to candidate tool identifiers # If any of the guess functions corresponding to candidate tool
# return a non-empty value then the tool identifier of the first function to do # identifiers return a non-empty value then the tool identifier of the
# so is returned: # first function to do so is returned:
# #
# $(call guess-tool,gnu-gcc llvm-clang,armclang) # <empty> # $(call guess-tool,gnu-gcc llvm-clang,armclang) # <empty>
# $(call guess-tool,gnu-gcc llvm-clang,clang-14) # llvm-clang # $(call guess-tool,gnu-gcc llvm-clang,clang-14) # llvm-clang
# $(call guess-tool,gnu-gcc llvm-clang,aarch64-none-elf-gcc-12) # gnu-gcc # $(call guess-tool,gnu-gcc llvm-clang,aarch64-none-elf-gcc-12) # gnu-gcc
# #
# Tools are checked in the order that they appear in `tools-$(tool-class)`, and # Tools are checked in the order that they appear in
# the first match is returned. # `tools-$(tool-class)`, and the first match is returned.
# #
# Arm Compiler for Embedded # Arm Compiler for Embedded
@ -245,24 +249,25 @@ guess-tool = $(firstword $(foreach candidate,$(1), \
# Locate and identify tools belonging to each toolchain. # Locate and identify tools belonging to each toolchain.
# #
# Each tool class in each toolchain receives a variable of the form # Each tool class in each toolchain receives a variable of the form
# `$(toolchain)-$(tool)` giving the associated path to the program. For example: # `$(toolchain)-$(tool)` giving the associated path to the program. For
# example:
# #
# - `aarch64-ld` gives the linker for the AArch64 toolchain, # - `aarch64-ld` gives the linker for the AArch64 toolchain,
# - `aarch32-oc` gives the object copier for the AArch32 toolchain, and # - `aarch32-oc` gives the object copier for the AArch32 toolchain, and
# - `host-cc` gives the C compiler for the host toolchain. # - `host-cc` gives the C compiler for the host toolchain.
# #
# For each of these variables, if no program path is explicitly provided by the # For each of these variables, if no program path is explicitly provided
# parent Makefile then the C compiler is queried (if supported) for its # by the parent Makefile then the C compiler is queried (if supported)
# location. This is done via the `guess-$(tool)-$(tool-class)` set of functions. # for its location. This is done via the `guess-$(tool)-$(tool-class)`
# For example: # set of functions. For example:
# #
# - `guess-arm-clang-ld` guesses the linker via Arm Clang, # - `guess-arm-clang-ld` guesses the linker via Arm Clang,
# - `guess-llvm-clang-as` guesses the assembler via LLVM Clang, and # - `guess-llvm-clang-as` guesses the assembler via LLVM Clang, and
# - `guess-gnu-gcc-od` guesses the object dumper via GNU GCC. # - `guess-gnu-gcc-od` guesses the object dumper via GNU GCC.
# #
# If the C compiler cannot provide the location (or the tool class is the C # If the C compiler cannot provide the location (or the tool class is
# compiler), then it is assigned the value of the `$(toolchain)-$(tool)-default` # the C compiler), then it is assigned the value of the
# variable. # `$(toolchain)-$(tool)-default` variable.
# #
guess-arm-clang-cpp = $(1) guess-arm-clang-cpp = $(1)
@ -360,3 +365,4 @@ endef
$(foreach toolchain,$(toolchains), \ $(foreach toolchain,$(toolchains), \
$(eval $(call locate-toolchain,$(toolchain)))) $(eval $(call locate-toolchain,$(toolchain))))
endif