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 | |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 14 | toolchains := host |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 15 | |
| 16 | MAKE_HELPERS_DIRECTORY := ../../make_helpers/ |
| 17 | include ${MAKE_HELPERS_DIRECTORY}build_macros.mk |
| 18 | include ${MAKE_HELPERS_DIRECTORY}build_env.mk |
| 19 | include ${MAKE_HELPERS_DIRECTORY}defaults.mk |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 20 | include ${MAKE_HELPERS_DIRECTORY}toolchain.mk |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 21 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 22 | OBJECTS := src/encrypt.o \ |
| 23 | src/cmd_opt.o \ |
| 24 | src/main.o |
| 25 | |
| 26 | HOSTCCFLAGS := -Wall -std=c99 |
| 27 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 28 | # 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 Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 31 | |
| 32 | ifeq (${DEBUG},1) |
| 33 | HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40 |
| 34 | else |
| 35 | ifeq (${BUILD_INFO},1) |
| 36 | HOSTCCFLAGS += -O2 -DLOG_LEVEL=20 |
| 37 | else |
| 38 | HOSTCCFLAGS += -O2 -DLOG_LEVEL=10 |
| 39 | endif |
| 40 | endif |
| 41 | ifeq (${V},0) |
| 42 | Q := @ |
| 43 | else |
| 44 | Q := |
| 45 | endif |
| 46 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 47 | HOSTCCFLAGS += ${DEFINES} |
| 48 | # USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper |
| 49 | # computed value. |
| 50 | HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3) |
| 51 | |
| 52 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 53 | # Make soft links and include from local directory otherwise wrong headers |
| 54 | # could get pulled in from firmware tree. |
| 55 | 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] | 56 | |
| 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/). |
| 63 | LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 64 | LIB := -lssl -lcrypto |
| 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 | |
Vincent Stehlé | b75a0dd | 2023-07-04 16:14:02 +0200 | [diff] [blame] | 68 | all: --openssl ${BINARY} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 69 | |
Vincent Stehlé | b75a0dd | 2023-07-04 16:14:02 +0200 | [diff] [blame] | 70 | ${BINARY}: ${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__;' | \ |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 73 | $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o |
| 74 | ${Q}$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@ |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 75 | |
| 76 | %.o: %.c |
| 77 | @echo " HOSTCC $<" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 78 | ${Q}$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@ |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 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}) |