xref: /optee_os/core/core.mk (revision a253662b1063c7bb866fd21afca550eb6d70b8f4)
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
11include core/arch/$(ARCH)/$(ARCH).mk
12
13PLATFORM_$(PLATFORM) := y
14PLATFORM_FLAVOR_$(PLATFORM_FLAVOR) := y
15
16$(eval $(call cfg-depends-all,CFG_PAGED_USER_TA,CFG_WITH_PAGER CFG_WITH_USER_TA))
17include core/crypto.mk
18
19# Setup compiler for this sub module
20COMPILER_$(sm)		?= $(COMPILER)
21include mk/$(COMPILER_$(sm)).mk
22
23cppflags$(sm)	+= -D__KERNEL__
24
25cppflags$(sm)	+= -Icore/include
26cppflags$(sm)	+= -include $(conf-file)
27cppflags$(sm)	+= -I$(out-dir)/core/include
28cppflags$(sm)	+= $(core-platform-cppflags)
29cflags$(sm)	+= $(core-platform-cflags)
30ifeq ($(CFG_CORE_SANITIZE_UNDEFINED),y)
31cflags$(sm)	+= -fsanitize=undefined
32endif
33ifeq ($(CFG_CORE_SANITIZE_KADDRESS),y)
34ifeq ($(CFG_ASAN_SHADOW_OFFSET),)
35$(error error: CFG_CORE_SANITIZE_KADDRESS not supported by platform (flavor))
36endif
37ifeq ($(COMPILER),clang)
38$(error error: CFG_CORE_SANITIZE_KADDRESS not supported with Clang)
39endif
40cflags_kasan	+= -fsanitize=kernel-address \
41		   -fasan-shadow-offset=$(CFG_ASAN_SHADOW_OFFSET)\
42		   --param asan-stack=1 --param asan-globals=1 \
43		   --param asan-instrumentation-with-call-threshold=0
44cflags$(sm)	+= $(cflags_kasan)
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)
73
74$(conf-file): FORCE
75	$(call check-conf-h)
76
77$(conf-mk-file):  FORCE
78	$(call check-conf-mk)
79
80$(conf-cmake-file):  FORCE
81	$(call check-conf-cmake)
82
83#
84# Do libraries
85#
86
87# Set a prefix to avoid conflicts with user TAs that will use the same
88# source but with different flags below
89base-prefix := $(sm)-
90libname = utils
91libdir = lib/libutils
92include mk/lib.mk
93
94# CFG_CRYPTOLIB_NAME must not be changed beyond this line
95CFG_CRYPTOLIB_NAME_$(CFG_CRYPTOLIB_NAME) := y
96
97ifeq ($(CFG_CRYPTOLIB_NAME),tomcrypt)
98ifeq ($(CFG_CORE_MBEDTLS_MPI),y)
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
104else
105libname = mpa
106libdir = lib/libmpa
107include mk/lib.mk
108endif
109endif #tomcrypt
110
111ifeq ($(CFG_CRYPTOLIB_NAME),mbedtls)
112$(call force,CFG_CRYPTO_RSASSA_NA1,n,not supported by mbedtls)
113libname = tomcrypt
114libdir = core/lib/libtomcrypt
115base-prefix :=
116include mk/lib.mk
117base-prefix := $(sm)-
118endif
119
120ifeq ($(firstword $(subst /, ,$(CFG_CRYPTOLIB_DIR))),core)
121# If a library can be compiled for both core and user space a base-prefix
122# is needed in order to avoid conflicts in the output. However, if the
123# library resides under core then it can't be compiled to user space.
124base-prefix :=
125endif
126
127libname = $(CFG_CRYPTOLIB_NAME)
128libdir = $(CFG_CRYPTOLIB_DIR)
129include mk/lib.mk
130
131base-prefix :=
132
133ifeq ($(CFG_DT),y)
134libname = fdt
135libdir = core/lib/libfdt
136include mk/lib.mk
137endif
138
139ifeq ($(CFG_ZLIB),y)
140libname = zlib
141libdir = core/lib/zlib
142include mk/lib.mk
143endif
144
145#
146# Do main source
147#
148
149subdirs = $(core-platform-subdirs) core
150include mk/subdir.mk
151
152include mk/compile.mk
153
154include $(if $(wildcard $(platform-dir)/link.mk), \
155		$(platform-dir)/link.mk, \
156		core/arch/$(ARCH)/kernel/link.mk)
157