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 68CFG_TEE_TA_LOG_LEVEL ?= 2 69cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) 70 71cppflags$(sm) += -I. -I$(ta-dev-kit-dir$(sm))/include 72 73ifeq ($(CFG_TA_MCOUNT),y) 74cppflags$(sm) += -pg 75endif 76 77libdirs += $(ta-dev-kit-dir$(sm))/lib 78libnames += utils 79libdeps += $(ta-dev-kit-dir$(sm))/lib/libutils.a 80libnames += utee 81libdeps += $(ta-dev-kit-dir$(sm))/lib/libutee.a 82ifeq ($(CFG_TA_MBEDTLS),y) 83libnames += mbedtls 84libdeps += $(ta-dev-kit-dir$(sm))/lib/libmbedtls.a 85endif 86libnames += dl 87libdeps += $(ta-dev-kit-dir$(sm))/lib/libdl.a 88 89# libutils provides __getauxval symbol which is needed by libgcc 10.x. We can't 90# link libutils after libgcc, because libgcc will replace some symbols provided 91# by libutils, which will cause further linking issues. 92# 93# But if we place libutils before libgcc, linker will not be able to resolve 94# __getauxval. So we need to link with libutils twice: before and after libgcc. 95# Hence it included both in $(libnames) and in $(libnames-after-libgcc) 96libnames-after-libgcc += utils 97libdeps-after-libgcc += $(ta-dev-kit-dir$(sm))/lib/libutils.a 98 99# Pass config variable (CFG_) from conf.mk on the command line 100cppflags$(sm) += $(strip \ 101 $(foreach var, $(filter CFG_%,$(.VARIABLES)), \ 102 $(if $(filter y,$($(var))), \ 103 -D$(var)=1, \ 104 $(if $(filter xn x,x$($(var))),,-D$(var)='$($(var))')))) 105 106include $(ta-dev-kit-dir$(sm))/mk/cleandirs.mk 107 108.PHONY: clean 109clean: 110 @$(cmd-echo-silent) ' CLEAN $(out-dir)' 111 ${q}rm -f $(cleanfiles) 112 ${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi 113 @$(cmd-echo-silent) ' CLEAN $(O)' 114 ${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi 115 116include $(ta-dev-kit-dir$(sm))/mk/$(COMPILER_$(sm)).mk 117include $(ta-dev-kit-dir$(sm))/mk/cc-option.mk 118 119subdirs = . 120include $(ta-dev-kit-dir$(sm))/mk/subdir.mk 121 122ifneq ($(user-ta-uuid),) 123# Build target is TA 124vpath %.c $(ta-dev-kit-dir$(sm))/src 125srcs += user_ta_header.c 126ifeq ($(sm),ta_arm32) 127vpath %.S $(ta-dev-kit-dir$(sm))/src 128srcs += ta_entry_a32.S 129endif 130endif 131 132SCRIPTS_DIR := $(ta-dev-kit-dir)/scripts 133include $(ta-dev-kit-dir$(sm))/mk/compile.mk 134 135ifneq ($(user-ta-uuid),) 136include $(ta-dev-kit-dir$(sm))/mk/link.mk 137endif 138 139ifneq ($(libname),) 140# Build target is static library 141all: $(libname).a 142cleanfiles += $(libname).a 143 144$(libname).a: $(objs) 145 @echo ' AR $@' 146 $(q)rm -f $@ && $(AR$(sm)) rcs $@ $^ 147endif 148 149ifneq (,$(shlibname)) 150include $(ta-dev-kit-dir$(sm))/mk/link_shlib.mk 151endif 152