1#
2# Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7toolchains := host
8
9MAKE_HELPERS_DIRECTORY := ../../make_helpers/
10include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
11include ${MAKE_HELPERS_DIRECTORY}build_env.mk
12include ${MAKE_HELPERS_DIRECTORY}defaults.mk
13include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
14
15FIPTOOL ?= fiptool${BIN_EXT}
16PROJECT := $(notdir ${FIPTOOL})
17OBJECTS := fiptool.o tbbr_config.o
18V ?= 0
19STATIC ?= 0
20
21override CPPFLAGS += -D_GNU_SOURCE -D_XOPEN_SOURCE=700
22HOSTCCFLAGS := -Wall -Werror -pedantic -std=c99
23ifeq (${DEBUG},1)
24  HOSTCCFLAGS += -g -O0 -DDEBUG
25else
26  HOSTCCFLAGS += -O2
27endif
28
29INCLUDE_PATHS := -I../../include/tools_share
30
31DEFINES += -DSTATIC=$(STATIC)
32
33ifeq (${STATIC},1)
34LDOPTS := -static
35else
36OPENSSL_DIR := /usr
37
38# Select OpenSSL version flag according to the OpenSSL build selected
39# from setting the OPENSSL_DIR path.
40$(eval $(call SELECT_OPENSSL_API_VERSION))
41
42# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
43# computed value.
44DEFINES += -DUSING_OPENSSL3=$(USING_OPENSSL3)
45
46# Include library directories where OpenSSL library files are located.
47# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
48# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
49# directory. However, for a local build of OpenSSL, the built binaries are
50# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
51# ${OPENSSL_DIR}/lib/).
52LDOPTS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto
53INCLUDE_PATHS += -I${OPENSSL_DIR}/include
54endif # STATIC
55
56HOSTCCFLAGS += ${DEFINES}
57
58ifeq (${V},0)
59  Q := @
60else
61  Q :=
62endif
63
64ifneq (${PLAT},)
65TF_PLATFORM_ROOT	:=	../../plat/
66include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
67COMBINED_PATH_FRAG := plat_fiptool/
68PLAT_FIPTOOL_HELPER_MK := $(foreach path_frag,$(subst /, ,$(patsubst ../../plat/%/,%,${PLAT_DIR})),\
69			  $(eval COMBINED_PATH_FRAG := ${COMBINED_PATH_FRAG}/${path_frag})\
70			  $(wildcard ${COMBINED_PATH_FRAG}/plat_fiptool.mk))
71endif
72
73ifneq (,$(wildcard $(lastword ${PLAT_FIPTOOL_HELPER_MK})))
74include ${PLAT_FIPTOOL_HELPER_MK}
75endif
76
77DEPS := $(patsubst %.o,%.d,$(OBJECTS))
78
79.PHONY: all clean distclean --openssl
80
81all: --openssl ${PROJECT}
82
83${PROJECT}: ${OBJECTS} Makefile
84	@echo "  HOSTLD  $@"
85	${Q}$(host-cc) ${OBJECTS} -o $@ $(LDOPTS)
86	@${ECHO_BLANK_LINE}
87	@echo "Built $@ successfully"
88	@${ECHO_BLANK_LINE}
89
90%.o: %.c Makefile
91	@echo "  HOSTCC  $<"
92	${Q}$(host-cc) -c ${CPPFLAGS} ${HOSTCCFLAGS} ${INCLUDE_PATHS} -MD -MP $< -o $@
93
94-include $(DEPS)
95
96--openssl:
97ifeq ($(STATIC),0)
98ifeq ($(DEBUG),1)
99	@echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
100endif
101endif # STATIC
102
103clean:
104	$(call SHELL_DELETE_ALL, ${PROJECT} ${OBJECTS} $(DEPS))
105