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