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