1#
2# Copyright (c) 2015-2021, 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
39  $(error Unknown chain of trust ${COT})
40endif
41
42ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
43include ${PLAT_CERT_CREATE_HELPER_MK}
44endif
45
46HOSTCCFLAGS := -Wall -std=c99
47
48ifeq (${DEBUG},1)
49  HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
50else
51  HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
52endif
53
54ifeq (${V},0)
55  Q := @
56else
57  Q :=
58endif
59
60HOSTCCFLAGS += ${DEFINES}
61
62# Make soft links and include from local directory otherwise wrong headers
63# could get pulled in from firmware tree.
64INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
65LIB_DIR := -L ${OPENSSL_DIR}/lib
66LIB := -lssl -lcrypto
67
68HOSTCC ?= gcc
69
70.PHONY: all clean realclean
71
72all: ${BINARY}
73
74${BINARY}: ${OBJECTS} Makefile
75	@echo "  HOSTLD  $@"
76	@echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
77                const char platform_msg[] = "${PLAT_MSG}";' | \
78                ${HOSTCC} -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
79	${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
80
81%.o: %.c
82	@echo "  HOSTCC  $<"
83	${Q}${HOSTCC} -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
84
85clean:
86	$(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
87
88realclean: clean
89	$(call SHELL_DELETE,${BINARY})
90
91