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 | BUILD_INFO ?= 1 |
| 8 | DEBUG := 0 |
Manish V Badarkhe | b9adb52 | 2020-09-05 04:40:41 +0100 | [diff] [blame] | 9 | ENCTOOL ?= encrypt_fw${BIN_EXT} |
Manish V Badarkhe | 635482e | 2020-08-13 05:56:33 +0100 | [diff] [blame] | 10 | BINARY := $(notdir ${ENCTOOL}) |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 11 | OPENSSL_DIR := /usr |
| 12 | |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 13 | toolchains := host |
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 |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 18 | include ${MAKE_HELPERS_DIRECTORY}common.mk |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 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 |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 41 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 42 | HOSTCCFLAGS += ${DEFINES} |
| 43 | # USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper |
| 44 | # computed value. |
| 45 | HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3) |
| 46 | |
| 47 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 48 | # Make soft links and include from local directory otherwise wrong headers |
| 49 | # could get pulled in from firmware tree. |
| 50 | 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] | 51 | |
| 52 | # Include library directories where OpenSSL library files are located. |
| 53 | # For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or |
| 54 | # /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/ |
| 55 | # directory. However, for a local build of OpenSSL, the built binaries are |
| 56 | # located under the main project directory (i.e.: ${OPENSSL_DIR}, not |
| 57 | # ${OPENSSL_DIR}/lib/). |
| 58 | LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 59 | LIB := -lssl -lcrypto |
| 60 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 61 | .PHONY: all clean realclean --openssl |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 62 | |
Vincent Stehlé | b75a0dd | 2023-07-04 16:14:02 +0200 | [diff] [blame] | 63 | all: --openssl ${BINARY} |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 64 | |
Vincent Stehlé | b75a0dd | 2023-07-04 16:14:02 +0200 | [diff] [blame] | 65 | ${BINARY}: ${OBJECTS} Makefile |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 66 | $(s)echo " HOSTLD $@" |
| 67 | $(q)echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__;' | \ |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 68 | $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 69 | $(q)$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@ |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 70 | |
| 71 | %.o: %.c |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 72 | $(s)echo " HOSTCC $<" |
| 73 | $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@ |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 74 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 75 | --openssl: |
| 76 | ifeq ($(DEBUG),1) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 77 | $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}" |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 78 | endif |
| 79 | |
Sumit Garg | b6c4b3c | 2019-11-11 18:46:36 +0530 | [diff] [blame] | 80 | clean: |
| 81 | $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS}) |
| 82 | |
| 83 | realclean: clean |
| 84 | $(call SHELL_DELETE,${BINARY}) |