1 export SOURCE=$(shell /bin/pwd)
6 export USE_APPLE_PB_SUPPORT = all
9 # Incremental Build option
11 ifndef INCR_EXPORTHDRS
12 ifeq ($(shell test -d $$OBJROOT/EXPORT_HDRS;echo $$?),0)
13 export INCR_EXPORTHDRS = TRUE
15 export INCR_EXPORTHDRS = FALSE
24 export COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security
25 export COMPONENT_LIST_UC := $(shell printf "%s" "$(COMPONENT_LIST)" | $(TR) a-z A-Z)
28 export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
29 export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST))
31 ifeq ($(COMPONENT), .)
32 export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
33 export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST))
37 # Architecture options
39 ifndef SUPPORTED_ARCH_CONFIGS
40 export SUPPORTED_ARCH_CONFIGS = PPC I386 X86_64 ARM
45 export ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z)
47 export ARCH_CONFIGS := $(shell arch | $(TR) a-z A-Z)
52 export ARCH_CONFIG_LC := $(shell printf "%s" "$(ARCH_CONFIG)" | $(TR) A-Z a-z)
57 # Kernel Configuration options
59 ifndef SUPPORTED_KERNEL_CONFIGS
60 export SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE
63 ifndef DEFAULT_KERNEL_CONFIG
64 ifeq ($(RC_ProjectName),xnu_debug)
65 export DEFAULT_KERNEL_CONFIG = DEBUG
67 export DEFAULT_KERNEL_CONFIG = RELEASE
71 # If KERNEL_CONFIGS is specified it should override KERNEL_CONFIG.
72 # If KERNEL_CONFIG is specified it will override the default. Will quit with
73 # error if more than one config is specified.
74 # If DEFAULT_KERNEL_CONFIG is not specified then it will be built RELEASE.
77 export KERNEL_CONFIGS = $(DEFAULT_KERNEL_CONFIG)
79 export KERNEL_CONFIGS = $(KERNEL_CONFIG)
84 export KERNEL_CONFIG = $(firstword $(KERNEL_CONFIGS))
87 ifneq ($(words $(KERNEL_CONFIG)), 1)
88 $(error There were $(words $(KERNEL_CONFIG)) parameters passed to KERNEL_CONFIG = $(KERNEL_CONFG). \
89 Are you sure? To specify multiple configurations please use KERNEL_CONFIGS)
93 export MACHINE_CONFIG = DEFAULT
98 # Target configuration options. NOTE - target configurations will
99 # override ARCH_CONFIGS and KERNEL_CONFIGS.
101 # Target configs come in groups of three parameters. The first is the
102 # kernel configuration, the second is the architecture configuration,
103 # and the third is the machine configuration. You may pass in as
104 # many groups of configurations as you wish. Each item passed in is
105 # seperated by whitespace.
108 # TARGET_CONFIGS="release ppc default debug i386 default release arm MX31ADS"
109 # Parameters may be in upper or lower case (they are converted to upper).
111 # "default" parameter is a special case. It means use the default value for
112 # that parameter. Here are the default values for each configuration:
114 # default kernel configuration = DEFAULT_KERNEL_CONFIG
115 # default architecture configuration = system architecture where you are running make.
116 # default machine configuration for ppc = none at this time.
117 # default machine configuration for i386 = none at this time.
118 # default machine configuration for x86_64 = none at this time.
119 # default machine configuration for arm = "S5L8900X".
121 ifndef TARGET_CONFIGS_UC
123 export TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z))
124 export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC))
125 export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC))
127 # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIG (which defaults to "DEFAULT")
128 temp_list = $(foreach my_kern_config, $(KERNEL_CONFIGS), $(my_kern_config) arch_slot $(MACHINE_CONFIG))
129 export TARGET_CONFIGS = $(strip $(foreach my_arch_config, $(ARCH_CONFIGS), $(subst arch_slot,$(my_arch_config),$(temp_list))))
130 export TARGET_CONFIGS_UC := $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z)
131 export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC))
132 export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC))
136 export MACHINE_CONFIG_LC := $(shell printf "%s" "$(MACHINE_CONFIG)" | $(TR) A-Z a-z)
137 export KERNEL_CONFIG_LC := $(shell printf "%s" "$(KERNEL_CONFIG)" | $(TR) A-Z a-z)
140 # Kernel Configuration to install
142 # supported install architecture : PPC I386 X86_64 ARM
144 export INSTALL_TYPE = $(DEFAULT_KERNEL_CONFIG)
147 export INSTALL_ARCHS = $(strip $(foreach my_config, $(SUPPORTED_ARCH_CONFIGS), $(findstring $(my_config), $(TARGET_CONFIGS_UC))))
148 export INSTALL_ARCHS_LC := $(shell printf "%s" "$(INSTALL_ARCHS)" | $(TR) A-Z a-z)
151 export INSTALL_ARCH_DEFAULT = $(firstword $(INSTALL_ARCHS))
154 # Standard defines list
156 export DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(IDENT)
165 # Compiler warning flags
169 -Wall -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \
170 -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
171 -Wshadow -Wcast-align -Wchar-subscripts -Winline \
172 -Wnested-externs -Wredundant-decls
174 export CWARNFLAGS ?= $(CWARNFLAGS_STD)
177 -Wall -Wno-format-y2k -W \
178 -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
179 -Wcast-align -Wchar-subscripts -Wredundant-decls
181 export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
185 # Setup for parallel sub-makes based on 2 times number of logical CPUs
188 export MAKEJOBS = --jobs=$(shell expr `/usr/sbin//sysctl -n hw.logicalcpu` \* 2)
192 # Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
194 ARCH_FLAGS_PPC = -arch ppc
195 ARCH_FLAGS_I386 = -arch i386
196 ARCH_FLAGS_X86_64 = -arch x86_64
197 ARCH_FLAGS_ARM = $($(addsuffix $(MACHINE_CONFIG),ARCH_FLAGS_ARM_))
199 ARCH_FLAGS_ALL_PPC = $(ARCH_FLAGS_PPC)
200 ARCH_FLAGS_ALL_I386 = $(ARCH_FLAGS_I386)
201 ARCH_FLAGS_ALL_X86_64 = $(ARCH_FLAGS_X86_64)
202 ARCH_FLAGS_ALL_ARM = -arch arm
209 export OTHER_CFLAGS = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS))
212 export DSYMBUILDDIR = ./Contents/Resources/DWARF/
215 # We must not use -fno-keep-inline-functions, or it will remove the dtrace
216 # probes from the kernel.
218 export CFLAGS_GEN = -static $(DEBUG_CFLAGS) -nostdinc -nostdlib \
219 -fno-builtin -finline -fno-common -msoft-float \
220 -fsigned-bitfields -fno-stack-protector $(OTHER_CFLAGS)
222 ifeq ($(BUILD_STABS),1)
223 export CFLAGS_GEN += -gstabs+
224 export BUILD_DWARF = 0
225 export BUILD_STABS = 1
227 export CFLAGS_GEN += -gdwarf-2
228 export BUILD_DWARF = 1
229 export BUILD_STABS = 0
232 export CFLAGS_RELEASE =
233 export CFLAGS_DEVELOPMENT =
234 export CFLAGS_DEBUG =
235 export CFLAGS_PROFILE = -pg
237 export CFLAGS_PPC = -Dppc -DPPC -D__PPC__ -DPAGE_SIZE_FIXED \
238 -mno-altivec -force_cpusubtype_ALL
239 export CFLAGS_I386 = -Di386 -DI386 -D__I386__ \
240 -DPAGE_SIZE_FIXED -force_cpusubtype_ALL
241 export CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
242 -DPAGE_SIZE_FIXED -mkernel
243 export CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \
244 -fno-strict-aliasing -fno-keep-inline-functions
246 ifeq (-arch armv7,$(ARCH_FLAGS_ARM))
247 CFLAGS_ARM += -mthumb
249 ifeq (-arch armv6,$(ARCH_FLAGS_ARM))
250 CFLAGS_ARM += -mthumb
252 ifeq (-arch armv5,$(ARCH_FLAGS_ARM))
253 CFLAGS_ARM += -mno-thumb
255 ifeq (-arch xscale,$(ARCH_FLAGS_ARM))
256 CFLAGS_ARM += -mthumb
259 export CFLAGS_RELEASEPPC = -O2 -mcpu=750 -mmultiple
260 export CFLAGS_DEVELOPMENTPPC = -O2 -mcpu=750 -mmultiple
261 export CFLAGS_DEBUGPPC = -O2 -mcpu=750 -mmultiple
262 export CFLAGS_PROFILEPPC = -O2 -mcpu=750 -mmultiple
264 export CFLAGS_RELEASEI386 = -Os
265 export CFLAGS_DEVELOPMENTI386 = -Os
266 export CFLAGS_DEBUGI386 = -Os
267 export CFLAGS_PROFILEI386 = -Os
269 export CFLAGS_RELEASEX86_64 = -Os
270 export CFLAGS_DEVELOPMENTX86_64 = -Os
271 # No space optimization for the DEBUG kernel for the benefit of gdb:
272 export CFLAGS_DEBUGX86_64 = -O0
273 export CFLAGS_PROFILEX86_64 = -Os
275 export CFLAGS_RELEASEARM = -O2
276 export CFLAGS_DEVELOPMENTARM = -O2
277 export CFLAGS_DEBUGARM = -O2
278 export CFLAGS_PROFILEARM = -O2
280 export CFLAGS = $(CFLAGS_GEN) \
281 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
282 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
283 $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \
284 $($(addsuffix $(KERNEL_CONFIG),CFLAGS_)) \
285 $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),CFLAGS_))) \
290 CXXFLAGS_GEN = -fno-rtti -fno-exceptions -fcheck-new -fapple-kext
292 CXXFLAGS = $(CXXFLAGS_GEN) \
293 $($(addsuffix $(ARCH_CONFIG),CXXFLAGS_)) \
294 $($(addsuffix $(KERNEL_CONFIG),CXXFLAGS_))
305 export SFLAGS_GEN = -static -D__ASSEMBLER__ $(OTHER_CFLAGS)
307 export SFLAGS_RELEASE =
308 export SFLAGS_DEVELOPMENT =
309 export SFLAGS_DEBUG =
310 export SFLAGS_PROFILE =
312 export SFLAGS_PPC = $(CFLAGS_PPC) -force_cpusubtype_ALL
313 export SFLAGS_I386 = $(CFLAGS_I386)
314 export SFLAGS_ARM = $(CFLAGS_ARM)
315 export SFLAGS_X86_64 = $(CFLAGS_X86_64)
317 export SFLAGS = $(SFLAGS_GEN) \
318 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
319 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
320 $($(addsuffix $(ARCH_CONFIG),SFLAGS_)) \
321 $($(addsuffix $(KERNEL_CONFIG),SFLAGS_)) \
327 LD = $(KC++) -nostdlib
333 export LDFLAGS_KERNEL_GEN = \
337 -Wl,-sectalign,__TEXT,__text,0x1000 \
338 -Wl,-sectalign,__DATA,__common,0x1000 \
339 -Wl,-sectalign,__DATA,__bss,0x1000 \
340 -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
341 -Wl,-sectcreate,__PRELINK_STATE,__kernel,/dev/null \
342 -Wl,-sectcreate,__PRELINK_STATE,__kexts,/dev/null \
343 -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null
345 # Availability of DWARF allows DTrace CTF (compressed type format) to be constructed
346 ifeq ($(BUILD_DWARF),1)
347 export LDFLAGS_KERNEL_GEN += \
348 -Wl,-sectcreate,__CTF,__ctf,/dev/null
351 export LDFLAGS_KERNEL_RELEASE =
352 export LDFLAGS_KERNEL_DEVELOPMENT =
353 export LDFLAGS_KERNEL_DEBUG =
354 export LDFLAGS_KERNEL_PROFILE =
356 export LDFLAGS_KERNEL_PPC = \
357 -force_cpusubtype_ALL \
359 -Wl,-pagezero_size,0x0 \
360 -Wl,-segaddr,__VECTORS,0x0 \
361 -Wl,-segaddr,__HIB,0x7000 \
362 -Wl,-segaddr,__TEXT,0xe000
364 export LDFLAGS_KERNEL_RELEASEI386 = \
366 -Wl,-pagezero_size,0x0 \
367 -Wl,-segaddr,__INITPT,0x00100000 \
368 -Wl,-segaddr,__INITGDT,0x00106000 \
369 -Wl,-segaddr,__SLEEP,0x00107000 \
370 -Wl,-segaddr,__HIB,0x00108000 \
371 -Wl,-image_base,0x200000 \
372 -Wl,-seg_page_size,__TEXT,0x200000
374 export LDFLAGS_KERNEL_DEBUGI386 = $(LDFLAGS_KERNEL_RELEASEI386)
375 export LDFLAGS_KERNEL_DEVELOPMENTI386 = $(LDFLAGS_KERNEL_RELEASEI386)
376 export LDFLAGS_KERNEL_PROFILEI386 = $(LDFLAGS_KERNEL_RELEASEI386)
378 # Keep these constants in sync with the *_SEG_BASE definitions in i386/pmap.h
379 export LDFLAGS_KERNEL_RELEASEX86_64 = \
381 -Wl,-pagezero_size,0x0 \
382 -Wl,-segaddr,__INITPT,0xffffff8000100000 \
383 -Wl,-segaddr,__INITGDT,0xffffff8000106000 \
384 -Wl,-segaddr,__SLEEP,0xffffff8000107000 \
385 -Wl,-segaddr,__HIB,0xffffff8000108000 \
386 -Wl,-image_base,0xffffff8000200000 \
387 -Wl,-seg_page_size,__TEXT,0x200000
389 export LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
390 export LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
391 export LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
393 export LDFLAGS_KERNEL_RELEASEARM = \
395 -Wl,-pagezero_size,0x0 \
396 -Wl,-image_base,0xC0001000 \
397 -Wl,-exported_symbols_list,$(TARGET)/kernel-kpi.exp
399 export LDFLAGS_KERNEL_DEVELOPMENTARM = \
401 -Wl,-pagezero_size,0x0 \
402 -Wl,-image_base,0xC0001000
404 export LDFLAGS_KERNEL_DEBUGARM = $(LDFLAGS_KERNEL_DEVELOPMENTARM)
407 export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
408 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
409 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
410 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \
411 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
412 $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
416 # Default runtime libraries to be linked with the kernel
418 export LD_KERNEL_LIBS = -lcc_kext
421 # Command to generate host binaries. Intentionally not
422 # $(CC), which controls the target compiler
429 export INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
430 export INCFLAGS_EXTERN = -I$(OBJROOT)/EXTERN_HDRS -I$(SRCROOT)/EXTERNAL_HEADERS -I$(SRCROOT)/EXTERNAL_HEADERS/bsd
431 export INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
432 export INCFLAGS_POSIX = -I$(OBJROOT)/EXPORT_HDRS/bsd
433 export INCFLAGS_LOCAL = -I.
435 export INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE)
440 export MIGFLAGS = $(DEFINES) $(INCFLAGS) $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_))
446 space:= $(empty) $(empty)
447 export VPATH_IMPORT = $(subst $(space),:,$(patsubst %,$(OBJROOT)/EXPORT_HDRS/%,$(strip $(COMPONENT_IMPORT_LIST)))):
448 export VPATH_EXTERN = $(OBJROOT)/EXTERN_HDRS:
449 export VPATH_GEN = .:$(SOURCE):
451 export VPATH = $(VPATH_GEN)$(VPATH_IMPORT)$(VPATH_EXTERN)$(VPATH_MAKEFILE)
454 # Macros that control installation of kernel and its header files
456 # install flags for header files
458 INSTALL_FLAGS = -c -m 0444
459 FILE_INSTALL_FLAGS = -c -m 0644
460 DATA_INSTALL_FLAGS = -c -m 0644
463 # Header file destinations
465 FRAMEDIR = System/Library/Frameworks
467 INCDIR = /usr/include
470 LCLDIR = $(FRAMEDIR)/System.framework/Versions/B/PrivateHeaders
474 KINCFRAME = $(FRAMEDIR)/Kernel.framework
475 KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
476 KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
477 KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
479 XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
481 SPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_
482 SINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_
483 KPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_
484 KINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_
488 # Compononent Header file destinations
490 EXPDIR = EXPORT_HDRS/$(COMPONENT)
495 export STRIP_FLAGS_RELEASE = -S -x
496 export STRIP_FLAGS_DEVELOPMENT = -S -x
497 export STRIP_FLAGS_DEBUG = -S
498 export STRIP_FLAGS_PROFILE = -S -x
500 export STRIP_FLAGS = $($(addsuffix $(KERNEL_CONFIG),STRIP_FLAGS_))
505 export DSYMUTIL_FLAGS_I386 = --arch=i386
506 export DSYMUTIL_FLAGS_X86_64 = --arch=x86_64
507 export DSYMUTIL_FLAGS_PPC = --arch=ppc
508 export DSYMUTIL_FLAGS_ARM = --arch=arm
510 export DSYMUTIL_FLAGS = $($(addsuffix $(ARCH_CONFIG),DSYMUTIL_FLAGS_))
513 # Man Page destination
515 MANDIR = usr/share/man
518 # DEBUG alias location
520 DEVELOPER_EXTRAS_DIR = AppleInternal/Developer/Extras
523 # This must be here before any rules are possibly defined by the
524 # machine dependent makefile fragment so that a plain "make" command
525 # always works. The config program will emit an appropriate rule to
526 # cause "all" to depend on every kernel configuration it generates.