xref: /rk3399_ARM-atf/tools/cert_create/Makefile (revision b9c20e5d144347ca28e17df080b7ee9bf0dd9377)
1#
2# Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7PLAT		:= none
8DEBUG		:= 0
9CRTTOOL		?= cert_create${BIN_EXT}
10BINARY		:= $(notdir ${CRTTOOL})
11COT		:= tbbr
12
13toolchains := host
14
15MAKE_HELPERS_DIRECTORY := ../../make_helpers/
16include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
17include ${MAKE_HELPERS_DIRECTORY}build_env.mk
18include ${MAKE_HELPERS_DIRECTORY}common.mk
19include ${MAKE_HELPERS_DIRECTORY}defaults.mk
20include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
21include ${MAKE_HELPERS_DIRECTORY}utilities.mk
22
23ifneq (${PLAT},none)
24TF_PLATFORM_ROOT	:=	../../plat/
25include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
26PLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
27endif
28
29# Common source files.
30OBJECTS := src/cert.o \
31           src/cmd_opt.o \
32           src/ext.o \
33           src/key.o \
34           src/main.o \
35           src/sha.o
36
37# Chain of trust.
38ifeq (${COT},tbbr)
39  include src/tbbr/tbbr.mk
40else ifeq (${COT},dualroot)
41  include src/dualroot/cot.mk
42else ifeq (${COT},cca)
43  include src/cca/cot.mk
44else
45  $(error Unknown chain of trust ${COT})
46endif
47
48ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
49include ${PLAT_CERT_CREATE_HELPER_MK}
50endif
51
52# Select OpenSSL version flag according to the OpenSSL build selected
53# from setting the OPENSSL_DIR path.
54$(eval $(call SELECT_OPENSSL_API_VERSION))
55
56HOSTCCFLAGS := -Wall -std=c99
57
58ifeq (${DEBUG},1)
59  HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
60else
61  HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
62endif
63
64HOSTCCFLAGS += ${DEFINES} -DPLAT_MSG=$(call escape-shell,"$(PLAT_MSG)")
65# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
66# computed value.
67HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
68
69# Make soft links and include from local directory otherwise wrong headers
70# could get pulled in from firmware tree.
71INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
72
73# Include library directories where OpenSSL library files are located.
74# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
75# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
76# directory. However, for a local build of OpenSSL, the built binaries are
77# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
78# ${OPENSSL_DIR}/lib/).
79LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
80LIB := -lssl -lcrypto
81
82.PHONY: all clean realclean --openssl
83
84all: --openssl ${BINARY}
85
86${BINARY}: ${OBJECTS} Makefile
87	$(s)echo "  HOSTLD  $@"
88	$(q)$(host-cc) ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
89
90%.o: %.c
91	$(s)echo "  HOSTCC  $<"
92	$(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
93
94--openssl:
95ifeq ($(DEBUG),1)
96	$(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
97endif
98
99clean:
100	$(call SHELL_DELETE_ALL,${OBJECTS})
101
102realclean: clean
103	$(call SHELL_DELETE,${BINARY})
104