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