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