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})
12OPENSSL_DIR	:= /usr
13COT		:= tbbr
14
15MAKE_HELPERS_DIRECTORY := ../../make_helpers/
16include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
17include ${MAKE_HELPERS_DIRECTORY}build_env.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
48HOSTCCFLAGS := -Wall -std=c99
49
50ifeq (${DEBUG},1)
51  HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
52else
53  HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
54endif
55
56ifeq (${V},0)
57  Q := @
58else
59  Q :=
60endif
61
62HOSTCCFLAGS += ${DEFINES}
63
64# Make soft links and include from local directory otherwise wrong headers
65# could get pulled in from firmware tree.
66INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
67
68# Include library directories where OpenSSL library files are located.
69# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
70# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
71# directory. However, for a local build of OpenSSL, the built binaries are
72# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
73# ${OPENSSL_DIR}/lib/).
74LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
75LIB := -lssl -lcrypto
76
77HOSTCC ?= gcc
78
79.PHONY: all clean realclean
80
81all: ${BINARY}
82
83${BINARY}: ${OBJECTS} Makefile
84	@echo "  HOSTLD  $@"
85	@echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
86                const char platform_msg[] = "${PLAT_MSG}";' | \
87                ${HOSTCC} -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
88	${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
89
90%.o: %.c
91	@echo "  HOSTCC  $<"
92	${Q}${HOSTCC} -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
93
94clean:
95	$(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
96
97realclean: clean
98	$(call SHELL_DELETE,${BINARY})
99
100