]> git.saurik.com Git - apple/xnu.git/blob - makedefs/MakeInc.def
xnu-4570.41.2.tar.gz
[apple/xnu.git] / makedefs / MakeInc.def
1 # -*- mode: makefile;-*-
2 #
3 # Copyright (C) 1999-2017 Apple Inc. All rights reserved.
4 #
5 # MakeInc.def contains global definitions for building,
6 # linking, and installing files.
7 #
8
9 #
10 # Architecture Configuration options
11 #
12 SUPPORTED_ARCH_CONFIGS := X86_64 X86_64H
13
14 #
15 # Kernel Configuration options
16 #
17 SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE KASAN
18
19 #
20 # Machine Configuration options
21 #
22
23 SUPPORTED_X86_64_MACHINE_CONFIGS = NONE
24 SUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
25
26
27 #
28 # Setup up *_LC variables during recursive invocations
29 #
30
31 ifndef CURRENT_ARCH_CONFIG_LC
32 export CURRENT_ARCH_CONFIG_LC := $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
33 endif
34
35 ifndef CURRENT_KERNEL_CONFIG_LC
36 export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
37 endif
38
39 ifndef CURRENT_MACHINE_CONFIG_LC
40 export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
41 endif
42
43 #
44 # Component List
45 #
46 COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security san
47 COMPONENT = $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
48 COMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
49
50
51 #
52 # Deployment target flag
53 #
54 ifeq ($(PLATFORM),MacOSX)
55 DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION)
56 else ifeq ($(PLATFORM),WatchOS)
57 DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION)
58 else ifeq ($(PLATFORM),tvOS)
59 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
60 else ifeq ($(PLATFORM),AppleTVOS)
61 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
62 else ifeq ($(PLATFORM),BridgeOS)
63 DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_BRIDGE
64 else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
65 DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION)
66 else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
67 DEPLOYMENT_TARGET_FLAGS =
68 else
69 DEPLOYMENT_TARGET_FLAGS =
70 endif
71
72 DEPLOYMENT_TARGET_DEFINES = -DPLATFORM_$(PLATFORM)
73
74
75 #
76 # Standard defines list
77 #
78 DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
79 -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(CONFIG_DEFINES) \
80 $(SEED_DEFINES)
81
82 #
83 # Compiler command
84 #
85 KCC = $(CC)
86 KC++ = $(CXX)
87
88 GENASSYM_KCC = $(CC)
89
90 #
91 # Compiler warning flags
92 #
93
94 USE_WERROR := 1
95 ifneq ($(BUILD_WERROR),)
96 USE_WERROR := $(BUILD_WERROR)
97 endif
98
99 ifeq ($(USE_WERROR),1)
100 WERROR := -Werror
101 endif
102
103 # Shared C/C++ warning flags
104 WARNFLAGS_STD := \
105 -Weverything \
106 -Wextra \
107 $(WERROR) \
108 -Wpointer-arith \
109 -Wreturn-type \
110 -Wcast-qual \
111 -Wwrite-strings \
112 -Wswitch \
113 -Wcast-align \
114 -Wchar-subscripts \
115 -Wredundant-decls \
116 -Wextra-tokens \
117 -Wunreachable-code \
118 -Wno-assign-enum \
119 -Wno-bad-function-cast \
120 -Wno-c++98-compat \
121 -Wno-c++-compat \
122 -Wno-conditional-uninitialized \
123 -Wno-conversion \
124 -Wnull-conversion \
125 -Wstring-conversion \
126 -Wliteral-conversion \
127 -Wnon-literal-null-conversion \
128 -Wint-conversion \
129 -Wenum-conversion \
130 -Wfloat-conversion \
131 -Wconstant-conversion \
132 -Wpointer-bool-conversion \
133 -Wno-covered-switch-default \
134 -Wno-disabled-macro-expansion \
135 -Wno-documentation-unknown-command \
136 -Wno-format-non-iso \
137 -Wno-format-nonliteral \
138 -Wno-reserved-id-macro \
139 -Wno-language-extension-token \
140 -Wno-missing-variable-declarations \
141 -Wno-packed \
142 -Wno-padded \
143 -Wno-partial-availability \
144 -Wno-pedantic \
145 -Wno-shift-sign-overflow \
146 -Wno-switch-enum \
147 -Wno-undef \
148 -Wno-unused-macros \
149 -Wno-used-but-marked-unused \
150 -Wno-variadic-macros \
151 -Wno-vla \
152 -Wno-zero-length-array
153
154 CWARNFLAGS_STD = \
155 $(WARNFLAGS_STD) \
156 -Wstrict-prototypes \
157 -Wmissing-prototypes \
158 -Wshadow \
159 -Winline \
160 -Wnested-externs
161
162 # Can be overridden in Makefile.template or Makefile.$arch
163 export CWARNFLAGS ?= $(CWARNFLAGS_STD)
164
165 define add_perfile_cflags
166 $(1)_CWARNFLAGS_ADD += $2
167 endef
168
169 CXXWARNFLAGS_STD = \
170 $(WARNFLAGS_STD) \
171 -Wno-c++98-compat-pedantic \
172 -Wno-exit-time-destructors \
173 -Wno-global-constructors \
174 -Wno-old-style-cast
175
176 # overloaded-virtual warnings are non-fatal (9000888)
177 CXXWARNFLAGS_STD += -Wno-error=overloaded-virtual
178
179 # Can be overridden in Makefile.template or Makefile.$arch
180 export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
181
182 define add_perfile_cxxflags
183 $(1)_CXXWARNFLAGS_ADD += $2
184 endef
185
186 #
187 # Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
188
189 ARCH_FLAGS_X86_64 = -arch x86_64
190 ARCH_FLAGS_X86_64H = -arch x86_64h
191
192
193
194 #
195 # Default CFLAGS
196 #
197 ifdef RC_NONARCH_CFLAGS
198 OTHER_CFLAGS = $(RC_NONARCH_CLFAGS)
199 endif
200
201 #
202 # Debug info
203 #
204 DSYMINFODIR = Contents
205 DSYMKGMACROSDIR = Contents/Resources
206 DSYMLLDBMACROSDIR = Contents/Resources/Python
207 DSYMDWARFDIR = Contents/Resources/DWARF
208
209 DEBUG_CFLAGS := -g
210 BUILD_DSYM := 1
211
212 #
213 # We must not use -fno-keep-inline-functions, or it will remove the dtrace
214 # probes from the kernel.
215 #
216 CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \
217 -fno-builtin -fno-common \
218 -fsigned-bitfields $(OTHER_CFLAGS)
219
220 CFLAGS_RELEASE =
221 CFLAGS_DEVELOPMENT =
222 CFLAGS_DEBUG =
223 CFLAGS_KASAN = $(CFLAGS_DEVELOPMENT)
224 CFLAGS_PROFILE = -pg
225
226 CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
227 -DPAGE_SIZE_FIXED -mkernel -msoft-float
228
229 CFLAGS_X86_64H = $(CFLAGS_X86_64)
230
231
232 CFLAGS_RELEASEX86_64 = -O2
233 CFLAGS_DEVELOPMENTX86_64 = -O2
234 CFLAGS_KASANX86_64 = $(CFLAGS_DEVELOPMENTX86_64)
235 # No space optimization for the DEBUG kernel for the benefit of gdb:
236 CFLAGS_DEBUGX86_64 = -O0
237 CFLAGS_PROFILEX86_64 = -O2
238
239 CFLAGS_RELEASEX86_64H = -O2
240 CFLAGS_DEVELOPMENTX86_64H = -O2
241 CFLAGS_KASANX86_64H = $(CFLAGS_DEVELOPMENTX86_64H)
242 # No space optimization for the DEBUG kernel for the benefit of gdb:
243 CFLAGS_DEBUGX86_64H = -O0
244 CFLAGS_PROFILEX86_64H = -O2
245
246 CFLAGS_RELEASEARM = -O2
247 CFLAGS_DEVELOPMENTARM = -O2
248 CFLAGS_DEBUGARM = -O0
249 CFLAGS_PROFILEARM = -O2
250
251
252
253 #
254 # KASAN support
255 #
256
257
258 ifeq ($(CURRENT_KERNEL_CONFIG),KASAN)
259 KASAN = 1
260 endif
261
262 ifeq ($(KASAN),1)
263
264 BUILD_LTO = 0
265 KASAN_SHIFT_X86_64=0xdffffe1000000000
266 KASAN_SHIFT_X86_64H=$(KASAN_SHIFT_X86_64)
267 KASAN_SHIFT=$($(addsuffix $(CURRENT_ARCH_CONFIG),KASAN_SHIFT_))
268 KASAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
269 CFLAGS_GEN += -DKASAN=1 -DKASAN_SHIFT=$(KASAN_SHIFT) -fsanitize=address \
270 -mllvm -asan-globals-live-support \
271 -mllvm -asan-mapping-offset=$(KASAN_SHIFT) \
272 -fsanitize-blacklist=$(KASAN_BLACKLIST)
273
274 endif
275
276 CFLAGS = $(CFLAGS_GEN) \
277 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
278 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
279 $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) \
280 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_)) \
281 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_))) \
282 $(DEPLOYMENT_TARGET_FLAGS) \
283 $(DEPLOYMENT_TARGET_DEFINES) \
284 $(DEFINES)
285
286 #
287 # Default C++ flags
288 #
289
290 OTHER_CXXFLAGS =
291
292 CXXFLAGS_GEN = -std=gnu++11 -fapple-kext $(OTHER_CXXFLAGS)
293
294 CXXFLAGS = $(CXXFLAGS_GEN) \
295 $($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
296 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
297
298 #
299 # Assembler command
300 #
301 AS = $(CC)
302 S_KCC = $(CC)
303
304 #
305 # Default SFLAGS
306 #
307 SFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
308
309 SFLAGS_RELEASE =
310 SFLAGS_DEVELOPMENT =
311 SFLAGS_KASAN = $(SFLAGS_DEVELOPMENT) -DKASAN=1
312 SFLAGS_DEBUG =
313 SFLAGS_PROFILE =
314
315 SFLAGS_X86_64 = $(CFLAGS_X86_64)
316 SFLAGS_X86_64H = $(CFLAGS_X86_64H)
317
318 SFLAGS = $(SFLAGS_GEN) \
319 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
320 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
321 $($(addsuffix $(CURRENT_ARCH_CONFIG),SFLAGS_)) \
322 $($(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_)) \
323 $(DEPLOYMENT_TARGET_FLAGS) \
324 $(DEPLOYMENT_TARGET_DEFINES) \
325 $(DEFINES)
326
327 #
328 # Linker command
329 #
330 LD = $(KC++) -nostdlib
331
332 #
333 # Default LDFLAGS
334 #
335 # Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
336 # ctf_insert creates the CTF section. It needs reserved padding in the
337 # headers for the load command segment and the CTF section structures.
338 #
339 LDFLAGS_KERNEL_GEN = \
340 -nostdlib \
341 -fapple-kext \
342 -Wl,-e,__start \
343 -Wl,-sectalign,__TEXT,__text,0x1000 \
344 -Wl,-sectalign,__DATA,__common,0x1000 \
345 -Wl,-sectalign,__DATA,__bss,0x1000 \
346 -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
347 -Wl,-sectcreate,"__PLK_TEXT_EXEC",__text,/dev/null \
348 -Wl,-sectcreate,__PRELINK_DATA,__data,/dev/null \
349 -Wl,-sectcreate,"__PLK_DATA_CONST",__data,/dev/null \
350 -Wl,-sectcreate,"__PLK_LLVM_COV",__llvm_covmap,/dev/null \
351 -Wl,-sectcreate,"__PLK_LINKEDIT",__data,/dev/null \
352 -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
353 -Wl,-new_linker \
354 -Wl,-pagezero_size,0x0 \
355 -Wl,-version_load_command \
356 -Wl,-function_starts \
357 -Wl,-headerpad,152
358
359 LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
360
361 LDFLAGS_KERNEL_RELEASE =
362 LDFLAGS_KERNEL_DEVELOPMENT =
363 LDFLAGS_KERNEL_KASAN = $(LDFLAGS_KERNEL_DEVELOPMENT)
364 LDFLAGS_KERNEL_DEBUG =
365 LDFLAGS_KERNEL_PROFILE =
366
367 # KASLR static slide config:
368 ifndef SLIDE
369 SLIDE=0x00
370 endif
371 KERNEL_MIN_ADDRESS = 0xffffff8000000000
372 KERNEL_BASE_OFFSET = 0x100000
373 KERNEL_STATIC_SLIDE = $(shell printf "0x%016x" \
374 $$[ $(SLIDE) << 21 ])
375 KERNEL_STATIC_BASE = $(shell printf "0x%016x" \
376 $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
377 KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
378 $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
379 KERNEL_TEXT_BASE = $(shell printf "0x%016x" \
380 $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
381
382 LDFLAGS_KERNEL_RELEASEX86_64 = \
383 -Wl,-pie \
384 -Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
385 -Wl,-image_base,$(KERNEL_TEXT_BASE) \
386 -Wl,-seg_page_size,__TEXT,0x200000 \
387 -Wl,-sectalign,__HIB,__bootPT,0x1000 \
388 -Wl,-sectalign,__HIB,__desc,0x1000 \
389 -Wl,-sectalign,__HIB,__data,0x1000 \
390 -Wl,-sectalign,__HIB,__text,0x1000 \
391 -Wl,-sectalign,__HIB,__const,0x1000 \
392 -Wl,-sectalign,__HIB,__bss,0x1000 \
393 -Wl,-sectalign,__HIB,__common,0x1000 \
394 -Wl,-sectalign,__HIB,__llvm_prf_cnts,0x1000 \
395 -Wl,-sectalign,__HIB,__llvm_prf_names,0x1000 \
396 -Wl,-sectalign,__HIB,__llvm_prf_data,0x1000 \
397 -Wl,-sectalign,__HIB,__textcoal_nt,0x1000 \
398 -Wl,-rename_section,__DATA,__const,__CONST,__constdata \
399 -Wl,-no_zero_fill_sections \
400 $(LDFLAGS_NOSTRIP_FLAG)
401
402 ifeq ($(KASAN),1)
403 LDFLAGS_KERNEL_RELEASEX86_64 += \
404 -Wl,-sectalign,__HIB,__cstring,0x1000 \
405 -Wl,-sectalign,__HIB,__asan_globals,0x1000 \
406 -Wl,-sectalign,__HIB,__asan_liveness,0x1000 \
407 -Wl,-sectalign,__HIB,__mod_term_func,0x1000 \
408 -Wl,-rename_section,__HIB,__mod_init_func,__NULL,__mod_init_func \
409 -Wl,-rename_section,__HIB,__eh_frame,__NULL,__eh_frame
410 endif
411
412 # Define KERNEL_BASE_OFFSET so known at compile time:
413 CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
414 CFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
415
416 LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
417 LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
418 LDFLAGS_KERNEL_KASANX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
419 LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
420
421 LDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
422 LDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
423 LDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
424 LDFLAGS_KERNEL_KASANX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
425 LDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
426
427
428 LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
429 $(LDFLAGS_KERNEL_SDK) \
430 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
431 $($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
432 $($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
433 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
434 $(DEPLOYMENT_TARGET_FLAGS)
435
436 #
437 # Default runtime libraries to be linked with the kernel
438 #
439 LD_KERNEL_LIBS = -lcc_kext
440
441 #
442 # DTrace support
443 #
444 ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
445 ifneq ($(filter ARM%,$(CURRENT_ARCH_CONFIG)),)
446 DO_CTFCONVERT = 0
447 DO_CTFMERGE = 0
448 DO_CTFMACHO = 0
449 else
450 DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
451 DO_CTFMERGE = 1
452 DO_CTFMACHO = $(NEEDS_CTF_MACHOS)
453 endif
454 else
455 DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
456 DO_CTFMERGE = 1
457 DO_CTFMACHO = $(NEEDS_CTF_MACHOS)
458 endif
459
460 #
461 # Default INCFLAGS
462 #
463 INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
464 INCFLAGS_EXTERN = -I$(SRCROOT)/EXTERNAL_HEADERS
465 INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
466 INCFLAGS_LOCAL = -I.
467 INCFLAGS_SDK = -I$(SDKROOT)/usr/local/include/kernel
468
469 INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK)
470
471 #
472 # Default MIGFLAGS
473 #
474 MIGFLAGS = $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
475 $(DEPLOYMENT_TARGET_FLAGS)
476
477 # Support for LLVM Profile Guided Optimization (PGO)
478
479 ifeq ($(BUILD_PROFILE),1)
480 CFLAGS_GEN += -fprofile-instr-generate -DPROFILE
481 CXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
482 endif
483
484 ifdef USE_PROFILE
485 CFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
486 CXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
487 LDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
488
489 CFLAGS_GEN += -Wno-error=profile-instr-out-of-date
490 endif
491
492 #
493 # Support for LLVM Link Time Optimization (LTO)
494 #
495 # LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
496 # and defaults to enabled except for DEBUG kernels
497 #
498 # CFLAGS_NOLTO_FLAG is needed on a per-file basis (for files
499 # that deal poorly with LTO, or files that must be machine
500 # code *.o files for xnu to build (i.e, setsegname runs on
501 # them).
502 #
503 # LDFLAGS_NOSTRIP_FLAG is used to support configurations that
504 # do not utilize an export list. For these configs to build,
505 # we need to prevent the LTO logic from dead stripping them.
506
507 LTO_ENABLED_RELEASE = 1
508 LTO_ENABLED_DEVELOPMENT = 1
509 LTO_ENABLED_DEBUG = 0
510 LTO_ENABLED_KASAN = 0
511
512 ifneq ($(BUILD_LTO),)
513 USE_LTO = $(BUILD_LTO)
514 else
515 USE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
516 endif
517
518 SUPPORTS_CTFCONVERT = 0
519 ifeq ($(USE_LTO),1)
520 CFLAGS_GEN += -flto
521 CXXFLAGS_GEN += -flto
522 LDFLAGS_KERNEL_GEN += -Wl,-mllvm,-inline-threshold=125 -Wl,-object_path_lto,$(TARGET)/lto.o # -Wl,-mllvm -Wl,-disable-fp-elim
523 LDFLAGS_NOSTRIP_FLAG = -rdynamic
524 CFLAGS_NOLTO_FLAG = -fno-lto
525 NEEDS_CTF_MACHOS = 1
526 else
527 LDFLAGS_NOSTRIP_FLAG =
528 CFLAGS_NOLTO_FLAG =
529 ifneq ($(CTFCONVERT),)
530 SUPPORTS_CTFCONVERT = 1
531 endif
532 NEEDS_CTF_MACHOS = 0
533 endif
534
535 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
536 BUILD_DSYM := 0
537 DO_CTFCONVERT := 0
538 DO_CTFMERGE := 0
539 DO_CTFMACHO := 0
540 KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
541 KC++ = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CXX)
542 S_KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
543 STRIP = true
544 endif
545
546 #
547 # Default VPATH
548 #
549 export VPATH = .:$(SOURCE)
550
551
552
553 #
554 # Macros that control installation of kernel and its header files
555 #
556 # install flags for header files
557 #
558 INSTALL_FLAGS = -c -S -m 0444
559 DATA_INSTALL_FLAGS = -c -S -m 0644
560 EXEC_INSTALL_FLAGS = -c -S -m 0755
561
562 #
563 # Header file destinations
564 #
565 FRAMEDIR = /System/Library/Frameworks
566
567 SINCVERS = B
568 SINCFRAME = $(FRAMEDIR)/System.framework
569 SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
570 SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
571 SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
572
573 ifndef INCDIR
574 INCDIR = /usr/include
575 endif
576 ifndef LCLDIR
577 LCLDIR = $(SPINCDIR)
578 endif
579
580 KINCVERS = A
581 KINCFRAME = $(FRAMEDIR)/Kernel.framework
582 KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
583 KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
584 KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
585
586 XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
587
588
589 PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UPLATFORM_$(x)))
590
591 SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
592 SINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
593 KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
594 KINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
595
596 #
597 # Compononent Header file destinations
598 #
599 EXPDIR = EXPORT_HDRS/$(COMPONENT)
600
601 #
602 # Strip Flags
603 #
604 STRIP_FLAGS_RELEASE = -S -x
605 STRIP_FLAGS_DEVELOPMENT = -S
606 STRIP_FLAGS_KASAN = $(STRIP_FLAGS_DEVELOPMENT)
607 STRIP_FLAGS_DEBUG = -S
608 STRIP_FLAGS_PROFILE = -S -x
609
610 STRIP_FLAGS = $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
611
612 #
613 # dsymutil flags
614 #
615 DSYMUTIL_FLAGS_GEN = --minimize
616
617 DSYMUTIL_FLAGS_X86_64 = --arch=x86_64
618 DSYMUTIL_FLAGS_X86_64H = --arch=x86_64h
619
620 DSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
621 $($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
622
623 #
624 # Man Page destination
625 #
626 MANDIR = /usr/share/man
627
628 #
629 # DEBUG alias location
630 #
631 DEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_$(CURRENT_KERNEL_CONFIG_LC)
632
633 #
634 # mach_kernel install location
635 #
636 INSTALL_KERNEL_DIR = /
637
638 #
639 # new OS X install location
640 #
641 SYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
642
643 #
644 # File names in DSTROOT
645 #
646
647 ifeq ($(PLATFORM),MacOSX)
648 KERNEL_FILE_NAME_PREFIX = kernel
649 else
650 KERNEL_FILE_NAME_PREFIX = mach
651 endif
652
653 ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
654 ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
655 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
656 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
657 else
658 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
659 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
660 endif
661 else
662 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
663 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
664 endif
665
666 CURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
667 CURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
668 ifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
669 ALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
670 endif
671
672 #
673 # System.kext pseudo-kext install location
674 #
675 INSTALL_EXTENSIONS_DIR = /System/Library/Extensions
676
677 #
678 # KDK location
679 #
680 INSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
681
682 #
683 # Misc. Etc.
684 #
685 INSTALL_SHARE_MISC_DIR = /usr/share/misc
686 INSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
687 INSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
688
689 #
690 # Overrides for XBS build aliases
691 #
692 ifeq ($(RC_ProjectName),xnu_debug)
693 INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
694 INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
695 INSTALL_KERNEL_SYM_TO_KDK = 1
696 INSTALL_XNU_DEBUG_FILES = 1
697 else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
698 INSTALL_KERNEL_SYM_TO_KDK = 1
699 USE_BINARY_PLIST = 1
700 else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
701 USE_BINARY_PLIST = 1
702 else ifeq ($(PLATFORM),MacOSX)
703 INSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
704 INSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
705 INSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
706 endif
707
708 ifeq ($(RC_ProjectName),xnu_kasan)
709 INSTALL_KASAN_ONLY = 1
710 endif
711
712 # vim: set ft=make: