1export SOURCE=$(shell /bin/pwd) 2 3# 4# gnumake 3.77 support 5# 6export USE_APPLE_PB_SUPPORT = all 7 8# 9# Incremental Build option 10# 11ifndef INCR_EXPORTHDRS 12ifeq ($(shell test -d $$OBJROOT/EXPORT_HDRS;echo $$?),0) 13export INCR_EXPORTHDRS = TRUE 14else 15export INCR_EXPORTHDRS = FALSE 16endif 17endif 18 19# 20# Component List 21# 22ifndef COMPONENT_LIST 23export COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security 24export COMPONENT_LIST_UC := $(shell printf "%s" "$(COMPONENT_LIST)" | $(TR) a-z A-Z) 25endif 26ifndef COMPONENT 27export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE)))) 28export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) 29else 30ifeq ($(COMPONENT), .) 31export COMPONENT := $(firstword $(subst /, ,$(shell $(RELPATH) $(SRCROOT) $(SOURCE)))) 32export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) 33endif 34endif 35 36# Architecture options 37# 38ifndef SUPPORTED_ARCH_CONFIGS 39export SUPPORTED_ARCH_CONFIGS = PPC I386 ARM 40endif 41 42ifndef ARCH_CONFIGS 43ifdef RC_ARCHS 44export ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z) 45else 46export ARCH_CONFIGS := $(shell arch | $(TR) a-z A-Z) 47endif 48endif 49ifdef ARCH_CONFIG 50ifndef ARCH_CONFIG_LC 51export ARCH_CONFIG_LC := $(shell printf "%s" "$(ARCH_CONFIG)" | $(TR) A-Z a-z) 52endif 53endif 54 55# 56# Kernel Configuration options 57# 58ifndef SUPPORTED_KERNEL_CONFIGS 59export SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE 60endif 61 62ifndef DEFAULT_KERNEL_CONFIG 63export DEFAULT_KERNEL_CONFIG = RELEASE 64endif 65 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. 70ifndef KERNEL_CONFIGS 71 ifndef KERNEL_CONFIG 72 export KERNEL_CONFIGS = $(DEFAULT_KERNEL_CONFIG) 73 else 74 export KERNEL_CONFIGS = $(KERNEL_CONFIG) 75 endif 76endif 77 78ifndef KERNEL_CONFIG 79export KERNEL_CONFIG = $(firstword $(KERNEL_CONFIGS)) 80endif 81 82ifneq ($(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) 85endif 86 87ifndef MACHINE_CONFIG 88export MACHINE_CONFIG = DEFAULT 89endif 90 91 92# 93# Target configuration options. NOTE - target configurations will 94# override ARCH_CONFIGS and KERNEL_CONFIGS. 95# 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. 101# 102# Example: 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). 105# 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: 108# 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". 114# 115ifndef TARGET_CONFIGS_UC 116ifdef TARGET_CONFIGS 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)) 120else 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)) 127endif 128endif 129 130export MACHINE_CONFIG_LC := $(shell printf "%s" "$(MACHINE_CONFIG)" | $(TR) A-Z a-z) 131export KERNEL_CONFIG_LC := $(shell printf "%s" "$(KERNEL_CONFIG)" | $(TR) A-Z a-z) 132 133# 134# Kernel Configuration to install 135# 136# supported install architecture : PPC I386 ARM 137# 138export INSTALL_TYPE = $(DEFAULT_KERNEL_CONFIG) 139 140ifndef INSTALL_ARCHS 141export INSTALL_ARCHS = $(strip $(foreach my_config, $(SUPPORTED_ARCH_CONFIGS), $(findstring $(my_config), $(TARGET_CONFIGS_UC)))) 142export INSTALL_ARCHS_LC := $(shell printf "%s" "$(INSTALL_ARCHS)" | $(TR) A-Z a-z) 143endif 144 145export INSTALL_ARCH_DEFAULT = PPC 146 147# 148# Standard defines list 149# 150export DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(IDENT) 151 152# 153# Compiler command 154# 155KCC := $(CC) 156KC++ := $(CXX) 157 158# 159# Compiler warning flags 160# 161 162CWARNFLAGS_STD = \ 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 167 168export CWARNFLAGS ?= $(CWARNFLAGS_STD) 169 170MWARNFLAGS_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 175 176export MWARNFLAGS ?= $(MWARNFLAGS_STD) 177 178CXXWARNFLAGS_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 182 183export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD) 184 185 186# 187# Setup for parallel sub-makes based on 2 times number of logical CPUs 188# 189ifndef MAKEJOBS 190export MAKEJOBS = --jobs=$(shell expr `/usr/sbin//sysctl -n hw.logicalcpu` \* 2) 191endif 192 193# 194# Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers 195 196ARCH_FLAGS_PPC = -arch ppc 197ARCH_FLAGS_I386 = -arch i386 198ARCH_FLAGS_ARM = $($(addsuffix $(MACHINE_CONFIG),ARCH_FLAGS_ARM_)) 199 200ARCH_FLAGS_ALL_PPC = $(ARCH_FLAGS_PPC) 201ARCH_FLAGS_ALL_I386 = $(ARCH_FLAGS_I386) 202ARCH_FLAGS_ALL_ARM = -arch arm 203 204 205# 206# Default CFLAGS 207# 208ifdef RC_CFLAGS 209export OTHER_CFLAGS = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS)) 210endif 211 212export DSYMBUILDDIR = ./Contents/Resources/DWARF/ 213 214# 215# We must not use -fno-keep-inline-functions, or it will remove the dtrace 216# probes from the kernel. 217# 218export CFLAGS_GEN = -static $(DEBUG_CFLAGS) -nostdinc -nostdlib \ 219 -fno-builtin -finline -msoft-float \ 220 -fsigned-bitfields $(OTHER_CFLAGS) 221 222ifeq ($(BUILD_STABS),1) 223export CFLAGS_GEN += -gstabs+ 224export BUILD_DWARF = 0 225export BUILD_STABS = 1 226else 227export CFLAGS_GEN += -gdwarf-2 228export BUILD_DWARF = 1 229export BUILD_STABS = 0 230endif 231 232export CFLAGS_RELEASE = 233export CFLAGS_DEVELOPMENT = 234export CFLAGS_DEBUG = 235export CFLAGS_PROFILE = -pg 236 237export CFLAGS_PPC = -Dppc -DPPC -D__PPC__ -DPAGE_SIZE_FIXED \ 238 -mno-altivec -force_cpusubtype_ALL 239export CFLAGS_I386 = -Di386 -DI386 -D__I386__ \ 240 -DPAGE_SIZE_FIXED -force_cpusubtype_ALL 241export CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \ 242 -fno-strict-aliasing -fno-keep-inline-functions 243 244ifeq (-arch armv7,$(ARCH_FLAGS_ARM)) 245CFLAGS_ARM += -mthumb 246endif 247ifeq (-arch armv6,$(ARCH_FLAGS_ARM)) 248CFLAGS_ARM += -mthumb 249endif 250ifeq (-arch armv5,$(ARCH_FLAGS_ARM)) 251#CFLAGS_ARM += -mthumb # <rdar://problem/6174175> 252endif 253ifeq (-arch xscale,$(ARCH_FLAGS_ARM)) 254CFLAGS_ARM += -mthumb 255endif 256 257export CFLAGS_RELEASEPPC = -O2 -mcpu=750 -mmultiple 258export CFLAGS_RELEASE_TRACEPPC = -O2 -mcpu=750 -mmultiple 259export CFLAGS_DEVELOPMENTPPC = -O2 -mcpu=750 -mmultiple 260export CFLAGS_DEBUGPPC = -O2 -mcpu=750 -mmultiple 261export CFLAGS_PROFILEPPC = -O2 -mcpu=750 -mmultiple 262 263export CFLAGS_RELEASEI386 = -Os 264export CFLAGS_DEVELOPMENTI386 = -Os 265export CFLAGS_DEBUGI386 = -Os 266export CFLAGS_PROFILEI386 = -Os 267 268export CFLAGS_RELEASEARM = -O2 269export CFLAGS_DEVELOPMENTARM = -O2 270export CFLAGS_DEBUGARM = -O2 271export CFLAGS_PROFILEARM = -O2 272 273export CFLAGS = $(CFLAGS_GEN) \ 274 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ 275 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ 276 $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \ 277 $($(addsuffix $(KERNEL_CONFIG),CFLAGS_)) \ 278 $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),CFLAGS_))) \ 279 $(DEFINES) 280 281export MIGCC = $(CC) 282 283# Default C++ flags 284# 285CXXFLAGS_GEN = -fno-rtti -fno-exceptions -fcheck-new -fapple-kext 286 287CXXFLAGS = $(CXXFLAGS_GEN) \ 288 $($(addsuffix $(ARCH_CONFIG),CXXFLAGS_)) \ 289 $($(addsuffix $(KERNEL_CONFIG),CXXFLAGS_)) 290 291# 292# Assembler command 293# 294AS = $(CC) 295S_KCC = $(CC) 296 297# 298# Default SFLAGS 299# 300export SFLAGS_GEN = -static -D__ASSEMBLER__ $(OTHER_CFLAGS) 301 302export SFLAGS_RELEASE = 303export SFLAGS_DEVELOPMENT = 304export SFLAGS_DEBUG = 305export SFLAGS_PROFILE = 306 307export SFLAGS_PPC = $(CFLAGS_PPC) -force_cpusubtype_ALL 308export SFLAGS_I386 = $(CFLAGS_I386) 309export SFLAGS_ARM = $(CFLAGS_ARM) 310 311export SFLAGS = $(SFLAGS_GEN) \ 312 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ 313 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ 314 $($(addsuffix $(ARCH_CONFIG),SFLAGS_)) \ 315 $($(addsuffix $(KERNEL_CONFIG),SFLAGS_)) \ 316 $(DEFINES) 317 318# 319# Linker command 320# 321LD = $(KC++) -nostdlib 322 323# 324# Default LDFLAGS 325# 326export LDFLAGS_COMPONENT_GEN = -static -r $(COMP_LDFLAGS_COMPONENT_GEN) 327 328export LDFLAGS_COMPONENT_RELEASE = $(COMP_LDFLAGS_COMPONENT_RELEASE) 329export LDFLAGS_COMPONENT_DEVELOPMENT = $(COMP_LDFLAGS_COMPONENT_DEVELOPMENT) 330export LDFLAGS_COMPONENT_DEBUG = $(COMP_LDFLAGS_COMPONENT_DEBUG) 331export LDFLAGS_COMPONENT_PROFILE = $(COMP_LDFLAGS_COMPONENT_PROFILE) 332 333export LDFLAGS_COMPONENT_PPC = $(COMP_LDFLAGS_COMPONENT_PPC) -force_cpusubtype_ALL 334export LDFLAGS_COMPONENT_I386 = $(COMP_LDFLAGS_COMPONENT_i386) 335export LDFLAGS_COMPONENT_ARM = $(COMP_LDFLAGS_COMPONENT_ARM) -Wl,-new_linker 336 337export LDFLAGS_COMPONENT = $(LDFLAGS_COMPONENT_GEN) \ 338 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ 339 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_COMPONENT_)) \ 340 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_COMPONENT_)) 341 342export LDFLAGS_KERNEL_GEN = \ 343 -static \ 344 -fapple-kext \ 345 -Wl,-e,__start \ 346 -Wl,-sectalign,__TEXT,__text,0x1000 \ 347 -Wl,-sectalign,__DATA,__common,0x1000 \ 348 -Wl,-sectalign,__DATA,__bss,0x1000 \ 349 -Wl,-sectcreate,__PRELINK,__text,/dev/null \ 350 -Wl,-sectcreate,__PRELINK,__symtab,/dev/null \ 351 -Wl,-sectcreate,__PRELINK,__info,/dev/null 352 353export LDFLAGS_KERNEL_RELEASE = 354export LDFLAGS_KERNEL_DEVELOPMENT = 355# -noseglinkedit 356export LDFLAGS_KERNEL_DEBUG = 357export LDFLAGS_KERNEL_PROFILE = 358 359export LDFLAGS_KERNEL_PPC = \ 360 -force_cpusubtype_ALL \ 361 -Wl,-new_linker \ 362 -Wl,-segaddr,__VECTORS,0x0 \ 363 -Wl,-segaddr,__HIB,0x7000 \ 364 -Wl,-segaddr,__TEXT,0xe000 365 366export LDFLAGS_KERNEL_I386 = \ 367 -Wl,-new_linker \ 368 -Wl,-segaddr,__HIB,0x100000 \ 369 -Wl,-segaddr,__TEXT,0x111000 370 371export LDFLAGS_KERNEL_ARM = \ 372 -Wl,-new_linker \ 373 -Wl,-segaddr,__HIB,0xC0000000 \ 374 -Wl,-segaddr,__TEXT,0xC0008000 375 376export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \ 377 $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ 378 $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ 379 $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \ 380 $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_)) 381 382 383# 384# Default runtime libraries to be linked with the kernel 385# 386export LD_KERNEL_LIBS = -lcc_kext 387 388# 389# Default INCFLAGS 390# 391export INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST)) 392export INCFLAGS_EXTERN = -I$(OBJROOT)/EXTERN_HDRS -I$(SRCROOT)/EXTERNAL_HEADERS -I$(SRCROOT)/EXTERNAL_HEADERS/bsd 393export INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT) 394export INCFLAGS_POSIX = -I$(OBJROOT)/EXPORT_HDRS/bsd 395export INCFLAGS_LOCAL = -I. 396 397export INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) 398 399# 400# Default MIGFLAGS 401# 402export MIGFLAGS = $(DEFINES) $(INCFLAGS) $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) 403 404# 405# Default VPATH 406# 407empty:= 408space:= $(empty) $(empty) 409export VPATH_IMPORT = $(subst $(space),:,$(patsubst %,$(OBJROOT)/EXPORT_HDRS/%,$(strip $(COMPONENT_IMPORT_LIST)))): 410export VPATH_EXTERN = $(OBJROOT)/EXTERN_HDRS: 411export VPATH_GEN = .:$(SOURCE): 412 413export VPATH = $(VPATH_GEN)$(VPATH_IMPORT)$(VPATH_EXTERN)$(VPATH_MAKEFILE) 414 415# 416# Macros that control installation of kernel and its header files 417# 418# install flags for header files 419# 420INSTALL_FLAGS = -c -m 0444 421FILE_INSTALL_FLAGS = -c -m 0644 422DATA_INSTALL_FLAGS = -c -m 0644 423 424# 425# Header file destinations 426# 427FRAMEDIR = System/Library/Frameworks 428ifndef INCDIR 429 INCDIR = /usr/include 430endif 431ifndef LCLDIR 432 LCLDIR = $(FRAMEDIR)/System.framework/Versions/B/PrivateHeaders 433endif 434 435KINCVERS = A 436KINCFRAME = $(FRAMEDIR)/Kernel.framework 437KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers 438KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders 439KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources 440 441XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE 442 443SPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_ 444SINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_ 445KPINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_ 446KINCFRAME_UNIFDEF = $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_ 447 448# 449# Compononent Header file destinations 450# 451EXPDIR = EXPORT_HDRS/$(COMPONENT) 452 453# 454# Strip Flags 455# 456export STRIP_FLAGS_RELEASE = -S -x 457export STRIP_FLAGS_DEVELOPMENT = -S -x 458export STRIP_FLAGS_RELEASE_TRACE = -S -x 459export STRIP_FLAGS_DEBUG = -S 460export STRIP_FLAGS_DEBUG_TRACE = -S 461export STRIP_FLAGS_PROFILE = -S -x 462 463export STRIP_FLAGS = $($(addsuffix $(KERNEL_CONFIG),STRIP_FLAGS_)) 464 465# 466# dsymutil flags 467# 468export DSYMUTIL_FLAGS_I386 = --arch=i386 469export DSYMUTIL_FLAGS_PPC = --arch=ppc 470export DSYMUTIL_FLAGS_ARM = --arch=arm 471 472export DSYMUTIL_FLAGS = $($(addsuffix $(ARCH_CONFIG),DSYMUTIL_FLAGS_)) 473 474# 475# Man Page destination 476# 477MANDIR = usr/share/man 478 479## 480# Verbosity 481## 482ifeq ($(RC_XBS),YES) 483VERBOSE = YES 484else 485VERBOSE = NO 486endif 487 488ifeq ($(VERBOSE),YES) 489_v = 490else 491_v = @ 492endif 493 494# 495# This must be here before any rules are possibly defined by the 496# machine dependent makefile fragment so that a plain "make" command 497# always works. The config program will emit an appropriate rule to 498# cause "all" to depend on every kernel configuration it generates. 499# 500 501default: all 502 503# vim: set ft=make: 504