xref: /optee_os/core/core.mk (revision df24e6517b6454cf906c16979ea0e7546c5c99d5)
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
46ifeq ($(CFG_SYSCALL_FTRACE),y)
47cflags$(sm)	+= -pg
48endif
49aflags$(sm)	+= $(core-platform-aflags)
50
51cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL)
52ifeq ($(CFG_TEE_CORE_MALLOC_DEBUG),y)
53cppflags$(sm) += -DENABLE_MDBG=1
54endif
55ifneq ($(CFG_TEE_CORE_DEBUG),y)
56cppflags$(sm)  += -DNDEBUG
57endif
58
59cppflags$(sm)	+= -Ildelf/include
60cppflags$(sm)	+= -Ilib/libutee/include
61
62ifeq ($(filter y, $(CFG_CORE_DYN_SHM) $(CFG_CORE_RESERVED_SHM)),)
63$(error error: No shared memory configured)
64endif
65
66# Tell all libraries and sub-directories (included below) that we have a
67# configuration file
68
69conf-file := $(out-dir)/include/generated/conf.h
70conf-mk-file := $(out-dir)/conf.mk
71conf-cmake-file := $(out-dir)/conf.cmake
72$(conf-file): $(conf-mk-file)
73
74cleanfiles += $(conf-file)
75cleanfiles += $(conf-mk-file)
76cleanfiles += $(conf-cmake-file)
77
78$(conf-file): FORCE
79	$(call check-conf-h)
80
81$(conf-mk-file):  FORCE
82	$(call check-conf-mk)
83
84$(conf-cmake-file):  FORCE
85	$(call check-conf-cmake)
86
87#
88# Do libraries
89#
90
91# Set a prefix to avoid conflicts with user TAs that will use the same
92# source but with different flags below
93base-prefix := $(sm)-
94libname = utils
95libdir = lib/libutils
96include mk/lib.mk
97
98# CFG_CRYPTOLIB_NAME must not be changed beyond this line
99CFG_CRYPTOLIB_NAME_$(CFG_CRYPTOLIB_NAME) := y
100
101ifeq ($(CFG_CRYPTOLIB_NAME),tomcrypt)
102ifeq ($(CFG_CORE_MBEDTLS_MPI),y)
103# We're compiling mbedtls too, but with a limited configuration which only
104# provides the MPI routines
105libname = mbedtls
106libdir = lib/libmbedtls
107include mk/lib.mk
108else
109libname = mpa
110libdir = lib/libmpa
111include mk/lib.mk
112endif
113endif #tomcrypt
114
115ifeq ($(CFG_CRYPTOLIB_NAME),mbedtls)
116$(call force,CFG_CRYPTO_RSASSA_NA1,n,not supported by mbedtls)
117libname = tomcrypt
118libdir = core/lib/libtomcrypt
119base-prefix :=
120include mk/lib.mk
121base-prefix := $(sm)-
122endif
123
124ifeq ($(firstword $(subst /, ,$(CFG_CRYPTOLIB_DIR))),core)
125# If a library can be compiled for both core and user space a base-prefix
126# is needed in order to avoid conflicts in the output. However, if the
127# library resides under core then it can't be compiled to user space.
128base-prefix :=
129endif
130
131libname = $(CFG_CRYPTOLIB_NAME)
132libdir = $(CFG_CRYPTOLIB_DIR)
133include mk/lib.mk
134
135base-prefix :=
136
137ifeq ($(CFG_DT),y)
138libname = fdt
139libdir = core/lib/libfdt
140include mk/lib.mk
141endif
142
143ifeq ($(CFG_ZLIB),y)
144libname = zlib
145libdir = core/lib/zlib
146include mk/lib.mk
147endif
148
149#
150# Do main source
151#
152
153subdirs = $(core-platform-subdirs) core
154include mk/subdir.mk
155
156include mk/compile.mk
157
158include $(if $(wildcard $(platform-dir)/link.mk), \
159		$(platform-dir)/link.mk, \
160		core/arch/$(ARCH)/kernel/link.mk)
161