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