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