Files
arm-trusted-firmware/tools/fiptool/Makefile
T
Boyan Karatotev cbd6cec3c3 feat(build): put fiptool in the build directory
For some reason, tools are not built in the build directory, but rather
in the source directory, regardless of what BUILD_BASE might say. This
is especially annoying when trying to have a few builds going at the
same time (like in a CI). For example, run A may check if a file X
exists. Seeing that it does not, it will start building the file. At the
same time, run B may also check if file X exists but before A has
written it, starting a build again. Then it is possible for A to use the
file it believes to have built right at the moment B begins writing to
it (and truncating it beforehand). This results in gcc failing to read a
fail and a failed build. The more parallel runs there are, the more
likely this is to happen, and this is virtually guaranteed to happen
with just a handful onwards.

So move fiptool and all of its build artefacts to the build directory.
Since there are platform differences between the various fiptool
incarnations, this goes in the plat build rather than a more top-level
location.

This patch adds the build macro MAKE_TOOL to do this generically for any
kind of tool since the other tools suffer from the same shortfall. This
macro takes care to use unique names for every type of argument that
building a tool might need. The fiptool makefile and platform add-ons
are updated accordingly.

This should have never been allowed in the first place, but downstream
scripts almost certainly depend on this behaviour now. So add a symlink
in the place of the old fiptool so these continue working. With any
luck, this will be removed in the future.

Change-Id: I3d4d87dab0f53deab5b43fbc6652146f0e4e7e81
Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
2025-07-07 16:15:39 +01:00

80 lines
2.3 KiB
Makefile

#
# Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
include ${MAKE_HELPERS_DIRECTORY}common.mk
include ${MAKE_HELPERS_DIRECTORY}defaults.mk
include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
FIPTOOL_SOURCES := fiptool.c tbbr_config.c
STATIC ?= 0
FIPTOOL_DEFINES += _GNU_SOURCE _XOPEN_SOURCE=700
FIPTOOL_CFLAGS := -Wall -Werror -pedantic -std=c99
ifeq (${DEBUG},1)
FIPTOOL_CFLAGS += -g -O0 -DDEBUG
else
FIPTOOL_CFLAGS += -O2
endif
FIPTOOL_INCLUDE_DIRS := ../../include/tools_share
FIPTOOL_DEFINES += STATIC=$(STATIC)
ifeq (${STATIC},1)
FIPTOOL_LDFLAGS := -static
else
OPENSSL_DIR := /usr
# Select OpenSSL version flag according to the OpenSSL build selected
# from setting the OPENSSL_DIR path.
$(eval $(call SELECT_OPENSSL_API_VERSION))
# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
# computed value.
FIPTOOL_DEFINES += USING_OPENSSL3=$(USING_OPENSSL3)
# Include library directories where OpenSSL library files are located.
# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
# directory. However, for a local build of OpenSSL, the built binaries are
# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
# ${OPENSSL_DIR}/lib/).
FIPTOOL_LDFLAGS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto
FIPTOOL_INCLUDE_DIRS += ${OPENSSL_DIR}/include
endif # STATIC
ifneq (${PLAT},)
TF_PLATFORM_ROOT := ../../plat/
include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
COMBINED_PATH_FRAG := plat_fiptool/
PLAT_FIPTOOL_HELPER_MK := $(foreach path_frag,$(subst /, ,$(patsubst ../../plat/%/,%,${PLAT_DIR})),\
$(eval COMBINED_PATH_FRAG := ${COMBINED_PATH_FRAG}/${path_frag})\
$(wildcard ${COMBINED_PATH_FRAG}/plat_fiptool.mk))
endif
ifneq (,$(wildcard $(lastword ${PLAT_FIPTOOL_HELPER_MK})))
include ${PLAT_FIPTOOL_HELPER_MK}
endif
$(eval $(call MAKE_TOOL,$(BUILD_PLAT)/tools,fiptool,FIPTOOL))
.PHONY: all clean distclean --openssl
all: --openssl
--openssl:
ifeq ($(STATIC),0)
ifeq ($(DEBUG),1)
$(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
endif
endif # STATIC
clean:
$(q)rm -rf $(BUILD_PLAT)/tools/fiptool