blob: 83f2f57e7d6ff47cd50f6d2e03d11a43a790bc1c [file] [log] [blame]
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05301#
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -05002# Copyright (c) 2019-2022, Linaro Limited. All rights reserved.
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05303#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
Sumit Gargb6c4b3c2019-11-11 18:46:36 +05307V ?= 0
8BUILD_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
Chris Kayc8a47ba2023-10-20 09:17:33 +000014toolchains := host
Juan Pablo Conde3539c742022-10-25 19:41:02 -040015
16MAKE_HELPERS_DIRECTORY := ../../make_helpers/
17include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
18include ${MAKE_HELPERS_DIRECTORY}build_env.mk
19include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +000020include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Juan Pablo Conde3539c742022-10-25 19:41:02 -040021
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053022OBJECTS := src/encrypt.o \
23 src/cmd_opt.o \
24 src/main.o
25
26HOSTCCFLAGS := -Wall -std=c99
27
Juan Pablo Conde3539c742022-10-25 19:41:02 -040028# Select OpenSSL version flag according to the OpenSSL build selected
29# from setting the OPENSSL_DIR path.
30$(eval $(call SELECT_OPENSSL_API_VERSION))
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053031
32ifeq (${DEBUG},1)
33 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
34else
35ifeq (${BUILD_INFO},1)
36 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
37else
38 HOSTCCFLAGS += -O2 -DLOG_LEVEL=10
39endif
40endif
41ifeq (${V},0)
42 Q := @
43else
44 Q :=
45endif
46
Juan Pablo Conde3539c742022-10-25 19:41:02 -040047HOSTCCFLAGS += ${DEFINES}
48# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
49# computed value.
50HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
51
52
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053053# Make soft links and include from local directory otherwise wrong headers
54# could get pulled in from firmware tree.
55INC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -050056
57# Include library directories where OpenSSL library files are located.
58# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
59# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
60# directory. However, for a local build of OpenSSL, the built binaries are
61# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
62# ${OPENSSL_DIR}/lib/).
63LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053064LIB := -lssl -lcrypto
65
Juan Pablo Conde3539c742022-10-25 19:41:02 -040066.PHONY: all clean realclean --openssl
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053067
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020068all: --openssl ${BINARY}
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053069
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020070${BINARY}: ${OBJECTS} Makefile
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053071 @echo " HOSTLD $@"
72 @echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__;' | \
Chris Kay523e8642023-12-04 12:03:51 +000073 $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
74 ${Q}$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053075
76%.o: %.c
77 @echo " HOSTCC $<"
Chris Kay523e8642023-12-04 12:03:51 +000078 ${Q}$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053079
Juan Pablo Conde3539c742022-10-25 19:41:02 -040080--openssl:
81ifeq ($(DEBUG),1)
82 @echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
83endif
84
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053085clean:
86 $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
87
88realclean: clean
89 $(call SHELL_DELETE,${BINARY})