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 32ifneq ($V,1) 33q := @ 34cmd-echo := true 35cmd-echo-silent := echo 36else 37q := 38cmd-echo := echo 39cmd-echo-silent := true 40endif 41 42ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4 43ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),) 44cmd-echo-silent := true 45endif 46else # make-3.8x 47ifneq ($(findstring s, $(MAKEFLAGS)),) 48cmd-echo-silent := true 49endif 50endif 51 52cppflags$(sm) := $($(sm)-platform-cppflags) $(CPPFLAGS_$(sm)) 53aflags$(sm) := $($(sm)-platform-aflags) 54cflags$(sm) := $($(sm)-platform-cflags) $(CFLAGS_$(sm)) 55cxxflags$(sm) := $($(sm)-platform-cxxflags) $(CXXFLAGS_$(sm)) 56ifneq (,$(shlibname)) 57# Exception handling is not supported in shared libraries (with GCC it would 58# require to use the shared libgcc, which depend on the GNU libc) 59cxxflags$(sm) += -fno-exceptions 60endif 61 62CFG_TEE_TA_LOG_LEVEL ?= 2 63cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) 64 65cppflags$(sm) += -I. -I$(ta-dev-kit-dir$(sm))/include 66 67ifeq ($(CFG_TA_MCOUNT),y) 68cppflags$(sm) += -pg 69endif 70 71libdirs += $(ta-dev-kit-dir$(sm))/lib 72libnames += utils 73libdeps += $(ta-dev-kit-dir$(sm))/lib/libutils.a 74libnames += utee 75libdeps += $(ta-dev-kit-dir$(sm))/lib/libutee.a 76ifeq ($(CFG_TA_MBEDTLS),y) 77libnames += mbedtls 78libdeps += $(ta-dev-kit-dir$(sm))/lib/libmbedtls.a 79endif 80libnames += dl 81libdeps += $(ta-dev-kit-dir$(sm))/lib/libdl.a 82 83# libutils provides __getauxval symbol which is needed by libgcc 10.x. We can't 84# link libutils after libgcc, because libgcc will replace some symbols provided 85# by libutils, which will cause further linking issues. 86# 87# But if we place libutils before libgcc, linker will not be able to resolve 88# __getauxval. So we need to link with libutils twice: before and after libgcc. 89# Hence it included both in $(libnames) and in $(libnames-after-libgcc) 90libnames-after-libgcc += utils 91libdeps-after-libgcc += $(ta-dev-kit-dir$(sm))/lib/libutils.a 92 93# Pass config variable (CFG_) from conf.mk on the command line 94cppflags$(sm) += $(strip \ 95 $(foreach var, $(filter CFG_%,$(.VARIABLES)), \ 96 $(if $(filter y,$($(var))), \ 97 -D$(var)=1, \ 98 $(if $(filter xn x,x$($(var))),,-D$(var)='$($(var))')))) 99 100include $(ta-dev-kit-dir$(sm))/mk/cleandirs.mk 101 102.PHONY: clean 103clean: 104 @$(cmd-echo-silent) ' CLEAN $(out-dir)' 105 ${q}rm -f $(cleanfiles) 106 ${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi 107 @$(cmd-echo-silent) ' CLEAN $(O)' 108 ${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi 109 110include $(ta-dev-kit-dir$(sm))/mk/$(COMPILER_$(sm)).mk 111include $(ta-dev-kit-dir$(sm))/mk/cc-option.mk 112 113subdirs = . 114include $(ta-dev-kit-dir$(sm))/mk/subdir.mk 115 116ifneq ($(user-ta-uuid),) 117# Build target is TA 118vpath %.c $(ta-dev-kit-dir$(sm))/src 119srcs += user_ta_header.c 120ifeq ($(sm),ta_arm32) 121vpath %.S $(ta-dev-kit-dir$(sm))/src 122srcs += ta_entry_a32.S 123endif 124endif 125 126SCRIPTS_DIR := $(ta-dev-kit-dir)/scripts 127include $(ta-dev-kit-dir$(sm))/mk/compile.mk 128 129ifneq ($(user-ta-uuid),) 130include $(ta-dev-kit-dir$(sm))/mk/link.mk 131endif 132 133ifneq ($(libname),) 134# Build target is static library 135all: $(libname).a 136cleanfiles += $(libname).a 137 138$(libname).a: $(objs) 139 @echo ' AR $@' 140 $(q)rm -f $@ && $(AR$(sm)) rcs -o $@ $^ 141endif 142 143ifneq (,$(shlibname)) 144include $(ta-dev-kit-dir$(sm))/mk/link_shlib.mk 145endif 146