Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #
  2. # Copyright (c) 2019-2022, Linaro Limited. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. V ?= 0
  7. BUILD_INFO ?= 1
  8. DEBUG := 0
  9. ENCTOOL ?= encrypt_fw${BIN_EXT}
  10. BINARY := $(notdir ${ENCTOOL})
  11. OPENSSL_DIR := /usr
  12. toolchains := host
  13. MAKE_HELPERS_DIRECTORY := ../../make_helpers/
  14. include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
  15. include ${MAKE_HELPERS_DIRECTORY}build_env.mk
  16. include ${MAKE_HELPERS_DIRECTORY}defaults.mk
  17. include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
  18. OBJECTS := src/encrypt.o \
  19. src/cmd_opt.o \
  20. src/main.o
  21. HOSTCCFLAGS := -Wall -std=c99
  22. # Select OpenSSL version flag according to the OpenSSL build selected
  23. # from setting the OPENSSL_DIR path.
  24. $(eval $(call SELECT_OPENSSL_API_VERSION))
  25. ifeq (${DEBUG},1)
  26. HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
  27. else
  28. ifeq (${BUILD_INFO},1)
  29. HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
  30. else
  31. HOSTCCFLAGS += -O2 -DLOG_LEVEL=10
  32. endif
  33. endif
  34. ifeq (${V},0)
  35. Q := @
  36. else
  37. Q :=
  38. endif
  39. HOSTCCFLAGS += ${DEFINES}
  40. # USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
  41. # computed value.
  42. HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
  43. # Make soft links and include from local directory otherwise wrong headers
  44. # could get pulled in from firmware tree.
  45. INC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include
  46. # Include library directories where OpenSSL library files are located.
  47. # For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
  48. # /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
  49. # directory. However, for a local build of OpenSSL, the built binaries are
  50. # located under the main project directory (i.e.: ${OPENSSL_DIR}, not
  51. # ${OPENSSL_DIR}/lib/).
  52. LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
  53. LIB := -lssl -lcrypto
  54. .PHONY: all clean realclean --openssl
  55. all: --openssl ${BINARY}
  56. ${BINARY}: ${OBJECTS} Makefile
  57. @echo " HOSTLD $@"
  58. @echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__;' | \
  59. $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
  60. ${Q}$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
  61. %.o: %.c
  62. @echo " HOSTCC $<"
  63. ${Q}$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
  64. --openssl:
  65. ifeq ($(DEBUG),1)
  66. @echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
  67. endif
  68. clean:
  69. $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
  70. realclean: clean
  71. $(call SHELL_DELETE,${BINARY})