blob: 924e5febab83f35d1e9749da4c64d42caee278fc [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
Juan Pablo Conde3539c742022-10-25 19:41:02 -040014
15MAKE_HELPERS_DIRECTORY := ../../make_helpers/
16include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
17include ${MAKE_HELPERS_DIRECTORY}build_env.mk
18include ${MAKE_HELPERS_DIRECTORY}defaults.mk
19
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053020OBJECTS := src/encrypt.o \
21 src/cmd_opt.o \
22 src/main.o
23
24HOSTCCFLAGS := -Wall -std=c99
25
Juan Pablo Conde3539c742022-10-25 19:41:02 -040026# Select OpenSSL version flag according to the OpenSSL build selected
27# from setting the OPENSSL_DIR path.
28$(eval $(call SELECT_OPENSSL_API_VERSION))
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053029
30ifeq (${DEBUG},1)
31 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
32else
33ifeq (${BUILD_INFO},1)
34 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
35else
36 HOSTCCFLAGS += -O2 -DLOG_LEVEL=10
37endif
38endif
39ifeq (${V},0)
40 Q := @
41else
42 Q :=
43endif
44
Juan Pablo Conde3539c742022-10-25 19:41:02 -040045HOSTCCFLAGS += ${DEFINES}
46# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
47# computed value.
48HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
49
50
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053051# Make soft links and include from local directory otherwise wrong headers
52# could get pulled in from firmware tree.
53INC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -050054
55# Include library directories where OpenSSL library files are located.
56# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
57# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
58# directory. However, for a local build of OpenSSL, the built binaries are
59# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
60# ${OPENSSL_DIR}/lib/).
61LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Sumit Gargb6c4b3c2019-11-11 18:46:36 +053062LIB := -lssl -lcrypto
63
64HOSTCC ?= gcc
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__;' | \
73 ${HOSTCC} -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
74 ${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
75
76%.o: %.c
77 @echo " HOSTCC $<"
78 ${Q}${HOSTCC} -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
79
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})