xref: /optee_os/core/core.mk (revision 2c028fdebbedee91f88f6c5325b5064a124dfe46)
1include mk/cleanvars.mk
2
3# Set current submodule (used for module specific flags compile result etc)
4sm := core
5sm-$(sm) := y
6
7arch-dir	:= core/arch/$(ARCH)
8platform-dir	:= $(arch-dir)/plat-$(PLATFORM)
9include $(platform-dir)/conf.mk
10include mk/config.mk
11# $(ARCH).mk also sets the compiler for the core module
12include core/arch/$(ARCH)/$(ARCH).mk
13
14PLATFORM_$(PLATFORM) := y
15PLATFORM_FLAVOR_$(PLATFORM_FLAVOR) := y
16
17$(eval $(call cfg-depends-all,CFG_PAGED_USER_TA,CFG_WITH_PAGER CFG_WITH_USER_TA))
18include core/crypto.mk
19
20cppflags$(sm)	+= -D__KERNEL__
21
22cppflags$(sm)	+= -Icore/include
23cppflags$(sm)	+= -include $(conf-file)
24cppflags$(sm)	+= -I$(out-dir)/core/include
25cppflags$(sm)	+= $(core-platform-cppflags)
26cflags$(sm)	+= $(core-platform-cflags)
27ifeq ($(CFG_CORE_SANITIZE_UNDEFINED),y)
28cflags$(sm)	+= -fsanitize=undefined
29endif
30ifeq ($(CFG_CORE_SANITIZE_KADDRESS),y)
31ifeq ($(CFG_ASAN_SHADOW_OFFSET),)
32$(error error: CFG_CORE_SANITIZE_KADDRESS not supported by platform (flavor))
33endif
34ifeq ($(COMPILER),clang)
35$(error error: CFG_CORE_SANITIZE_KADDRESS not supported with Clang)
36endif
37cflags_kasan	+= -fsanitize=kernel-address \
38		   -fasan-shadow-offset=$(CFG_ASAN_SHADOW_OFFSET)\
39		   --param asan-stack=1 --param asan-globals=1 \
40		   --param asan-instrumentation-with-call-threshold=0
41cflags$(sm)	+= $(cflags_kasan)
42endif
43ifeq ($(CFG_SYSCALL_FTRACE),y)
44cflags$(sm)	+= -pg
45endif
46aflags$(sm)	+= $(core-platform-aflags)
47
48cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL)
49ifeq ($(CFG_TEE_CORE_MALLOC_DEBUG),y)
50cppflags$(sm) += -DENABLE_MDBG=1
51endif
52ifneq ($(CFG_TEE_CORE_DEBUG),y)
53cppflags$(sm)  += -DNDEBUG
54endif
55
56cppflags$(sm)	+= -Ildelf/include
57cppflags$(sm)	+= -Ilib/libutee/include
58
59ifeq ($(filter y, $(CFG_CORE_DYN_SHM) $(CFG_CORE_RESERVED_SHM)),)
60$(error error: No shared memory configured)
61endif
62
63# Tell all libraries and sub-directories (included below) that we have a
64# configuration file
65
66conf-file := $(out-dir)/include/generated/conf.h
67conf-mk-file := $(out-dir)/conf.mk
68conf-cmake-file := $(out-dir)/conf.cmake
69$(conf-file): $(conf-mk-file)
70
71cleanfiles += $(conf-file)
72cleanfiles += $(conf-mk-file)
73cleanfiles += $(conf-cmake-file)
74
75$(conf-file): FORCE
76	$(call check-conf-h)
77
78$(conf-mk-file):  FORCE
79	$(call check-conf-mk)
80
81$(conf-cmake-file):  FORCE
82	$(call check-conf-cmake)
83
84#
85# Do libraries
86#
87
88# Set a prefix to avoid conflicts with user TAs that will use the same
89# source but with different flags below
90base-prefix := $(sm)-
91libname = utils
92libdir = lib/libutils
93include mk/lib.mk
94
95# CFG_CRYPTOLIB_NAME must not be changed beyond this line
96CFG_CRYPTOLIB_NAME_$(CFG_CRYPTOLIB_NAME) := y
97
98ifeq ($(CFG_CRYPTOLIB_NAME),tomcrypt)
99# We're compiling mbedtls too, but with a limited configuration which only
100# provides the MPI routines
101libname = mbedtls
102libdir = lib/libmbedtls
103include mk/lib.mk
104endif #tomcrypt
105
106ifeq ($(CFG_CRYPTOLIB_NAME),mbedtls)
107$(call force,CFG_CRYPTO_RSASSA_NA1,n,not supported by mbedtls)
108libname = tomcrypt
109libdir = core/lib/libtomcrypt
110base-prefix :=
111include mk/lib.mk
112base-prefix := $(sm)-
113endif
114
115ifeq ($(firstword $(subst /, ,$(CFG_CRYPTOLIB_DIR))),core)
116# If a library can be compiled for both core and user space a base-prefix
117# is needed in order to avoid conflicts in the output. However, if the
118# library resides under core then it can't be compiled to user space.
119base-prefix :=
120endif
121
122libname = $(CFG_CRYPTOLIB_NAME)
123libdir = $(CFG_CRYPTOLIB_DIR)
124include mk/lib.mk
125
126base-prefix :=
127
128libname = fdt
129libdir = core/lib/libfdt
130include mk/lib.mk
131
132ifeq ($(CFG_ZLIB),y)
133libname = zlib
134libdir = core/lib/zlib
135include mk/lib.mk
136endif
137
138#
139# Do main source
140#
141
142subdirs = $(core-platform-subdirs) core
143include mk/subdir.mk
144
145include mk/compile.mk
146
147include $(if $(wildcard $(platform-dir)/link.mk), \
148		$(platform-dir)/link.mk, \
149		core/arch/$(ARCH)/kernel/link.mk)
150