1# Get the dir of the ta-dev-kit, requires make version 3.81 or later 2ta-dev-kit-dir := $(patsubst %/,%,$(abspath $(dir $(lastword $(MAKEFILE_LIST)))..)) 3 4.PHONY: all 5all: 6 7include $(ta-dev-kit-dir)/mk/conf.mk 8ta-dev-kit-dir$(sm) := $(ta-dev-kit-dir) 9 10ifneq (1, $(words $(BINARY) $(LIBNAME) $(SHLIBNAME))) 11$(error You must specify exactly one of BINARY, LIBNAME or SHLIBNAME) 12endif 13 14ifneq ($O,) 15out-dir := $O 16else 17out-dir := . 18endif 19link-out-dir := $(out-dir) # backward compat 20link-out-dir$(sm) := $(out-dir) 21 22user-ta-uuid := $(BINARY) 23user-ta-version := $(if $(CFG_TA_VERSION),$(CFG_TA_VERSION),0) 24user-ta-ldadd := $(LDADD) 25libname := $(LIBNAME) 26shlibname := $(SHLIBNAME) 27shlibuuid := $(SHLIBUUID) 28 29arch-bits-ta_arm32 := 32 30arch-bits-ta_arm64 := 64 31 32# For convenience 33ifdef CFLAGS 34CFLAGS32 ?= $(CFLAGS) 35CFLAGS64 ?= $(CFLAGS) 36endif 37 38ifneq ($V,1) 39q := @ 40cmd-echo := true 41cmd-echo-silent := echo 42else 43q := 44cmd-echo := echo 45cmd-echo-silent := true 46endif 47 48ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 49ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),) 50cmd-echo-silent := true 51endif 52else # make-3.8x 53ifneq ($(findstring s, $(MAKEFLAGS)),) 54cmd-echo-silent := true 55endif 56endif 57 58cppflags$(sm) := $($(sm)-platform-cppflags) $(CPPFLAGS_$(sm)) 59aflags$(sm) := $($(sm)-platform-aflags) 60cflags$(sm) := $($(sm)-platform-cflags) $(CFLAGS_$(sm)) 61cxxflags$(sm) := $($(sm)-platform-cxxflags) $(CXXFLAGS_$(sm)) 62ifneq (,$(shlibname)) 63# Exception handling is not supported in shared libraries (with GCC it would 64# require to use the shared libgcc, which depend on the GNU libc) 65cxxflags$(sm) += -fno-exceptions 66endif 67 68ifeq ($(CFG_TA_OPTEE_CORE_API_COMPAT_1_1),y) 69cppflags$(sm) += -D__OPTEE_CORE_API_COMPAT_1_1=1 70endif 71CFG_TEE_TA_LOG_LEVEL ?= 2 72cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) 73 74cppflags$(sm) += -I. -I$(ta-dev-kit-dir$(sm))/include 75 76ifeq ($(CFG_TA_MCOUNT),y) 77cppflags$(sm) += -pg 78endif 79 80libdirs += $(ta-dev-kit-dir$(sm))/lib 81libnames += utils 82libdeps += $(ta-dev-kit-dir$(sm))/lib/libutils.a 83libnames += utee 84libdeps += $(ta-dev-kit-dir$(sm))/lib/libutee.a 85ifeq ($(CFG_TA_MBEDTLS),y) 86libnames += mbedtls 87libdeps += $(ta-dev-kit-dir$(sm))/lib/libmbedtls.a 88endif 89libnames += dl 90libdeps += $(ta-dev-kit-dir$(sm))/lib/libdl.a 91 92# libutils provides __getauxval symbol which is needed by libgcc 10.x. We can't 93# link libutils after libgcc, because libgcc will replace some symbols provided 94# by libutils, which will cause further linking issues. 95# 96# But if we place libutils before libgcc, linker will not be able to resolve 97# __getauxval. So we need to link with libutils twice: before and after libgcc. 98# Hence it included both in $(libnames) and in $(libnames-after-libgcc) 99libnames-after-libgcc += utils 100libdeps-after-libgcc += $(ta-dev-kit-dir$(sm))/lib/libutils.a 101 102# Pass config variable (CFG_) from conf.mk on the command line 103cppflags$(sm) += $(strip \ 104 $(foreach var, $(filter CFG_%,$(.VARIABLES)), \ 105 $(if $(filter y,$($(var))), \ 106 -D$(var)=1, \ 107 $(if $(filter xn x,x$($(var))),,-D$(var)='$($(var))')))) 108 109include $(ta-dev-kit-dir$(sm))/mk/cleandirs.mk 110 111.PHONY: clean 112clean: 113 @$(cmd-echo-silent) ' CLEAN $(out-dir)' 114 ${q}rm -f $(cleanfiles) 115 ${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi 116 @$(cmd-echo-silent) ' CLEAN $(O)' 117 ${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi 118 119include $(ta-dev-kit-dir$(sm))/mk/$(COMPILER_$(sm)).mk 120include $(ta-dev-kit-dir$(sm))/mk/cc-option.mk 121 122subdirs = . 123include $(ta-dev-kit-dir$(sm))/mk/subdir.mk 124 125ifneq ($(user-ta-uuid),) 126# Build target is TA 127vpath %.c $(ta-dev-kit-dir$(sm))/src 128srcs += user_ta_header.c 129ifeq ($(sm),ta_arm32) 130vpath %.S $(ta-dev-kit-dir$(sm))/src 131srcs += ta_entry_a32.S 132endif 133endif 134 135SCRIPTS_DIR := $(ta-dev-kit-dir)/scripts 136include $(ta-dev-kit-dir$(sm))/mk/compile.mk 137 138ifneq ($(user-ta-uuid),) 139include $(ta-dev-kit-dir$(sm))/mk/link.mk 140endif 141 142ifneq ($(libname),) 143# Build target is static library 144all: $(libname).a 145cleanfiles += $(libname).a 146 147$(libname).a: $(objs) 148 @echo ' AR $@' 149 $(q)rm -f $@ && $(AR$(sm)) rcs $@ $^ 150endif 151 152ifneq (,$(shlibname)) 153include $(ta-dev-kit-dir$(sm))/mk/link_shlib.mk 154endif 155