blob: 50b0fa2f910e768df65e5a13d18792a9267bfdbb [file] [log] [blame]
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05301#
Chris Kay01995442024-06-14 11:31:03 +00002# Copyright (c) 2024, Arm Limited. All rights reserved.
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -05003# Copyright (c) 2019-2022, Linaro Limited. All rights reserved.
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05304#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05308BUILD_INFO ?= 1
9DEBUG := 0
Manish V Badarkheb9adb522020-09-05 04:40:41 +010010ENCTOOL ?= encrypt_fw${BIN_EXT}
Manish V Badarkhe635482e2020-08-13 05:56:33 +010011BINARY := $(notdir ${ENCTOOL})
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053012OPENSSL_DIR := /usr
13
Juan Pablo Conde3539c742022-10-25 19:41:02 -040014MAKE_HELPERS_DIRECTORY := ../../make_helpers/
15include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
16include ${MAKE_HELPERS_DIRECTORY}build_env.mk
Chris Kay1870c722024-05-02 17:52:37 +000017include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Pablo Conde3539c742022-10-25 19:41:02 -040018include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +000019include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Juan Pablo Conde3539c742022-10-25 19:41:02 -040020
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053021OBJECTS := src/encrypt.o \
22 src/cmd_opt.o \
23 src/main.o
24
25HOSTCCFLAGS := -Wall -std=c99
26
Juan Pablo Conde3539c742022-10-25 19:41:02 -040027# Select OpenSSL version flag according to the OpenSSL build selected
28# from setting the OPENSSL_DIR path.
29$(eval $(call SELECT_OPENSSL_API_VERSION))
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053030
31ifeq (${DEBUG},1)
32 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
33else
34ifeq (${BUILD_INFO},1)
35 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
36else
37 HOSTCCFLAGS += -O2 -DLOG_LEVEL=10
38endif
39endif
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053040
Juan Pablo Conde3539c742022-10-25 19:41:02 -040041HOSTCCFLAGS += ${DEFINES}
42# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
43# computed value.
44HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
45
46
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053047# Make soft links and include from local directory otherwise wrong headers
48# could get pulled in from firmware tree.
49INC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -050050
51# Include library directories where OpenSSL library files are located.
52# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
53# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
54# directory. However, for a local build of OpenSSL, the built binaries are
55# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
56# ${OPENSSL_DIR}/lib/).
57LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053058LIB := -lssl -lcrypto
59
Juan Pablo Conde3539c742022-10-25 19:41:02 -040060.PHONY: all clean realclean --openssl
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053061
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020062all: --openssl ${BINARY}
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053063
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020064${BINARY}: ${OBJECTS} Makefile
Chris Kay1870c722024-05-02 17:52:37 +000065 $(s)echo " HOSTLD $@"
Chris Kay01995442024-06-14 11:31:03 +000066 $(q)$(host-cc) ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053067
68%.o: %.c
Chris Kay1870c722024-05-02 17:52:37 +000069 $(s)echo " HOSTCC $<"
70 $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053071
Juan Pablo Conde3539c742022-10-25 19:41:02 -040072--openssl:
73ifeq ($(DEBUG),1)
Chris Kay1870c722024-05-02 17:52:37 +000074 $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
Juan Pablo Conde3539c742022-10-25 19:41:02 -040075endif
76
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053077clean:
Chris Kay01995442024-06-14 11:31:03 +000078 $(call SHELL_DELETE_ALL,${OBJECTS})
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053079
80realclean: clean
81 $(call SHELL_DELETE,${BINARY})