xref: /optee_os/ta/ta.mk (revision 095567e5e50cbd8918b4e9b181f70d08be7e8a1b)
1include mk/cleanvars.mk
2
3# Set current submodule (used for module specific flags compile result etc)
4sm := $(ta-target)
5sm-$(sm) := y
6
7# Setup compiler for this sub module
8COMPILER_$(sm)		?= $(COMPILER)
9include mk/$(COMPILER_$(sm)).mk
10
11#
12# Config flags from mk/config.mk
13#
14
15ifeq ($(CFG_TA_MBEDTLS_SELF_TEST),y)
16$(sm)-platform-cppflags += -DMBEDTLS_SELF_TEST
17endif
18
19ifeq ($(CFG_TEE_TA_MALLOC_DEBUG),y)
20# Build malloc debug code into libutils: (mdbg_malloc(), mdbg_free(),
21# mdbg_check(), etc.).
22$(sm)-platform-cppflags += -DENABLE_MDBG=1
23endif
24
25# Config variables to be explicitly exported to the dev kit conf.mk
26ta-mk-file-export-vars-$(sm) += CFG_TA_FLOAT_SUPPORT
27ta-mk-file-export-vars-$(sm) += CFG_CACHE_API
28ta-mk-file-export-vars-$(sm) += CFG_SECURE_DATA_PATH
29ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS_SELF_TEST
30ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
31ta-mk-file-export-vars-$(sm) += CFG_SYSTEM_PTA
32
33# Expand platform flags here as $(sm) will change if we have several TA
34# targets. Platform flags should not change after inclusion of ta/ta.mk.
35cppflags$(sm)	:= $(platform-cppflags) $($(sm)-platform-cppflags)
36cflags$(sm)	:= $(platform-cflags) $($(sm)-platform-cflags)
37aflags$(sm)	:= $(platform-aflags) $($(sm)-platform-aflags)
38
39# Changes to cppflags$(sm) will only affect how TA dev kit libraries are
40# compiled, these flags are not propagated to the TA
41cppflags$(sm)	+= -include $(conf-file)
42cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
43
44base-prefix := $(sm)-
45
46libname = utils
47libdir = lib/libutils
48include mk/lib.mk
49
50libname = mpa
51libdir = lib/libmpa
52include mk/lib.mk
53
54libname = utee
55libdir = lib/libutee
56include mk/lib.mk
57
58ifeq ($(CFG_TA_MBEDTLS),y)
59libname = mbedtls
60libdir = lib/libmbedtls
61include mk/lib.mk
62ta-mk-file-export-vars-$(sm) += CFG_TA_MBEDTLS
63endif
64
65base-prefix :=
66
67incdirs-host := $(filter-out lib/libutils%, $(incdirs$(sm)))
68incfiles-extra-host := lib/libutils/ext/include/compiler.h
69incfiles-extra-host += lib/libutils/ext/include/util.h
70incfiles-extra-host += lib/libutils/ext/include/types_ext.h
71incfiles-extra-host += $(conf-file)
72incfiles-extra-host += $(conf-mk-file)
73incfiles-extra-host += $(conf-cmake-file)
74incfiles-extra-host += core/include/tee/tee_fs_key_manager.h
75incfiles-extra-host += core/include/tee/fs_htree.h
76incfiles-extra-host += core/include/signed_hdr.h
77
78#
79# Copy lib files and exported headers from each lib
80#
81
82define copy-file
83$2/$$(notdir $1): $1
84	@set -e; \
85	mkdir -p $$(dir $$@) ; \
86	$(cmd-echo-silent) '  INSTALL $$@' ; \
87	cp $$< $$@
88
89cleanfiles += $2/$$(notdir $1)
90ta_dev_kit: $2/$$(notdir $1)
91endef
92
93# Copy the .a files
94$(foreach f, $(libfiles), \
95	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib)))
96
97# Copy .mk files
98ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk mk/cleandirs.mk \
99	ta/arch/$(ARCH)/link.mk ta/arch/$(ARCH)/link_shlib.mk \
100	ta/mk/ta_dev_kit.mk
101
102$(foreach f, $(ta-mkfiles), \
103	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))
104
105# Copy the .h files for TAs
106define copy-incdir
107sf := $(subst $1/, , $(shell find $1 -name "*.h"))
108$$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
109	$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))))))
110endef
111$(foreach d, $(incdirs$(sm)), \
112	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/include)))
113
114# Copy the .h files needed by host
115$(foreach d, $(incdirs-host), \
116	$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
117$(foreach f, $(incfiles-extra-host), \
118	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))
119
120# Copy the src files
121ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c ta/arch/$(ARCH)/ta.ld.S
122$(foreach f, $(ta-srcfiles), \
123	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))
124
125# Copy keys
126ta-keys = keys/default_ta.pem
127$(foreach f, $(ta-keys), \
128	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))
129
130# Copy the scripts
131ta-scripts = scripts/sign.py scripts/symbolize.py
132$(foreach f, $(ta-scripts), \
133	$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))
134
135# Create config file
136conf-mk-file-export := $(out-dir)/export-$(sm)/mk/conf.mk
137sm-$(conf-mk-file-export) := $(sm)
138define mk-file-export
139.PHONY: $(conf-mk-file-export)
140$(conf-mk-file-export):
141	@$$(cmd-echo-silent) '  CHK    ' $$@
142	$(q)echo sm := $$(sm-$(conf-mk-file-export)) > $$@.tmp
143	$(q)echo sm-$$(sm-$(conf-mk-file-export)) := y >> $$@.tmp
144	$(q)($$(foreach v, $$(ta-mk-file-export-vars-$$(sm-$(conf-mk-file-export))), \
145		$$(if $$($$(v)),echo $$(v) := $$($$(v));,))) >> $$@.tmp
146	$(q)echo '$$(ta-mk-file-export-add-$$(sm-$(conf-mk-file-export)))' | sed 's/_nl_ */\n/g' >> $$@.tmp
147	$(q)$(call mv-if-changed,$$@.tmp,$$@)
148endef
149$(eval $(mk-file-export))
150
151cleanfiles := $(cleanfiles) $(conf-mk-file-export)
152ta_dev_kit: $(conf-mk-file-export)
153
154all: ta_dev_kit
155