190aa901fSSumit Garg# 29bc52d33SJuan Pablo Conde# Copyright (c) 2019-2022, Linaro Limited. All rights reserved. 390aa901fSSumit Garg# 490aa901fSSumit Garg# SPDX-License-Identifier: BSD-3-Clause 590aa901fSSumit Garg# 690aa901fSSumit Garg 790aa901fSSumit GargBUILD_INFO ?= 1 890aa901fSSumit GargDEBUG := 0 9b13e3f9fSManish V BadarkheENCTOOL ?= encrypt_fw${BIN_EXT} 10fafd3ec9SManish V BadarkheBINARY := $(notdir ${ENCTOOL}) 1190aa901fSSumit GargOPENSSL_DIR := /usr 1290aa901fSSumit Garg 13cc277de8SChris Kaytoolchains := host 14cf2dd17dSJuan Pablo Conde 15cf2dd17dSJuan Pablo CondeMAKE_HELPERS_DIRECTORY := ../../make_helpers/ 16cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk 17cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk 18*7c4e1eeaSChris Kayinclude ${MAKE_HELPERS_DIRECTORY}common.mk 19cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}defaults.mk 20cc277de8SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}toolchain.mk 21cf2dd17dSJuan Pablo Conde 2290aa901fSSumit GargOBJECTS := src/encrypt.o \ 2390aa901fSSumit Garg src/cmd_opt.o \ 2490aa901fSSumit Garg src/main.o 2590aa901fSSumit Garg 2690aa901fSSumit GargHOSTCCFLAGS := -Wall -std=c99 2790aa901fSSumit Garg 28cf2dd17dSJuan Pablo Conde# Select OpenSSL version flag according to the OpenSSL build selected 29cf2dd17dSJuan Pablo Conde# from setting the OPENSSL_DIR path. 30cf2dd17dSJuan Pablo Conde$(eval $(call SELECT_OPENSSL_API_VERSION)) 3190aa901fSSumit Garg 3290aa901fSSumit Gargifeq (${DEBUG},1) 3390aa901fSSumit Garg HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40 3490aa901fSSumit Gargelse 3590aa901fSSumit Gargifeq (${BUILD_INFO},1) 3690aa901fSSumit Garg HOSTCCFLAGS += -O2 -DLOG_LEVEL=20 3790aa901fSSumit Gargelse 3890aa901fSSumit Garg HOSTCCFLAGS += -O2 -DLOG_LEVEL=10 3990aa901fSSumit Gargendif 4090aa901fSSumit Gargendif 4190aa901fSSumit Garg 42cf2dd17dSJuan Pablo CondeHOSTCCFLAGS += ${DEFINES} 43cf2dd17dSJuan Pablo Conde# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper 44cf2dd17dSJuan Pablo Conde# computed value. 45cf2dd17dSJuan Pablo CondeHOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3) 46cf2dd17dSJuan Pablo Conde 47cf2dd17dSJuan Pablo Conde 4890aa901fSSumit Garg# Make soft links and include from local directory otherwise wrong headers 4990aa901fSSumit Garg# could get pulled in from firmware tree. 5090aa901fSSumit GargINC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include 519bc52d33SJuan Pablo Conde 529bc52d33SJuan Pablo Conde# Include library directories where OpenSSL library files are located. 539bc52d33SJuan Pablo Conde# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or 549bc52d33SJuan Pablo Conde# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/ 559bc52d33SJuan Pablo Conde# directory. However, for a local build of OpenSSL, the built binaries are 569bc52d33SJuan Pablo Conde# located under the main project directory (i.e.: ${OPENSSL_DIR}, not 579bc52d33SJuan Pablo Conde# ${OPENSSL_DIR}/lib/). 589bc52d33SJuan Pablo CondeLIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR} 5990aa901fSSumit GargLIB := -lssl -lcrypto 6090aa901fSSumit Garg 61cf2dd17dSJuan Pablo Conde.PHONY: all clean realclean --openssl 6290aa901fSSumit Garg 63aa57ce63SVincent Stehléall: --openssl ${BINARY} 6490aa901fSSumit Garg 65aa57ce63SVincent Stehlé${BINARY}: ${OBJECTS} Makefile 66*7c4e1eeaSChris Kay $(s)echo " HOSTLD $@" 67*7c4e1eeaSChris Kay $(q)echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__;' | \ 68ffb77421SChris Kay $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o 69*7c4e1eeaSChris Kay $(q)$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@ 7090aa901fSSumit Garg 7190aa901fSSumit Garg%.o: %.c 72*7c4e1eeaSChris Kay $(s)echo " HOSTCC $<" 73*7c4e1eeaSChris Kay $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@ 7490aa901fSSumit Garg 75cf2dd17dSJuan Pablo Conde--openssl: 76cf2dd17dSJuan Pablo Condeifeq ($(DEBUG),1) 77*7c4e1eeaSChris Kay $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}" 78cf2dd17dSJuan Pablo Condeendif 79cf2dd17dSJuan Pablo Conde 8090aa901fSSumit Gargclean: 8190aa901fSSumit Garg $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS}) 8290aa901fSSumit Garg 8390aa901fSSumit Gargrealclean: clean 8490aa901fSSumit Garg $(call SHELL_DELETE,${BINARY}) 85