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