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