Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 1 | # |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 2 | # Copyright (c) 2019-2022, Linaro Limited. All rights reserved. |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 7 | V ?= 0 |
| 8 | BUILD_INFO ?= 1 |
| 9 | DEBUG := 0 |
Manish V Badarkhe | b9adb52 | 2020-09-05 04:40:41 +0100 | [diff] [blame] | 10 | ENCTOOL ?= encrypt_fw${BIN_EXT} |
Manish V Badarkhe | 635482e | 2020-08-13 05:56:33 +0100 | [diff] [blame] | 11 | BINARY := $(notdir ${ENCTOOL}) |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 12 | OPENSSL_DIR := /usr |
| 13 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 14 | |
| 15 | MAKE_HELPERS_DIRECTORY := ../../make_helpers/ |
| 16 | include ${MAKE_HELPERS_DIRECTORY}build_macros.mk |
| 17 | include ${MAKE_HELPERS_DIRECTORY}build_env.mk |
| 18 | include ${MAKE_HELPERS_DIRECTORY}defaults.mk |
| 19 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 20 | OBJECTS := src/encrypt.o \ |
| 21 | src/cmd_opt.o \ |
| 22 | src/main.o |
| 23 | |
| 24 | HOSTCCFLAGS := -Wall -std=c99 |
| 25 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 26 | # 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 Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 29 | |
| 30 | ifeq (${DEBUG},1) |
| 31 | HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40 |
| 32 | else |
| 33 | ifeq (${BUILD_INFO},1) |
| 34 | HOSTCCFLAGS += -O2 -DLOG_LEVEL=20 |
| 35 | else |
| 36 | HOSTCCFLAGS += -O2 -DLOG_LEVEL=10 |
| 37 | endif |
| 38 | endif |
| 39 | ifeq (${V},0) |
| 40 | Q := @ |
| 41 | else |
| 42 | Q := |
| 43 | endif |
| 44 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 45 | HOSTCCFLAGS += ${DEFINES} |
| 46 | # USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper |
| 47 | # computed value. |
| 48 | HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3) |
| 49 | |
| 50 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 51 | # Make soft links and include from local directory otherwise wrong headers |
| 52 | # could get pulled in from firmware tree. |
| 53 | INC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include |
Juan Pablo Conde | 7275a5a | 2022-03-02 18:10:08 -0500 | [diff] [blame] | 54 | |
| 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/). |
| 61 | LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 62 | LIB := -lssl -lcrypto |
| 63 | |
| 64 | HOSTCC ?= gcc |
| 65 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 66 | .PHONY: all clean realclean --openssl |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 67 | |
Ross Burton | 7d7916d | 2021-01-13 12:47:25 +0000 | [diff] [blame] | 68 | all: ${BINARY} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 69 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 70 | ${BINARY}: --openssl ${OBJECTS} Makefile |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 71 | @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 Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 80 | --openssl: |
| 81 | ifeq ($(DEBUG),1) |
| 82 | @echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}" |
| 83 | endif |
| 84 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 85 | clean: |
| 86 | $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS}) |
| 87 | |
| 88 | realclean: clean |
| 89 | $(call SHELL_DELETE,${BINARY}) |