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
23 export COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security
24 export COMPONENT_LIST_UC := $(shell printf "%s" "$(COMPONENT_LIST)" | $(TR) a-z A-Z)
27 export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
28 export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST))
30 ifeq ($(COMPONENT), .)
31 export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE))))
32 export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST))
36 # Architecture options
38 ifndef SUPPORTED_ARCH_CONFIGS
39 export SUPPORTED_ARCH_CONFIGS = PPC I386 ARM
44 export ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z)
46 export ARCH_CONFIGS := $(shell arch | $(TR) a-z A-Z)
51 export ARCH_CONFIG_LC := $(shell printf "%s" "$(ARCH_CONFIG)" | $(TR) A-Z a-z)
56 # Kernel Configuration options
58 ifndef SUPPORTED_KERNEL_CONFIGS
59 export SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE
62 ifndef DEFAULT_KERNEL_CONFIG
63 export DEFAULT_KERNEL_CONFIG = RELEASE
66 # If KERNEL_CONFIGS is specified it should override KERNEL_CONFIG.
67 # If KERNEL_CONFIG is specified it will override the default. Will quit with
68 # error if more than one config is specified.
69 # If DEFAULT_KERNEL_CONFIG is not specified then it will be built RELEASE.
72 export KERNEL_CONFIGS = $(DEFAULT_KERNEL_CONFIG)
74 export KERNEL_CONFIGS = $(KERNEL_CONFIG)
79 export KERNEL_CONFIG = $(firstword $(KERNEL_CONFIGS))
82 ifneq ($(words $(KERNEL_CONFIG)), 1)
83 $(error There were $(words $(KERNEL_CONFIG)) parameters passed to KERNEL_CONFIG = $(KERNEL_CONFG). \
84 Are you sure? To specify multiple configurations please use KERNEL_CONFIGS)
88 export MACHINE_CONFIG = DEFAULT
93 # Target configuration options. NOTE - target configurations will
94 # override ARCH_CONFIGS and KERNEL_CONFIGS.
96 # Target configs come in groups of three parameters. The first is the
97 # kernel configuration, the second is the architecture configuration,
98 # and the third is the machine configuration. You may pass in as
99 # many groups of configurations as you wish. Each item passed in is
100 # seperated by whitespace.
103 # TARGET_CONFIGS="release ppc default debug i386 default release arm MX31ADS"
104 # Parameters may be in upper or lower case (they are converted to upper).
106 # "default" parameter is a special case. It means use the default value for
107 # that parameter. Here are the default values for each configuration:
109 # default kernel configuration = DEFAULT_KERNEL_CONFIG
110 # default architecture configuration = system architecture where you are running make.
111 # default machine configuration for ppc = none at this time.
112 # default machine configuration for i386 = none at this time.
113 # default machine configuration for arm = "S5L8900X".
115 ifndef TARGET_CONFIGS_UC
117 export TARGET_CONFIGS_UC = $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z))
118 export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC))
119 export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC))
121 # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIG (which defaults to "DEFAULT")
122 temp_list = $(foreach my_kern_config, $(KERNEL_CONFIGS), $(my_kern_config) arch_slot $(MACHINE_CONFIG))
123 export TARGET_CONFIGS = $(strip $(foreach my_arch_config, $(ARCH_CONFIGS), $(subst arch_slot,$(my_arch_config),$(temp_list))))
124 export TARGET_CONFIGS_UC := $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z)
125 export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC))
126 export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC))
130 export MACHINE_CONFIG_LC := $(shell printf "%s" "$(MACHINE_CONFIG)" | $(TR) A-Z a-z)
131 export KERNEL_CONFIG_LC := $(shell printf "%s" "$(KERNEL_CONFIG)" | $(TR) A-Z a-z)
134 # Kernel Configuration to install
136 # supported install architecture : PPC I386 ARM
138 export INSTALL_TYPE = $(DEFAULT_KERNEL_CONFIG)
141 export INSTALL_ARCHS = $(strip $(foreach my_config, $(SUPPORTED_ARCH_CONFIGS), $(findstring $(my_config), $(TARGET_CONFIGS_UC))))
142 export INSTALL_ARCHS_LC := $(shell printf "%s" "$(INSTALL_ARCHS)" | $(TR) A-Z a-z)
145 export INSTALL_ARCH_DEFAULT = PPC
148 # Standard defines list
150 export DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(IDENT)
159 # Compiler warning flags
163 -Wall -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \
164 -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
165 -Wshadow -Wcast-align -Wbad-function-cast -Wchar-subscripts -Winline \
166 -Wnested-externs -Wredundant-decls
168 export CWARNFLAGS ?= $(CWARNFLAGS_STD)
171 -Wall -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes \
172 -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
173 -Wshadow -Wcast-align -Wbad-function-cast -Wchar-subscripts -Winline \
174 -Wnested-externs -Wredundant-decls
176 export MWARNFLAGS ?= $(MWARNFLAGS_STD)
179 -Wall -Wno-format-y2k -W \
180 -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch \
181 -Wshadow -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls
183 export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
187 # Setup for parallel sub-makes based on 2 times number of logical CPUs
190 export MAKEJOBS = --jobs=$(shell expr `/usr/sbin//sysctl -n hw.logicalcpu` \* 2)
194 # Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
196 ARCH_FLAGS_PPC = -arch ppc
197 ARCH_FLAGS_I386 = -arch i386
198 ARCH_FLAGS_ARM = $($(addsuffix $(MACHINE_CONFIG),ARCH_FLAGS_ARM_))
205 export OTHER_CFLAGS = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS))
208 export DSYMBUILDDIR = ./Contents/Resources/DWARF/
211 # We must not use -fno-keep-inline-functions, or it will remove the dtrace
212 # probes from the kernel.
214 export CFLAGS_GEN = -static $(DEBUG_CFLAGS) -nostdinc -nostdlib \
215 -fno-builtin -finline -msoft-float \
216 -fsigned-bitfields $(OTHER_CFLAGS)
218 export CFLAGS_RELEASE =
219 export CFLAGS_DEVELOPMENT =
220 export CFLAGS_DEBUG =
221 export CFLAGS_PROFILE = -pg
223 ifeq ($(BUILD_STABS),1)
224 export CFLAGS_PPC = -Dppc -DPPC -D__PPC__ -DPAGE_SIZE_FIXED \
225 -mno-altivec -gstabs+ -force_cpusubtype_ALL
226 export CFLAGS_I386 = -Di386 -DI386 -D__I386__ \
227 -DPAGE_SIZE_FIXED -gstabs+ -force_cpusubtype_ALL
228 export CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \
229 -fno-strict-aliasing -gstabs+ -fno-keep-inline-functions
230 export BUILD_DWARF = 0
231 export BUILD_STABS = 1
233 export CFLAGS_PPC = -Dppc -DPPC -D__PPC__ -DPAGE_SIZE_FIXED \
234 -mno-altivec -gdwarf-2 -force_cpusubtype_ALL
235 export CFLAGS_I386 = -Di386 -DI386 -D__I386__ \
236 -DPAGE_SIZE_FIXED -gdwarf-2 -force_cpusubtype_ALL
237 export CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \
238 -fno-strict-aliasing -gdwarf-2 -fno-keep-inline-functions
239 export BUILD_DWARF = 1
240 export BUILD_STABS = 0
242 ifeq (-arch armv6,$(ARCH_FLAGS_ARM))
243 CFLAGS_ARM += -mthumb
245 ifeq (-arch armv5,$(ARCH_FLAGS_ARM))
246 CFLAGS_ARM += -mthumb
248 ifeq (-arch xscale,$(ARCH_FLAGS_ARM))
249 CFLAGS_ARM += -mthumb
252 export CFLAGS_RELEASEPPC = -O2 -mcpu=750 -mmultiple
253 export CFLAGS_RELEASE_TRACEPPC = -O2 -mcpu=750 -mmultiple
254 export CFLAGS_DEVELOPMENTPPC = -O2 -mcpu=750 -mmultiple
255 export CFLAGS_DEBUGPPC = -O2 -mcpu=750 -mmultiple
256 export CFLAGS_PROFILEPPC = -O2 -mcpu=750 -mmultiple
258 export CFLAGS_RELEASEI386 = -Os
259 export CFLAGS_DEVELOPMENTI386 = -Os
260 export CFLAGS_DEBUGI386 = -Os
261 export CFLAGS_PROFILEI386 = -Os
263 export CFLAGS_RELEASEARM = -O2
264 export CFLAGS_DEVELOPMENTARM = -O2
265 export CFLAGS_DEBUGARM = -O2
266 export CFLAGS_PROFILEARM = -O2
268 export CFLAGS = $(CFLAGS_GEN) \
269 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
270 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
271 $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \
272 $($(addsuffix $(KERNEL_CONFIG),CFLAGS_)) \
273 $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),CFLAGS_))) \
280 CXXFLAGS_GEN = -fno-rtti -fno-exceptions -fcheck-new -fapple-kext
282 CXXFLAGS = $(CXXFLAGS_GEN) \
283 $($(addsuffix $(ARCH_CONFIG),CXXFLAGS_)) \
284 $($(addsuffix $(KERNEL_CONFIG),CXXFLAGS_))
295 export SFLAGS_GEN = -static -D__ASSEMBLER__ $(OTHER_CFLAGS)
297 export SFLAGS_RELEASE =
298 export SFLAGS_DEVELOPMENT =
299 export SFLAGS_DEBUG =
300 export SFLAGS_PROFILE =
302 export SFLAGS_PPC = $(CFLAGS_PPC) -force_cpusubtype_ALL
303 export SFLAGS_I386 = $(CFLAGS_I386)
304 export SFLAGS_ARM = $(CFLAGS_ARM)
306 export SFLAGS = $(SFLAGS_GEN) \
307 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
308 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
309 $($(addsuffix $(ARCH_CONFIG),SFLAGS_)) \
310 $($(addsuffix $(KERNEL_CONFIG),SFLAGS_)) \
316 LD = $(KC++) -nostdlib
321 export LDFLAGS_COMPONENT_GEN = -static -r $(COMP_LDFLAGS_COMPONENT_GEN)
323 export LDFLAGS_COMPONENT_RELEASE = $(COMP_LDFLAGS_COMPONENT_RELEASE)
324 export LDFLAGS_COMPONENT_DEVELOPMENT = $(COMP_LDFLAGS_COMPONENT_DEVELOPMENT)
325 export LDFLAGS_COMPONENT_DEBUG = $(COMP_LDFLAGS_COMPONENT_DEBUG)
326 export LDFLAGS_COMPONENT_PROFILE = $(COMP_LDFLAGS_COMPONENT_PROFILE)
328 export LDFLAGS_COMPONENT_PPC = $(COMP_LDFLAGS_COMPONENT_PPC) -force_cpusubtype_ALL
329 export LDFLAGS_COMPONENT_I386 = $(COMP_LDFLAGS_COMPONENT_i386)
330 export LDFLAGS_COMPONENT_ARM = $(COMP_LDFLAGS_COMPONENT_ARM)
332 export LDFLAGS_COMPONENT = $(LDFLAGS_COMPONENT_GEN) \
333 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
334 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_COMPONENT_)) \
335 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_COMPONENT_))
337 export LDFLAGS_KERNEL_GEN = \
341 -Wl,-sectalign,__TEXT,__text,0x1000 \
342 -Wl,-sectalign,__DATA,__common,0x1000 \
343 -Wl,-sectalign,__DATA,__bss,0x1000 \
344 -Wl,-sectcreate,__PRELINK,__text,/dev/null \
345 -Wl,-sectcreate,__PRELINK,__symtab,/dev/null \
346 -Wl,-sectcreate,__PRELINK,__info,/dev/null
348 export LDFLAGS_KERNEL_RELEASE =
349 export LDFLAGS_KERNEL_DEVELOPMENT =
351 export LDFLAGS_KERNEL_DEBUG =
352 export LDFLAGS_KERNEL_PROFILE =
354 export LDFLAGS_KERNEL_PPC = \
355 -force_cpusubtype_ALL \
357 -Wl,-segaddr,__VECTORS,0x0 \
358 -Wl,-segaddr,__HIB,0x7000 \
359 -Wl,-segaddr,__TEXT,0xe000
361 export LDFLAGS_KERNEL_I386 = \
363 -Wl,-segaddr,__HIB,0x100000 \
364 -Wl,-segaddr,__TEXT,0x111000
366 export LDFLAGS_KERNEL_ARM = \
367 -Wl,-segaddr,__HIB,0xC0000000 \
368 -Wl,-segaddr,__TEXT,0xC0008000
370 export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
371 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \
372 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \
373 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \
374 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))
378 # Default runtime libraries to be linked with the kernel
380 export LD_KERNEL_LIBS = -lcc_kext
385 export INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
386 export INCFLAGS_EXTERN = -I$(OBJROOT)/EXTERN_HDRS -I$(SRCROOT)/EXTERNAL_HEADERS -I$(SRCROOT)/EXTERNAL_HEADERS/bsd
387 export INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
388 export INCFLAGS_POSIX = -I$(OBJROOT)/EXPORT_HDRS/bsd
389 export INCFLAGS_LOCAL = -I.
391 export INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE)
396 export MIGFLAGS = $(DEFINES) $(INCFLAGS) $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_))
402 space:= $(empty) $(empty)
403 export VPATH_IMPORT = $(subst $(space),:,$(patsubst %,$(OBJROOT)/EXPORT_HDRS/%,$(strip $(COMPONENT_IMPORT_LIST)))):
404 export VPATH_EXTERN = $(OBJROOT)/EXTERN_HDRS:
405 export VPATH_GEN = .:$(SOURCE):
407 export VPATH = $(VPATH_GEN)$(VPATH_IMPORT)$(VPATH_EXTERN)$(VPATH_MAKEFILE)
410 # Macros that control installation of kernel and its header files
412 # install flags for header files
414 INSTALL_FLAGS = -c -m 0444
415 FILE_INSTALL_FLAGS = -c -m 0644
416 DATA_INSTALL_FLAGS = -c -m 0644
419 # Header file destinations
421 FRAMEDIR = System/Library/Frameworks
423 INCDIR = /usr/include
426 LCLDIR = $(FRAMEDIR)/System.framework/Versions/B/PrivateHeaders
430 KINCFRAME = $(FRAMEDIR)/Kernel.framework
431 KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
432 KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
433 KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
435 XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
437 SPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_
438 SINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_
439 KPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_
440 KINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_
443 # Compononent Header file destinations
445 EXPDIR = EXPORT_HDRS/$(COMPONENT)
450 export STRIP_FLAGS_RELEASE = -S -x
451 export STRIP_FLAGS_DEVELOPMENT = -S -x
452 export STRIP_FLAGS_RELEASE_TRACE = -S -x
453 export STRIP_FLAGS_DEBUG = -S
454 export STRIP_FLAGS_DEBUG_TRACE = -S
455 export STRIP_FLAGS_PROFILE = -S -x
457 export STRIP_FLAGS = $($(addsuffix $(KERNEL_CONFIG),STRIP_FLAGS_))
462 export DSYMUTIL_FLAGS_I386 = --arch=i386
463 export DSYMUTIL_FLAGS_PPC = --arch=ppc
464 export DSYMUTIL_FLAGS_ARM = --arch=arm
466 export DSYMUTIL_FLAGS = $($(addsuffix $(ARCH_CONFIG),DSYMUTIL_FLAGS_))
469 # Man Page destination
471 MANDIR = usr/share/man
482 ifeq ($(VERBOSE),YES)
489 # This must be here before any rules are possibly defined by the
490 # machine dependent makefile fragment so that a plain "make" command
491 # always works. The config program will emit an appropriate rule to
492 # cause "all" to depend on every kernel configuration it generates.