arm-trusted-firmware/make_helpers/build_env.mk
Chris Kay f4dd18c270 build: consolidate directory creation rules
This commit streamlines directory creation by introducing a single
pattern rule to automatically make directories for which there is a
dependency.

We currently use several macros to generate rules to create directories
upon dependence, which is a significant amount of code and a lot of
redundancy. The rule introduced by this change represents a catch-all:
any rule dependency on a path ending in a forward slash is automatically
created.

Now, rules can rely on an unordered dependency (`|`) on `$$(@D)/` which,
when secondary expansion is enabled, expands to the directory of the
target being built, e.g.:

    build/main.o: main.c | $$(@D)/ # automatically creates `build/`

Change-Id: I7e554efa2ac850e779bb302fd9c7fbb239886c9f
Signed-off-by: Chris Kay <chris.kay@arm.com>
2024-07-22 09:41:30 +00:00

67 lines
2.5 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.")
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 SHELL_REMOVE_DIR
$(error "SHELL_REMOVE_DIR not defined for build environment.")
endif
endif