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