]> git.saurik.com Git - apple/xnu.git/blobdiff - makedefs/MakeInc.def
xnu-3789.41.3.tar.gz
[apple/xnu.git] / makedefs / MakeInc.def
index 5c9d12e8670ede72c222490b78908e0567d15fd7..b05ec67cab0fb4d1f6a031d618ceea34e0902ce3 100644 (file)
-export SOURCE=$(shell /bin/pwd)
-
+# -*- mode: makefile;-*-
+#
+# Copyright (C) 1999-2016 Apple Inc. All rights reserved.
 #
-# gnumake 3.77 support
+# MakeInc.def contains global definitions for building,
+# linking, and installing files.
 #
-export USE_APPLE_PB_SUPPORT = all
 
 #
-# Incremental Build option
+# Architecture Configuration options
 #
-ifndef INCR_EXPORTHDRS
-ifeq ($(shell test -d $$OBJROOT/EXPORT_HDRS;echo $$?),0)
-export INCR_EXPORTHDRS = TRUE
-else
-export INCR_EXPORTHDRS = FALSE
-endif
-endif
-
-ifndef INCR_INSTALLHDRS
-ifeq ($(shell test -d $$DSTROOT/$INCDIR;echo $$?),0)
-export INCR_INSTALLHDRS        = TRUE
-else
-export INCR_INSTALLHDRS        = FALSE
-endif
-endif
+SUPPORTED_ARCH_CONFIGS := X86_64 X86_64H
 
 #
-# Component List
+# Kernel Configuration options
 #
-ifndef COMPONENT_LIST 
-export COMPONENT_LIST  = osfmk bsd iokit pexpert libkern libsa
-export COMPONENT_LIST_UC := $(shell echo -n $(COMPONENT_LIST) | $(TR) a-z A-Z)
-endif
-ifndef COMPONENT
-export COMPONENT       := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
-export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) 
-else
-ifeq   ($(COMPONENT), .)
-export COMPONENT        := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
-export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) 
-endif
-endif
+SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE
 
-# Architecture options
 #
-#  supported configurations : PPC I386
+# Machine Configuration options
 #
-ifndef ARCH_CONFIGS
-ifdef RC_ARCHS
-export ARCH_CONFIGS    := $(shell echo -n $(RC_ARCHS) | $(TR) a-z A-Z)
-else
-export ARCH_CONFIGS    := $(shell arch | $(TR) a-z A-Z)
-endif
-endif
-ifdef  ARCH_CONFIG
-ifndef ARCH_CONFIG_LC
-export ARCH_CONFIG_LC  := $(shell echo -n $(ARCH_CONFIG) | $(TR) A-Z a-z)
-endif
-endif
+
+SUPPORTED_X86_64_MACHINE_CONFIGS = NONE
+SUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
 
 
-# Kernel Configuration options  
 #
-# supported configurations : RELEASE DEBUG PROFILE
+# Setup up *_LC variables during recursive invocations
 #
-ifndef KERNEL_CONFIGS
-export KERNEL_CONFIGS  = RELEASE
+
+ifndef CURRENT_ARCH_CONFIG_LC
+       export CURRENT_ARCH_CONFIG_LC   := $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
+endif
+
+ifndef CURRENT_KERNEL_CONFIG_LC
+       export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
 endif
-ifndef KERNEL_CONFIG
-export KERNEL_CONFIG   = $(firstword $(KERNEL_CONFIGS))
+
+ifndef CURRENT_MACHINE_CONFIG_LC
+       export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
 endif
 
 #
-# Kernel Configuration to install
+# Component List
+#
+COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security
+COMPONENT      = $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
+COMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
+
+
 #
-#  supported install architecture : PPC I386
+# Deployment target flag
 #
-export INSTALL_TYPE    = RELEASE
-ifndef INSTALL_ARCHS
-ifdef RC_ARCHS
-export INSTALL_ARCHS   = $(ARCH_CONFIGS)
+ifeq ($(PLATFORM),MacOSX)
+    DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION)
+else ifeq ($(PLATFORM),WatchOS)
+    DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION)
+else ifeq ($(PLATFORM),tvOS)
+    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
+else ifeq ($(PLATFORM),AppleTVOS)
+    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
+else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
+    DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION)
+else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
+    DEPLOYMENT_TARGET_FLAGS =
 else
-export INSTALL_ARCHS   = $(ARCH_CONFIGS)
-endif
-export INSTALL_ARCHS_LC := $(shell echo -n $(ARCH_CONFIGS) | $(TR) A-Z a-z)
+    DEPLOYMENT_TARGET_FLAGS =
 endif
 
-export INSTALL_ARCH_DEFAULT    = PPC
+DEPLOYMENT_TARGET_DEFINES = -DPLATFORM_$(PLATFORM)
+
 
 #
 # Standard defines list
 #
-export DEFINES = -DAPPLE -DNeXT -DKERNEL_PRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(IDENT)
+DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
+       -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(CONFIG_DEFINES) \
+       $(SEED_DEFINES)
 
 #
 # Compiler command
 #
-KCC  = /usr/bin/cc
-KC++ = /usr/bin/c++
-CC   = $(KCC)
+KCC  = $(CC)
+KC++ = $(CXX)
+
+GENASSYM_KCC = $(CC)
+
+#
+# Compiler warning flags
+#
+
+CWARNFLAGS_STD = \
+       -Weverything -Werror -Wextra -Wstrict-prototypes \
+       -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
+       -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \
+       -Winline -Wnested-externs -Wredundant-decls -Wextra-tokens \
+       -Wunreachable-code \
+       -Wno-assign-enum \
+       -Wno-bad-function-cast \
+       -Wno-c++98-compat \
+       -Wno-c++-compat \
+       -Wno-conditional-uninitialized \
+       -Wno-conversion \
+       -Wno-covered-switch-default \
+       -Wno-disabled-macro-expansion \
+       -Wno-documentation-unknown-command \
+       -Wno-format-non-iso \
+       -Wno-format-nonliteral \
+       -Wno-reserved-id-macro \
+       -Wno-language-extension-token \
+       -Wno-missing-variable-declarations \
+       -Wno-packed \
+       -Wno-padded \
+       -Wno-partial-availability \
+       -Wno-pedantic \
+       -Wno-shift-sign-overflow \
+       -Wno-switch-enum \
+       -Wno-undef \
+       -Wno-unused-macros \
+       -Wno-used-but-marked-unused \
+       -Wno-variadic-macros \
+       -Wno-vla \
+       -Wno-zero-length-array
+
+# Can be overridden in Makefile.template or Makefile.$arch
+export CWARNFLAGS ?= $(CWARNFLAGS_STD)
+
+define add_perfile_cflags
+$(1)_CWARNFLAGS_ADD += $2
+endef
+
+CXXWARNFLAGS_STD = \
+       -Weverything -Werror -Wextra -Wpointer-arith -Wreturn-type \
+       -Wcast-qual -Wwrite-strings -Wswitch -Wcast-align -Wchar-subscripts \
+       -Wredundant-decls -Wextra-tokens \
+       -Wunreachable-code \
+       -Wno-assign-enum \
+       -Wno-bad-function-cast \
+       -Wno-c++98-compat \
+       -Wno-c++98-compat-pedantic \
+       -Wno-c++-compat \
+       -Wno-conditional-uninitialized \
+       -Wno-conversion \
+       -Wno-covered-switch-default \
+       -Wno-disabled-macro-expansion \
+       -Wno-documentation-unknown-command \
+       -Wno-exit-time-destructors \
+       -Wno-format-non-iso \
+       -Wno-format-nonliteral \
+       -Wno-global-constructors \
+       -Wno-reserved-id-macro \
+       -Wno-language-extension-token \
+       -Wno-missing-variable-declarations \
+       -Wno-old-style-cast \
+       -Wno-packed \
+       -Wno-padded \
+       -Wno-partial-availability \
+       -Wno-pedantic \
+       -Wno-shift-sign-overflow \
+       -Wno-switch-enum \
+       -Wno-undef \
+       -Wno-unused-macros \
+       -Wno-used-but-marked-unused \
+       -Wno-variadic-macros \
+       -Wno-vla \
+       -Wno-zero-length-array
+
+# overloaded-virtual warnings are non-fatal (9000888)
+CXXWARNFLAGS_STD += -Wno-error=overloaded-virtual
+
+# Can be overridden in Makefile.template or Makefile.$arch
+export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
+
+define add_perfile_cxxflags
+$(1)_CXXWARNFLAGS_ADD += $2
+endef
+
+#
+# Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
+
+ARCH_FLAGS_X86_64        = -arch x86_64
+ARCH_FLAGS_X86_64H       = -arch x86_64h
 
 
-#
-# Setup for parallel sub-makes when doing an RC build
-#
-ifndef MAKEJOBS
-ifeq "YES" "$(RC_XBS)"
-export MAKEJOBS = --jobs=3
-endif
-endif
 
 #
 # Default CFLAGS
 #
 ifdef RC_CFLAGS
-export OTHER_CFLAGS    = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS))
+OTHER_CFLAGS   = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS))
 endif
 
-export CFLAGS_GEN = -static -g -nostdinc -nostdlib -no-cpp-precomp \
-       -fno-builtin -finline -fno-keep-inline-functions -msoft-float \
-       -fsigned-bitfields -Wpointer-arith $(OTHER_CFLAGS) -fpermissive 
+#
+# Debug info
+#
+DSYMINFODIR    = Contents
+DSYMKGMACROSDIR        = Contents/Resources
+DSYMLLDBMACROSDIR = Contents/Resources/Python
+DSYMDWARFDIR   = Contents/Resources/DWARF
+
+DEBUG_CFLAGS := -gdwarf-2
+BUILD_DSYM := 1
+
+#
+# We must not use -fno-keep-inline-functions, or it will remove the dtrace
+# probes from the kernel.
+#
+CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \
+       -fno-builtin -fno-common \
+       -fsigned-bitfields $(OTHER_CFLAGS)
+
+CFLAGS_RELEASE =
+CFLAGS_DEVELOPMENT     =
+CFLAGS_DEBUG   =
+CFLAGS_PROFILE =  -pg
+
+CFLAGS_X86_64  = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
+                               -DPAGE_SIZE_FIXED -mkernel -msoft-float
+
+CFLAGS_X86_64H = $(CFLAGS_X86_64)
+
 
-export CFLAGS_RELEASE  = 
-export CFLAGS_DEBUG    = -fno-omit-frame-pointer
-export CFLAGS_PROFILE  = 
+CFLAGS_RELEASEX86_64 = -O2
+CFLAGS_DEVELOPMENTX86_64 = -O2
+# No space optimization for the DEBUG kernel for the benefit of gdb:
+CFLAGS_DEBUGX86_64 = -O0
+CFLAGS_PROFILEX86_64 = -O2
 
-export CFLAGS_PPC      = -arch ppc -Dppc -DPPC -D__PPC__ -D_BIG_ENDIAN=__BIG_ENDIAN__
-export CFLAGS_I386     = -arch i386 -Di386 -DI386 -D__I386__ -D_BIG_ENDIAN=__LITTLE_ENDIAN__
+CFLAGS_RELEASEX86_64H = -O2
+CFLAGS_DEVELOPMENTX86_64H = -O2
+# No space optimization for the DEBUG kernel for the benefit of gdb:
+CFLAGS_DEBUGX86_64H = -O0
+CFLAGS_PROFILEX86_64H = -O2
 
-export CFLAGS_RELEASEPPC = -O2 -mcpu=750 -mmultiple -fschedule-insns
-export CFLAGS_RELEASE_TRACEPPC = -O2 -mcpu=750 -mmultiple -fschedule-insns
-export CFLAGS_DEBUGPPC = -O2 -mcpu=750 -mmultiple -fschedule-insns
-export CFLAGS_RELEASEI386 = -O2
-export CFLAGS_DEBUGI386 = -O2
+CFLAGS_RELEASEARM = -O2
+CFLAGS_DEVELOPMENTARM = -O2
+CFLAGS_DEBUGARM = -O0
+CFLAGS_PROFILEARM = -O2
 
-export CFLAGS  = $(CFLAGS_GEN) \
-                 $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \
-                 $($(addsuffix $(KERNEL_CONFIG),CFLAGS_)) \
-                 $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),CFLAGS_))) \
+
+CFLAGS = $(CFLAGS_GEN) \
+                 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) \
+                 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_))) \
+                 $(DEPLOYMENT_TARGET_FLAGS) \
+                 $(DEPLOYMENT_TARGET_DEFINES) \
                  $(DEFINES)
 
-# Default CCFLAGS
-#(we do not call it CPPFLAGS as that has a special meaning in unix tradition
-# and in gcc: CPPFLAGS is for C Pre-Processor flags.  CCFLAGS has precedent
-# in ProjectBuilder because of the .cc extension)
 #
-CPPFLAGS_GEN  = -fno-rtti -fno-exceptions -fcheck-new -fapple-kext 
+# Default C++ flags
+#
+
+OTHER_CXXFLAGS =
+
+CXXFLAGS_GEN  = -std=gnu++11 -fapple-kext $(OTHER_CXXFLAGS)
 
-CPPFLAGS      = $(CPPFLAGS_GEN) \
-                 $($(addsuffix $(ARCH_CONFIG),CCFLAGS_)) \
-                 $($(addsuffix $(KERNEL_CONFIG),CCFLAGS_))
+CXXFLAGS      = $(CXXFLAGS_GEN) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
+                 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
 
 #
 # Assembler command
 #
-AS     = /usr/bin/cc
-S_KCC  = /usr/bin/cc
+AS     = $(CC)
+S_KCC  = $(CC)
 
 #
 # Default SFLAGS
 #
-export SFLAGS_GEN = -static -D__ASSEMBLER__ -force_cpusubtype_ALL $(OTHER_CFLAGS)
+SFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
 
-export SFLAGS_RELEASE  = 
-export SFLAGS_DEBUG    = 
-export SFLAGS_PROFILE  = 
+SFLAGS_RELEASE =
+SFLAGS_DEVELOPMENT     =
+SFLAGS_DEBUG   =
+SFLAGS_PROFILE =
 
-export SFLAGS_PPC      = $(CFLAGS_PPC)
-export SFLAGS_I386     = $(CFLAGS_I386)
+SFLAGS_X86_64  = $(CFLAGS_X86_64)
+SFLAGS_X86_64H = $(CFLAGS_X86_64H)
 
-export SFLAGS  = $(SFLAGS_GEN) \
-                 $($(addsuffix $(ARCH_CONFIG),SFLAGS_)) \
-                 $($(addsuffix $(KERNEL_CONFIG),SFLAGS_)) \
+SFLAGS = $(SFLAGS_GEN) \
+                 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),SFLAGS_)) \
+                 $($(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_)) \
+                 $(DEPLOYMENT_TARGET_FLAGS) \
+                 $(DEPLOYMENT_TARGET_DEFINES) \
                  $(DEFINES)
 
 #
 # Linker command
 #
-LD     = /usr/bin/ld
+LD     = $(KC++) -nostdlib
 
 #
 # Default LDFLAGS
 #
-export LDFLAGS_COMPONENT_GEN = -static -r 
+# Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
+# ctf_insert creates the CTF section.  It needs reserved padding in the
+# headers for the load command segment and the CTF section structures.
+#
+LDFLAGS_KERNEL_GEN = \
+       -nostdlib \
+       -fapple-kext \
+       -Wl,-e,__start \
+       -Wl,-sectalign,__TEXT,__text,0x1000 \
+       -Wl,-sectalign,__DATA,__common,0x1000 \
+       -Wl,-sectalign,__DATA,__bss,0x1000 \
+    -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
+    -Wl,-sectcreate,"__PLK_TEXT_EXEC",__text,/dev/null \
+    -Wl,-sectcreate,__PRELINK_DATA,__data,/dev/null \
+    -Wl,-sectcreate,"__PLK_DATA_CONST",__data,/dev/null \
+    -Wl,-sectcreate,"__PLK_LINKEDIT",__data,/dev/null \
+       -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
+       -Wl,-new_linker \
+       -Wl,-pagezero_size,0x0 \
+       -Wl,-version_load_command \
+       -Wl,-function_starts \
+       -Wl,-headerpad,152
+
+LDFLAGS_KERNEL_SDK     = -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
+
+LDFLAGS_KERNEL_RELEASE =
+LDFLAGS_KERNEL_DEVELOPMENT     =
+LDFLAGS_KERNEL_DEBUG   =
+LDFLAGS_KERNEL_PROFILE =
+
+# KASLR static slide config:
+ifndef SLIDE
+SLIDE=0x00
+endif
+KERNEL_MIN_ADDRESS      = 0xffffff8000000000
+KERNEL_BASE_OFFSET      = 0x100000
+KERNEL_STATIC_SLIDE     = $(shell printf "0x%016x" \
+                         $$[ $(SLIDE) << 21 ])
+KERNEL_STATIC_BASE      = $(shell printf "0x%016x" \
+                         $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
+KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
+                         $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
+KERNEL_TEXT_BASE        = $(shell printf "0x%016x" \
+                         $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
+
+LDFLAGS_KERNEL_RELEASEX86_64 = \
+       -Wl,-pie \
+       -Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
+       -Wl,-image_base,$(KERNEL_TEXT_BASE) \
+       -Wl,-seg_page_size,__TEXT,0x200000 \
+       -Wl,-sectalign,__HIB,__bootPT,0x1000 \
+       -Wl,-sectalign,__HIB,__desc,0x1000 \
+       -Wl,-sectalign,__HIB,__data,0x1000 \
+       -Wl,-sectalign,__HIB,__text,0x1000 \
+       -Wl,-sectalign,__HIB,__const,0x1000 \
+       -Wl,-sectalign,__HIB,__bss,0x1000 \
+       -Wl,-sectalign,__HIB,__common,0x1000 \
+       -Wl,-sectalign,__HIB,__llvm_prf_cnts,0x1000 \
+       -Wl,-sectalign,__HIB,__llvm_prf_names,0x1000 \
+       -Wl,-sectalign,__HIB,__llvm_prf_data,0x1000 \
+       -Wl,-sectalign,__HIB,__textcoal_nt,0x1000 \
+       -Wl,-rename_section,__DATA,__const,__CONST,__constdata \
+       -Wl,-no_zero_fill_sections \
+       $(LDFLAGS_NOSTRIP_FLAG)
+
+# Define KERNEL_BASE_OFFSET so known at compile time:
+CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
+CFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
+
+LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
+
+LDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
+LDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
+LDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
+LDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
+
+
+LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
+                 $(LDFLAGS_KERNEL_SDK) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
+                 $($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
+                 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
+                 $(DEPLOYMENT_TARGET_FLAGS)
 
-export LDFLAGS_COMPONENT_RELEASE       = 
-export LDFLAGS_COMPONENT_DEBUG                 = 
-export LDFLAGS_COMPONENT_PROFILE       = 
+#
+# Default runtime libraries to be linked with the kernel
+#
+LD_KERNEL_LIBS = -lcc_kext
 
-export LDFLAGS_COMPONENT_PPC   = -arch ppc
-export LDFLAGS_COMPONENT_I386  = -arch i386
+#
+# DTrace support
+#
+ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
+ifneq ($(filter ARM%,$(CURRENT_ARCH_CONFIG)),)
+DO_CTFCONVERT = 0
+DO_CTFMERGE   = 0
+DO_CTFMACHO   = 0
+else
+DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
+DO_CTFMERGE   = 1
+DO_CTFMACHO   = $(NEEDS_CTF_MACHOS)
+endif
+else
+DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
+DO_CTFMERGE   = 1
+DO_CTFMACHO   = $(NEEDS_CTF_MACHOS)
+endif
 
-export LDFLAGS_COMPONENT       = $(LDFLAGS_COMPONENT_GEN) \
-                 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_COMPONENT_)) \
-                 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_COMPONENT_))
+#
+# Default INCFLAGS
+#
+INCFLAGS_IMPORT        = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
+INCFLAGS_EXTERN        = -I$(SRCROOT)/EXTERNAL_HEADERS
+INCFLAGS_GEN   = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
+INCFLAGS_LOCAL = -I.
+INCFLAGS_SDK   = -I$(SDKROOT)/usr/local/include/kernel
 
-export LDFLAGS_KERNEL_GEN = -static -force_cpusubtype_ALL -segalign 0x1000
+INCFLAGS       = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK)
 
-export LDFLAGS_KERNEL_RELEASE  =
-#  -noseglinkedit
-export LDFLAGS_KERNEL_DEBUG    = 
-export LDFLAGS_KERNEL_PROFILE  = 
+#
+# Default MIGFLAGS
+#
+MIGFLAGS       = $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
+               $(DEPLOYMENT_TARGET_FLAGS)
+
+# Support for LLVM Profile Guided Optimization (PGO)
 
-export LDFLAGS_KERNEL_PPC      = -arch ppc -segaddr __VECTORS 0x0 -segaddr __TEXT 0x7000 -e __start -sectalign __TEXT __text 0x1000 -sectalign __DATA __common 0x1000 -sectalign __DATA __bss 0x1000
-export LDFLAGS_KERNEL_I386     = -arch i386 -segaddr __TEXT 0x100000 -e _pstart
+ifeq ($(BUILD_PROFILE),1)
+CFLAGS_GEN += -fprofile-instr-generate -DPROFILE
+CXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
+endif
 
-export LDFLAGS_KERNEL  = $(LDFLAGS_KERNEL_GEN) \
-                 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \
-                 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))
+ifdef USE_PROFILE
+CFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
+CXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
+LDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
 
+CFLAGS_GEN += -Wno-error=profile-instr-out-of-date
+endif
 
 #
-# Default runtime libraries to be linked with the kernel
+# Support for LLVM Link Time Optimization (LTO)
 #
-export LD_KERNEL_LIBS  = -lcc_kext
-
+# LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
+# and defaults to enabled except for DEBUG kernels
 #
-# Default INCFLAGS
+# CFLAGS_NOLTO_FLAG is needed on a per-file basis (for files
+# that deal poorly with LTO, or files that must be machine
+# code *.o files for xnu to build (i.e, setsegname runs on
+# them).
 #
-export INCFLAGS_IMPORT         = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
-export INCFLAGS_EXTERN         = -I$(OBJROOT)/EXTERN_HDRS -I$(SRCROOT)/EXTERNAL_HEADERS -I$(SRCROOT)/EXTERNAL_HEADERS/bsd
-export INCFLAGS_GEN    = -I$(SRCROOT)/$(COMPONENT) 
-export INCFLAGS_POSIX  = -I$(OBJROOT)/EXPORT_HDRS/bsd
-export INCFLAGS_LOCAL  = -I.
+# LDFLAGS_NOSTRIP_FLAG is used to support configurations that
+# do not utilize an export list.  For these configs to build,
+# we need to prevent the LTO logic from dead stripping them.
 
-export INCFLAGS        = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE)
+LTO_ENABLED_RELEASE = 1
+LTO_ENABLED_DEVELOPMENT = 1
+LTO_ENABLED_DEBUG = 0
 
-#
-# Default MIGFLAGS
-#
-export MIGFLAGS        = $(DEFINES) $(INCFLAGS) $($(addsuffix $(ARCH_CONFIG),CFLAGS_))
+ifneq ($(BUILD_LTO),)
+USE_LTO = $(BUILD_LTO)
+else
+USE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
+endif
+
+SUPPORTS_CTFCONVERT    = 0
+ifeq ($(USE_LTO),1)
+CFLAGS_GEN     += -flto
+CXXFLAGS_GEN   += -flto
+LDFLAGS_KERNEL_GEN     += -Wl,-mllvm,-inline-threshold=125 -Wl,-object_path_lto,$(TARGET)/lto.o # -Wl,-mllvm -Wl,-disable-fp-elim
+LDFLAGS_NOSTRIP_FLAG = -rdynamic
+CFLAGS_NOLTO_FLAG = -fno-lto
+NEEDS_CTF_MACHOS       = 1
+else
+LDFLAGS_NOSTRIP_FLAG =
+CFLAGS_NOLTO_FLAG =
+ifneq ($(CTFCONVERT),)
+SUPPORTS_CTFCONVERT    = 1
+endif
+NEEDS_CTF_MACHOS       = 0
+endif
+
+ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
+BUILD_DSYM     := 0
+DO_CTFCONVERT  := 0
+DO_CTFMERGE    := 0
+DO_CTFMACHO    := 0
+KCC            = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
+KC++           = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CXX)
+S_KCC          = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
+STRIP          = true
+endif
 
 #
 # Default VPATH
 #
-empty:=
-space:= $(empty) $(empty)
-export VPATH_IMPORT    = $(subst $(space),:,$(patsubst %,$(OBJROOT)/EXPORT_HDRS/%,$(strip $(COMPONENT_IMPORT_LIST)))):
-export VPATH_EXTERN    = $(OBJROOT)/EXTERN_HDRS:
-export VPATH_GEN       = .:$(SOURCE):
-
-export VPATH           = $(VPATH_GEN)$(VPATH_IMPORT)$(VPATH_EXTERN)$(VPATH_MAKEFILE)
+export VPATH = .:$(SOURCE)
 
 #
-# Macros that control installation of kernel and it's header files
+# Macros that control installation of kernel and its header files
 #
 # install flags for header files
-# 
-INSTALL_FLAGS = -c -m 0444
-FILE_INSTALL_FLAGS = -c -m 0644
-DATA_INSTALL_FLAGS = -c -m 0644
+#
+INSTALL_FLAGS = -c -S -m 0444
+DATA_INSTALL_FLAGS = -c -S -m 0644
+EXEC_INSTALL_FLAGS = -c -S -m 0755
 
 #
 # Header file destinations
 #
-FRAMEDIR = System/Library/Frameworks
+FRAMEDIR = /System/Library/Frameworks
+
+SINCVERS = B
+SINCFRAME = $(FRAMEDIR)/System.framework
+SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
+SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
+SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
+
 ifndef INCDIR
     INCDIR = /usr/include
 endif
 ifndef LCLDIR
-    LCLDIR = $(FRAMEDIR)/System.framework/Versions/B/PrivateHeaders
+    LCLDIR = $(SPINCDIR)
 endif
 
 KINCVERS = A
 KINCFRAME = $(FRAMEDIR)/Kernel.framework
 KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
 KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
+KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
+
+XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
+
+
+PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UPLATFORM_$(x)))
+
+SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
+SINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
+KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
+KINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
 
 #
 # Compononent Header file destinations
@@ -274,24 +548,107 @@ EXPDIR = EXPORT_HDRS/$(COMPONENT)
 #
 # Strip Flags
 #
-export STRIP_FLAGS_RELEASE     = -S 
-export STRIP_FLAGS_RELEASE_TRACE       = -S 
-export STRIP_FLAGS_DEBUG       = -S 
-export STRIP_FLAGS_PROFILE     = -S 
+STRIP_FLAGS_RELEASE    = -S -x
+STRIP_FLAGS_DEVELOPMENT        = -S
+STRIP_FLAGS_DEBUG      = -S
+STRIP_FLAGS_PROFILE    = -S -x
+
+STRIP_FLAGS    = $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
+
+#
+# dsymutil flags
+#
+DSYMUTIL_FLAGS_GEN     = --minimize
+
+DSYMUTIL_FLAGS_X86_64  = --arch=x86_64
+DSYMUTIL_FLAGS_X86_64H = --arch=x86_64h
 
-export STRIP_FLAGS     = $($(addsuffix $(KERNEL_CONFIG),STRIP_FLAGS_)) 
+DSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
+       $($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
 
 #
 # Man Page destination
 #
-MANDIR = usr/share/man
+MANDIR = /usr/share/man
 
 #
-#  This must be here before any rules are possibly defined by the
-#  machine dependent makefile fragment so that a plain "make" command
-#  always works.  The config program will emit an appropriate rule to
-#  cause "all" to depend on every kernel configuration it generates.
+# DEBUG alias location
 #
+DEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_debug
 
-default: all
+#
+# mach_kernel install location
+#
+INSTALL_KERNEL_DIR = /
+
+#
+# new OS X install location
+#
+SYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
+
+#
+# File names in DSTROOT
+#
+
+ifeq ($(PLATFORM),MacOSX)
+KERNEL_FILE_NAME_PREFIX = kernel
+else
+KERNEL_FILE_NAME_PREFIX = mach
+endif
+
+ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
+ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
+KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
+KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
+else
+KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
+KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
+endif
+else
+KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
+KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
+endif
+
+CURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
+CURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
+ifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
+ALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
+endif
+
+#
+# System.kext pseudo-kext install location
+#
+INSTALL_EXTENSIONS_DIR = /System/Library/Extensions
+
+#
+# KDK location
+#
+INSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
+
+#
+# Misc. Etc.
+#
+INSTALL_SHARE_MISC_DIR = /usr/share/misc
+INSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
+INSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
+
+#
+# Overrides for XBS build aliases
+#
+ifeq ($(RC_ProjectName),xnu_debug)
+INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
+INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
+INSTALL_KERNEL_SYM_TO_KDK = 1
+INSTALL_XNU_DEBUG_FILES = 1
+else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
+INSTALL_KERNEL_SYM_TO_KDK = 1
+USE_BINARY_PLIST = 1
+else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
+USE_BINARY_PLIST = 1
+else ifeq ($(PLATFORM),MacOSX)
+INSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
+INSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
+INSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
+endif
 
+# vim: set ft=make: