arm-trusted-firmware/make_helpers/build_env.mk
Chris Kay cc277de816 build: refactor toolchain detection
This change refactors how we identify the toolchain, with the ultimate
aim of eventually cleaning up the various mechanisms that we employ to
configure default tools, identify the tools in use, and configure
toolchain flags.

To do this, we introduce three new concepts in this change:

- Toolchain identifiers,
- Tool class identifiers, and
- Tool identifiers.

Toolchain identifiers identify a configurable chain of tools targeting
one platform/machine/architecture. Today, these are:

- The host machine, which receives the `host` identifier,
- The AArch32 architecture, which receives the `aarch32` identifier, and
- The AArch64 architecture, which receivs the `aarch64` identifier.

The tools in a toolchain may come from different vendors, and are not
necessarily expected to come from one single toolchain distribution. In
most cases it is perfectly valid to mix tools from different toolchain
distributions, with some exceptions (notably, link-time optimization
generally requires the compiler and the linker to be aligned).

Tool class identifiers identify a class (or "role") of a tool. C
compilers, assemblers and linkers are all examples of tool classes.

Tool identifiers identify a specific tool recognized and supported by
the build system. Every tool that can make up a part of a toolchain must
receive a tool identifier.

These new identifiers can be used to retrieve information about the
toolchain in a more standardized fashion.

For example, logic in a Makefile that should only execute when the C
compiler is GNU GCC can now check the tool identifier for the C compiler
in the relevant toolchain:

    ifeq ($($(ARCH)-cc-id),gnu-gcc)
        ...
    endif

Change-Id: Icc23e43aaa32f4fd01d8187c5202f5012a634e7c
Signed-off-by: Chris Kay <chris.kay@arm.com>
2024-02-06 11:14:52 +00:00

72 lines
2.8 KiB
Makefile

#
# Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# This file contains the logic to identify and include any relevant
# build environment specific make include files.
ifndef BUILD_ENV_MK
BUILD_ENV_MK := $(lastword $(MAKEFILE_LIST))
# Block possible built-in command definitions that are not fully portable.
# This traps occurences that need replacing with our OS portable macros
COPY := $$(error "Replace COPY with call to SHELL_COPY or SHELL_COPY_TREE.")
CP := $$(error "Replace CP with call to SHELL_COPY or SHELL_COPY_TREE.")
DEL := $$(error "Replace DEL with call to SHELL_DELETE.")
MD := $$(error "Replace MD with call to MAKE_PREREQ_DIR.")
MKDIR := $$(error "Replace MKDIR with call to MAKE_PREREQ_DIR.")
RD := $$(error "Replace RD with call to SHELL_REMOVE_DIR.")
RM := $$(error "Replace RM with call to SHELL_DELETE.")
RMDIR := $$(error "Replace RMDIR with call to SHELL_REMOVE_DIR.")
ENV_FILE_TO_INCLUDE := unix.mk
ifdef OSTYPE
ifneq ($(findstring ${OSTYPE}, cygwin),)
ENV_FILE_TO_INCLUDE := cygwin.mk
else
ifneq ($(findstring ${OSTYPE}, MINGW32 mingw msys),)
ENV_FILE_TO_INCLUDE := msys.mk
endif
endif
else
ifdef MSYSTEM
# Although the MINGW MSYS shell sets OSTYPE as msys in its environment,
# it does not appear in the GNU make view of environment variables.
# We use MSYSTEM as an alternative, as that is seen by make
ifneq ($(findstring ${MSYSTEM}, MINGW32 mingw msys),)
OSTYPE ?= msys
ENV_FILE_TO_INCLUDE := msys.mk
endif
else
ifdef OS
ifneq ($(findstring ${OS}, Windows_NT),)
ENV_FILE_TO_INCLUDE := windows.mk
endif
endif
endif
endif
include $(dir $(lastword $(MAKEFILE_LIST)))${ENV_FILE_TO_INCLUDE}
ENV_FILE_TO_INCLUDE :=
ifndef SHELL_COPY
$(error "SHELL_COPY not defined for build environment.")
endif
ifndef SHELL_COPY_TREE
$(error "SHELL_COPY_TREE not defined for build environment.")
endif
ifndef SHELL_DELETE_ALL
$(error "SHELL_DELETE_ALL not defined for build environment.")
endif
ifndef SHELL_DELETE
$(error "SHELL_DELETE not defined for build environment.")
endif
ifndef MAKE_PREREQ_DIR
$(error "MAKE_PREREQ_DIR not defined for build environment.")
endif
ifndef SHELL_REMOVE_DIR
$(error "SHELL_REMOVE_DIR not defined for build environment.")
endif
endif