1# -*- mode: makefile;-*- 2# 3# Copyright (C) 2010-2020 Apple Inc. All rights reserved. 4# 5# MakeInc.top is the top-level makefile for the xnu 6# build system. All the main XBS targets 7# (like "installhdrs") are defined here, as 8# well as globals that can be overridden on 9# the command-line by the user. 10# 11# This makefile's main purpose is to bootstrap 12# the user's intent ("build these 3 kernels") 13# into 3 single-architecture builds that each 14# invoke the recursive make build system. 15# As such, we have no knowledge of how to build 16# a kernel or perform actions other than 17# invoking a sub-make with a different 18# current directory, makefile, and target. One 19# side effect of this is that each 20# single-architecture build is responsible for 21# inserting its build products into the final 22# multi-architecture output files. To avoid 23# races, these aggregating stages for 24# "primary" build configs are done in serial. 25# 26 27export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd 28 29include $(MakeInc_cmd) 30 31 32# 33# Architecture Configuration options 34# 35 36# Default to current kernel architecture 37 38ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) 39 override DEFAULT_ARCH_CONFIG := ARM 40else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),) 41 override DEFAULT_ARCH_CONFIG := X86_64 42else 43 override DEFAULT_ARCH_CONFIG := X86_64 44endif 45 46# Accept either explicit ARCH_CONFIGS or XBS-style RC_ARCHS 47ifndef ARCH_CONFIGS 48ifdef RC_ARCHS 49ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z | $(TR) " " "\n" | sort -u | $(TR) "\n" " ") 50else 51ARCH_CONFIGS := DEFAULT 52endif 53endif 54 55# 56# Kernel Configuration options 57# 58 59DEFAULT_PRODUCT_CONFIGS := 60 61ifneq ($(filter $(RC_ProjectName),xnu_debug),) 62override DEFAULT_KERNEL_CONFIG := DEBUG 63else ifneq ($(filter $(RC_ProjectName),xnu_kasan),) 64override KERNEL_CONFIGS := KASAN 65else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) 66override DEFAULT_KERNEL_CONFIG := DEVELOPMENT 67else ifeq ($(PLATFORM),MacOSX) 68override DEFAULT_KERNEL_CONFIG := DEVELOPMENT 69else 70override DEFAULT_KERNEL_CONFIG := RELEASE 71endif 72 73# If KERNEL_CONFIGS is specified it should override default 74ifndef KERNEL_CONFIGS 75KERNEL_CONFIGS := DEFAULT 76endif 77 78# If PRODUCT_CONFIGS is specified it should override default 79ifndef PRODUCT_CONFIGS 80PRODUCT_CONFIGS := $(DEFAULT_PRODUCT_CONFIGS) 81endif 82 83# 84# Machine Configuration options 85# 86 87override DEFAULT_I386_MACHINE_CONFIG := NONE 88override DEFAULT_X86_64_MACHINE_CONFIG := NONE 89override DEFAULT_X86_64H_MACHINE_CONFIG := NONE 90 91ifneq ($(findstring _Sim,$(RC_ProjectName)),) 92override DEFAULT_ARM_MACHINE_CONFIG := NONE 93override DEFAULT_ARM64_MACHINE_CONFIG := NONE 94else ifneq ($(findstring _host,$(RC_ProjectName)),) 95override DEFAULT_ARM_MACHINE_CONFIG := NONE 96override DEFAULT_ARM64_MACHINE_CONFIG := NONE 97else 98override DEFAULT_ARM_MACHINE_CONFIG := NONE 99override DEFAULT_ARM64_MACHINE_CONFIG := VMAPPLE 100endif 101 102# This is typically never specified (TARGET_CONFIGS is used) 103ifndef MACHINE_CONFIGS 104MACHINE_CONFIGS := DEFAULT 105endif 106 107# 108# Target configuration options. NOTE - target configurations will 109# override ARCH_CONFIGS and KERNEL_CONFIGS and MACHINE_CONFIGS. 110# 111# Target configs come in groups of three parameters. The first is the 112# kernel configuration, the second is the architecture configuration, 113# and the third is the machine configuration. You may pass in as 114# many groups of configurations as you wish. Each item passed in is 115# seperated by whitespace. 116# 117# Example: 118# TARGET_CONFIGS="release ppc default debug i386 default release arm MX31ADS" 119# Parameters may be in upper or lower case (they are converted to upper). 120# 121# "default" parameter is a special case. It means use the default value for 122# that parameter. Here are the default values for each configuration: 123# 124# default kernel configuration = DEFAULT_KERNEL_CONFIG 125# default architecture configuration = system architecture where you are running make. 126 127ifneq ($(filter $(SUPPORTED_PLATFORMS),$(PLATFORM)),) 128 129# Defaults for "make all_embedded" 130ifeq ($(KERNEL_CONFIGS),DEFAULT) 131KERNEL_CONFIGS_EMBEDDED := RELEASE DEVELOPMENT 132else 133KERNEL_CONFIGS_EMBEDDED := $(KERNEL_CONFIGS) 134endif 135 136ifeq ($(ARCH_CONFIGS),DEFAULT) 137ARCH_CONFIGS_EMBEDDED := ARM ARM64 138ARCH_CONFIGS_DESKTOP := X86_64 139else 140ARCH_CONFIGS_EMBEDDED := $(strip $(shell echo $(filter-out X86_64, $(ARCH_CONFIGS)) | $(TR) a-z A-Z)) 141ARCH_CONFIGS_DESKTOP := $(strip $(shell echo $(filter X86_64, $(ARCH_CONFIGS)) | $(TR) a-z A-Z)) 142endif 143 144# Find supported products from the device map 145ifneq ($(EMBEDDED_DEVICE_MAP),) 146DEVICEMAP_PRODUCTS_ARMV7 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \ 147 -query 'SELECT DISTINCT TargetType \ 148 FROM Files \ 149 INNER JOIN Manifests USING (manifestID) \ 150 INNER JOIN Targets USING (Target) \ 151 WHERE (KernelMachOArchitecture LIKE "armv7" \ 152 AND fileType in ("KernelCache", "RestoreKernelCache"))') 153DEVICEMAP_PRODUCTS_ARMV7S := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \ 154 -query 'SELECT DISTINCT TargetType \ 155 FROM Files \ 156 INNER JOIN Manifests USING (manifestID) \ 157 INNER JOIN Targets USING (Target) \ 158 WHERE (KernelMachOArchitecture LIKE "armv7s" \ 159 AND fileType in ("KernelCache", "RestoreKernelCache"))') 160DEVICEMAP_PRODUCTS_ARMV7K := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \ 161 -query 'SELECT DISTINCT TargetType \ 162 FROM Files \ 163 INNER JOIN Manifests USING (manifestID) \ 164 INNER JOIN Targets USING (Target) \ 165 WHERE (KernelMachOArchitecture LIKE "armv7k" \ 166 AND fileType in ("KernelCache", "RestoreKernelCache"))') 167DEVICEMAP_PRODUCTS_ARM := $(DEVICEMAP_PRODUCTS_ARMV7) $(DEVICEMAP_PRODUCTS_ARMV7S) $(DEVICEMAP_PRODUCTS_ARMV7K) 168 169 170DEVICEMAP_PRODUCTS_ARM64 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \ 171 -query 'SELECT DISTINCT TargetType \ 172 FROM Files \ 173 INNER JOIN Manifests USING (manifestID) \ 174 INNER JOIN Targets USING (Target) \ 175 WHERE (KernelMachOArchitecture LIKE "arm64" \ 176 AND fileType in ("KernelCache", "RestoreKernelCache"))') 177DEVICEMAP_PRODUCTS_OSX_ARM64 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \ 178 -query 'SELECT DISTINCT TargetType \ 179 FROM Files \ 180 INNER JOIN Manifests USING (manifestID) \ 181 INNER JOIN Targets USING (Target) \ 182 WHERE (KernelMachOArchitecture LIKE "arm64" \ 183 AND fileType in ("KernelCache", "RestoreKernelCache") \ 184 AND SDKPlatform == "macosx")') 185 186 187# Generate a list of mappings of the form "n75:arm;t8002" based on the device map 188DEVICEMAP_PRODUCT_SOC_MAPPINGS := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) -query SELECT DISTINCT TargetType, KernelMachOArchitecture, KernelPlatform FROM Targets | awk -F\| '{ if ($$2 ~ /armv[0-9][a-z]?/) { print $$1 ":arm;" $$3 } else if ($$2 ~ /arm64[a-z]?/) { print $$1 ":arm64;" $$3 ";" $$4} else { print $$1 ":" $$2 ";" $$3 ";" $$4} }' ) 189 190# use embedded_device_map 191endif 192 193# Map a product like "n75" to "arm;t8002" 194# $(1) is a product name in lower case 195function_lookup_product = $(call function_substitute_word_with_replacement, \ 196 $(1), \ 197 $(DEVICEMAP_PRODUCT_SOC_MAPPINGS), \ 198 unknown_arch_for_$(1);unknown_platform_for_$(1) \ 199 ) 200 201ifneq ($(PLATFORM),MacOSX) 202ifneq ($(EMBEDDED_DEVICE_MAP),) 203# Generate a list of mappings for products that use a different platform for their kernel configuration than their true platform 204# of the form "n71m:arm64;s8000;s8003". The 4th element is the true SoC platform, which will get an on-disk copy, while the 205# kernel's recursive build system will build the 3rd element as the KernelPlatform 206DEVICEMAP_PRODUCT_SOC_ALIASES := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) -query SELECT DISTINCT TargetType, KernelMachOArchitecture, KernelPlatform, Platform FROM Targets WHERE KernelPlatform "!=" Platform | awk -F\| '{ if ($$2 ~ /armv[0-9][a-z]?/) { print $$1 ":arm;" $$3 ";" $$4} else if ($$2 ~ /arm64[a-z]?/) { print $$1 ":arm64;" $$3 ";" $$4} else { print $$1 ":" $$2 ";" $$3 ";" $$4} }' ) 207 208endif 209endif 210 211function_lookup_product_alias = $(call function_substitute_word_with_replacement, \ 212 $(1), \ 213 $(DEVICEMAP_PRODUCT_SOC_ALIASES), \ 214 ) 215endif 216 217ifeq ($(PLATFORM),MacOSX) 218 219# Defaults for "make all_desktop" 220ifeq ($(KERNEL_CONFIGS),DEFAULT) 221KERNEL_CONFIGS_DESKTOP := RELEASE DEVELOPMENT 222else 223KERNEL_CONFIGS_DESKTOP := $(KERNEL_CONFIGS) 224endif 225 226endif 227 228ifndef TARGET_CONFIGS 229ifneq ($(PRODUCT_CONFIGS),) 230# generate TARGET_CONFIGS using KERNEL_CONFIGS and PRODUCT_CONFIGS 231TARGET_CONFIGS := $(foreach my_devicemap_config,$(foreach my_product_config,$(shell printf "%s" "$(PRODUCT_CONFIGS)" | $(TR) A-Z a-z),$(call function_lookup_product,$(my_product_config))),$(foreach my_kernel_config,$(KERNEL_CONFIGS),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 232TARGET_CONFIGS_ALIASES := $(foreach my_devicemap_config,$(foreach my_product_config,$(shell printf "%s" "$(PRODUCT_CONFIGS)" | $(TR) A-Z a-z),$(call function_lookup_product_alias,$(my_product_config))),$(foreach my_kernel_config,$(KERNEL_CONFIGS),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 233else ifneq ($(filter %_release_embedded,$(MAKECMDGOALS)),) 234# generate TARGET_CONFIGS for RELEASE kernel configs and products in the device map 235TARGET_CONFIGS := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product,$(my_product_config)))),$(foreach my_kernel_config,RELEASE,$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 236TARGET_CONFIGS_ALIASES := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product_alias,$(my_product_config)))),$(foreach my_kernel_config,RELEASE,$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 237else ifneq ($(filter %_development_embedded,$(MAKECMDGOALS)),) 238# generate TARGET_CONFIGS for DEVELOPMENT kernel configs and products in the device map 239TARGET_CONFIGS := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product,$(my_product_config)))),$(foreach my_kernel_config,DEVELOPMENT,$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 240TARGET_CONFIGS_ALIASES := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product_alias,$(my_product_config)))),$(foreach my_kernel_config,DEVELOPMENT,$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 241else ifneq ($(filter %_embedded,$(MAKECMDGOALS)),) 242# generate TARGET_CONFIGS for all kernel configs and products in the device map 243TARGET_CONFIGS := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product,$(my_product_config)))),$(foreach my_kernel_config,$(KERNEL_CONFIGS_EMBEDDED),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 244TARGET_CONFIGS_ALIASES := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_$(my_arch_config)),$(call function_lookup_product_alias,$(my_product_config)))),$(foreach my_kernel_config,$(KERNEL_CONFIGS_EMBEDDED),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 245else ifeq (xnu_headers_driverkit,$(RC_ProjectName)) 246# generate TARGET_CONFIGS for all kernel configs for B&I 247TARGET_CONFIGS = DEVELOPMENT arm64 DEFAULT DEVELOPMENT X86_64 DEFAULT 248else ifneq ($(filter %_desktop,$(MAKECMDGOALS)),) 249# generate TARGET_CONFIGS for all kernel configs for B&I 250TARGET_CONFIGS := $(foreach my_kern_config, $(KERNEL_CONFIGS_DESKTOP), $(foreach my_arch_config, $(ARCH_CONFIGS_DESKTOP), $(foreach my_machine_config, $(MACHINE_CONFIGS), $(my_kern_config) $(my_arch_config) $(my_machine_config)))) 251TARGET_CONFIGS += $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_OSX_$(my_arch_config)),$(call function_lookup_product,$(my_product_config)))),$(foreach my_kernel_config,$(KERNEL_CONFIGS_EMBEDDED),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 252TARGET_CONFIGS_ALIASES := $(foreach my_devicemap_config,$(foreach my_arch_config,$(ARCH_CONFIGS_EMBEDDED),$(foreach my_product_config,$(DEVICEMAP_PRODUCTS_OSX_$(my_arch_config)),$(call function_lookup_product_alias,$(my_product_config)))),$(foreach my_kernel_config,$(KERNEL_CONFIGS_EMBEDDED),$(my_kernel_config) $(subst ;, ,$(my_devicemap_config)))) 253else 254# generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIGS (which defaults to "DEFAULT") 255TARGET_CONFIGS := $(foreach my_kern_config, $(KERNEL_CONFIGS), $(foreach my_arch_config, $(ARCH_CONFIGS), $(foreach my_machine_config, $(MACHINE_CONFIGS), $(my_kern_config) $(my_arch_config) $(my_machine_config)))) 256TARGET_CONFIGS_ALIASES := 257endif 258endif 259 260ifeq ($(TARGET_CONFIGS),) 261$(error No TARGET_CONFIGS specified) 262endif 263 264TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z)) 265TARGET_CONFIGS_ALIASES_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS_ALIASES)" | $(TR) a-z A-Z)) 266 267# 268# Build Configurations 269# 270# TARGET_CONFIGS is unwieldy for use in Makefiles. Convert them to 271# "build configurations" which are tuples joined by "^". For 272# example, "RELEASE I386 DEFAULT DEVELOPMENT ARM DEFAULT" becomes 273# "RELEASE^I386^NONE DEVELOPMENT^ARM^T8002", which can be looped 274# over trivially. PRIMARY_BUILD_CONFIGS is the first config 275# for each architecture, used primarily for machine-dependent recursion. 276# VARIANT_CONFIGS contains one build configuration for each combination 277# of kernel architecture and configuration. It is used for variant 278# installation recursion. 279 280BUILD_CONFIGS = $(call function_create_build_configs, $(TARGET_CONFIGS_UC)) 281 282PRIMARY_ARCHS = $(strip $(sort $(foreach build_config, $(BUILD_CONFIGS), $(call function_extract_arch_config_from_build_config, $(build_config))))) 283PRIMARY_BUILD_CONFIGS = $(strip $(foreach arch, $(PRIMARY_ARCHS), $(firstword $(foreach build_config, $(BUILD_CONFIGS), $(if $(filter $(arch),$(call function_extract_arch_config_from_build_config, $(build_config))), $(build_config), ))))) 284NON_PRIMARY_BUILD_CONFIGS = $(strip $(filter-out $(PRIMARY_BUILD_CONFIGS), $(BUILD_CONFIGS))) 285FIRST_BUILD_CONFIG = $(firstword $(BUILD_CONFIGS)) 286 287# Build list of all kernel configurations present in all build configs. 288PRIMARY_KERNEL_CONFIGS = $(strip $(sort $(foreach build_config, $(BUILD_CONFIGS), $(call function_extract_kernel_config_from_build_config, $(build_config))))) 289 290# Pick one build configuration for each kernel configuration. 291# This will be used to populate System.kext variants in SYMROOT / DSTROOT. 292VARIANT_CONFIGS = $(strip \ 293 $(foreach kernel_config, $(PRIMARY_KERNEL_CONFIGS), \ 294 $(firstword $(call function_match_build_config_for_kernel_config, $(BUILD_CONFIGS), $(kernel_config))))) 295 296ifneq ($(TARGET_CONFIGS_ALIASES_UC),) 297ALIAS_CONFIGS = $(call function_create_alias_configs, $(TARGET_CONFIGS_ALIASES_UC)) 298else 299ALIAS_CONFIGS = 300endif 301 302# $(warning PRIMARY_ARCHS is $(PRIMARY_ARCHS)) 303# $(warning TARGET_CONFIGS is $(TARGET_CONFIGS)) 304# $(warning BUILD_CONFIGS is $(BUILD_CONFIGS)) 305# $(warning PRIMARY_BUILD_CONFIGS is $(PRIMARY_BUILD_CONFIGS)) 306# $(warning NON_PRIMARY_BUILD_CONFIGS is $(NON_PRIMARY_BUILD_CONFIGS)) 307# $(warning TARGET_CONFIGS_ALIASES is $(TARGET_CONFIGS_ALIASES)) 308# $(warning ALIAS_CONFIGS is $(ALIAS_CONFIGS)) 309# $(warning PRIMARY_KERNEL_CONFIGS is $(PRIMARY_KERNEL_CONFIGS)) 310# $(warning VARIANT_CONFIGS is $(VARIANT_CONFIGS)) 311 312MEMORY_SIZE := $(shell /usr/sbin/sysctl -n hw.memsize) 313 314# Assume LTO scaling by default, unless it is being explicitly passed on the command-line 315LARGE_BUILD_FOOTPRINT := $(if $(BUILD_LTO),$(BUILD_LTO),1) 316 317ifeq ($(LARGE_BUILD_FOOTPRINT),1) 318RAM_PER_KERNEL_BUILD := 4294967296 319else 320RAM_PER_KERNEL_BUILD := 268435456 321endif 322 323KERNEL_BUILDS_IN_PARALLEL := $(shell if [ $(MEMORY_SIZE) -le $$((1 * $(RAM_PER_KERNEL_BUILD))) ]; then echo 1; elif [ $(MEMORY_SIZE) -gt $$(($(SYSCTL_HW_PHYSICALCPU) * $(RAM_PER_KERNEL_BUILD))) ]; then echo $(SYSCTL_HW_PHYSICALCPU); else expr $(MEMORY_SIZE) / $(RAM_PER_KERNEL_BUILD); fi ) 324# $(warning Building $(KERNEL_BUILDS_IN_PARALLEL) kernels in parallel) 325 326# 327# TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template 328# 329# $(1) is the name of the makefile target to invoke for the each build config 330# after setting up the parallel hierarchy in the TARGET directory 331# $(2) is an optional suffix on the TARGET directory, which might even be 332# "/.." 333# $(3) are any dependencies for the bootstrap target 334# $(4) are any dependencies that are expanded per-build config to another bootstrap target 335# $(5) is how many build configurations to build in parallel 336# $(6) is which build configs to build in parallel 337# 338# Since building many configurations in parallel may overwhelm the system, 339# we try to throttle behavior into more managable S "stripes" of N/S 340# configurations by generating sequential dependencies between configs 341# in each stripe. That ensures that only S kernel builds are occurring 342# at once at any point in time 343 344define TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template 345 346# Create a list of synthesized targets for each build config 347$(1)_bootstrap_target_list = $$(addprefix $(1)_bootstrap_,$(6)) 348 349.PHONY: $$($(1)_bootstrap_target_list) 350 351$(1)_generated_stripe_dependencies = $$(call _function_generate_stripe_groupings,$(1),$(5),$(call reverse,$(6))) 352ifeq ($$(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 353$$(warning Generate makefile fragment: $$($(1)_generated_stripe_dependencies)) 354endif 355$$(eval $$($(1)_generated_stripe_dependencies)) 356 357$$($(1)_bootstrap_target_list): $(1)_bootstrap_% : $(1)_stripe_dep_for_% $$(addsuffix _bootstrap_%,$(4)) $(3) 358 $$(_v)$$(MKDIR) $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2) 359 $$(_v)$${MAKE} \ 360 -C $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2) \ 361 -f $${SRCROOT}/Makefile \ 362 CURRENT_KERNEL_CONFIG=$$(call function_extract_kernel_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \ 363 CURRENT_ARCH_CONFIG=$$(call function_extract_arch_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \ 364 CURRENT_MACHINE_CONFIG=$$(call function_extract_machine_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \ 365 CURRENT_BUILD_CONFIG=$$(patsubst $(1)_bootstrap_%,%,$$@) \ 366 PRIMARY_BUILD_CONFIGS="$(PRIMARY_BUILD_CONFIGS)" BUILD_CONFIGS="$(BUILD_CONFIGS)" \ 367 SOURCE=$${SRCROOT}/ \ 368 RELATIVE_SOURCE_PATH=. \ 369 TARGET=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)/ \ 370 OBJPATH=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@)) \ 371 $(1) 372 373.PHONY: $(1)_bootstrap 374 375$(1)_bootstrap: $$($(1)_bootstrap_target_list) 376endef 377 378# 379# TOP_LEVEL_STRIPE_DEPENDENCY_template 380# 381# $(1) is the Makefile target we are building for 382# $(2) is the build config that must build first 383# $(3) is the build config that must build after $(2) 384 385define TOP_LEVEL_STRIPE_DEPENDENCY_template 386 387.PHONY: $(1)_stripe_dep_for_$(3) 388 389 $(1)_stripe_dep_for_$(3): $(if $(2),$(1)_bootstrap_$(2)) 390 391endef 392 393# $(1) is the Makefile target we are building for 394# $(2) is the stripe size 395# $(3) is the list of the build configs in the current group 396# $(4) is the list of remaining build configs 397_function_generate_stripe_groupings_recursive = $(foreach stripe_index,$(call sequence,$(2)),$(if $(word $(stripe_index),$(4)),$(call TOP_LEVEL_STRIPE_DEPENDENCY_template,$(1),$(word $(stripe_index),$(3)),$(word $(stripe_index),$(4))))) $(if $(word $(call increment,$(2)),$(4)),$(call _function_generate_stripe_groupings_recursive,$(1),$(2),$(wordlist 1,$(2),$(4)),$(wordlist $(call increment,$(2)),$(words $(4)),$(4)))) 398 399# $(1) is the Makefile target we are building for 400# $(2) is the stripe size 401# $(3) is the list of the build configs 402_function_generate_stripe_groupings = $(call _function_generate_stripe_groupings_recursive,$(1),$(2),,$(3)) 403 404# 405# Setup pass for build system tools 406# 407 408generated_top_level_build_setup = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_setup,/..,,,1,$(FIRST_BUILD_CONFIG)) 409ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 410$(warning Generate makefile fragment: $(generated_top_level_build_setup)) 411endif 412$(eval $(generated_top_level_build_setup)) 413 414.PHONY: setup 415 416# invalidate current kernel in $(SYMROOT). Timestamp must be +1 from a previous kernel build 417setup: build_setup_bootstrap 418 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new 419 # -nt and -ot are evaluated differently by bash, dash, and zsh (and are not part of the POSIX specification). 420 # Explicitly specify what should happen when the right hand file doesn't exist. 421 $(_v)while [ \! $(OBJROOT)/.mach_kernel.timestamp.new -nt $(OBJROOT)/.mach_kernel.timestamp -a \( \! -e $(OBJROOT)/.mach_kernel.timestamp.new -o -e $(OBJROOT)/.mach_kernel.timestamp \) ]; do \ 422 $(SLEEP) 1; \ 423 $(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new; \ 424 done 425 $(_v)$(MV) $(OBJROOT)/.mach_kernel.timestamp.new $(OBJROOT)/.mach_kernel.timestamp 426 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp.new 427 $(_v)while [ $(OBJROOT)/.symbolset.timestamp.new -ot $(OBJROOT)/.symbolset.timestamp ]; do \ 428 $(SLEEP) 1; \ 429 $(TOUCH) $(OBJROOT)/.symbolset.timestamp.new; \ 430 done 431 $(_v)$(MV) $(OBJROOT)/.symbolset.timestamp.new $(OBJROOT)/.symbolset.timestamp 432 433# 434# Install kernel header files 435# 436.PHONY: exporthdrs exporthdrs_mi exporthdrs_md 437 438exporthdrs: exporthdrs_mi exporthdrs_md 439 440# 441# Install machine independent kernel header files 442# 443 444generated_top_level_build_exporthdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_mi,,setup,,1,$(FIRST_BUILD_CONFIG)) 445ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 446$(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_mi)) 447endif 448$(eval $(generated_top_level_build_exporthdrs_mi)) 449 450exporthdrs_mi: build_exporthdrs_mi_bootstrap 451 452# 453# Install machine dependent kernel header files 454# 455 456generated_top_level_build_exporthdrs_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_md,,setup,,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS)) 457ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 458$(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_md)) 459endif 460$(eval $(generated_top_level_build_exporthdrs_md)) 461 462exporthdrs_md: build_exporthdrs_md_bootstrap 463 464# 465# Install kernel header files 466# 467 468.PHONY: installhdrs installhdrs_mi installhdrs_md 469 470ifneq ($(filter $(RC_ProjectName),xnu_debug),) 471installhdrs: 472 @: 473else ifneq ($(filter $(RC_ProjectName),xnu_kasan),) 474installhdrs: 475 @: 476else 477 478installhdrs: installhdrs_mi installhdrs_md 479endif 480 481.PHONY: installhdrs_embedded installhdrs_release_embedded installhdrs_development_embedded installhdrs_desktop 482 483installhdrs_embedded installhdrs_release_embedded installhdrs_desktop: installhdrs 484 485installhdrs_development_embedded: 486 487# 488# Install machine independent header files 489# 490 491generated_top_level_build_installhdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_installhdrs_mi,,setup,build_exporthdrs_mi,1,$(FIRST_BUILD_CONFIG)) 492ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 493$(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_mi)) 494endif 495$(eval $(generated_top_level_build_installhdrs_mi)) 496 497installhdrs_mi: build_installhdrs_mi_bootstrap 498 499# 500# Install machine dependent kernel header files 501# 502 503generated_top_level_build_installhdrs_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_installhdrs_md,,setup,build_exporthdrs_md,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS)) 504ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 505$(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_md)) 506endif 507$(eval $(generated_top_level_build_installhdrs_md)) 508 509installhdrs_md: build_installhdrs_md_bootstrap 510 511.PHONY: install_textfiles install_textfiles_mi install_textfiles_md 512 513install_textfiles: install_textfiles_mi install_textfiles_md 514 515# 516# Install machine independent text files (man pages, dtrace scripts, etc.) 517# 518 519generated_top_level_textfiles_install_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install_mi,,setup,,1,$(FIRST_BUILD_CONFIG)) 520ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 521$(warning Generate makefile fragment: $(generated_top_level_textfiles_install_mi)) 522endif 523$(eval $(generated_top_level_textfiles_install_mi)) 524 525install_textfiles_mi: textfiles_install_mi_bootstrap 526 527# 528# Install machine dependent text files (man pages, dtrace scripts, etc.) 529# 530 531generated_top_level_textfiles_install_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install_md,,setup,,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS)) 532ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 533$(warning Generate makefile fragment: $(generated_top_level_textfiles_install_md)) 534endif 535$(eval $(generated_top_level_textfiles_install_md)) 536 537install_textfiles_md: textfiles_install_md_bootstrap 538 539# 540# Build all architectures for all Configuration/Architecture options 541# 542 543generated_top_level_build_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_all,,setup exporthdrs,,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS)) 544ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 545$(warning Generate makefile fragment: $(generated_top_level_build_all)) 546endif 547$(eval $(generated_top_level_build_all)) 548 549.PHONY: build 550 551build: build_all_bootstrap 552 553# 554# Post-process build results 555# 556 557generated_top_level_config_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_all,,setup,build_all,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS)) 558ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 559$(warning Generate makefile fragment: $(generated_top_level_config_all)) 560endif 561$(eval $(generated_top_level_config_all)) 562 563.PHONY: all config 564 565all config: config_all_bootstrap 566 567.PHONY: all_embedded all_release_embedded all_development_embedded all_desktop 568 569all_embedded all_release_embedded all_development_embedded all_desktop: all 570 571# 572# Install kernel files 573# 574 575generated_top_level_build_install_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_install_primary,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS)) 576ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 577$(warning Generate makefile fragment: $(generated_top_level_build_install_primary)) 578endif 579$(eval $(generated_top_level_build_install_primary)) 580 581.PHONY: install_primary 582 583install_primary: build_install_primary_bootstrap 584 585generated_top_level_build_install_non_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_install_non_primary,,setup,config_all,$(KERNEL_BUILDS_IN_PARALLEL),$(NON_PRIMARY_BUILD_CONFIGS)) 586ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 587$(warning Generate makefile fragment: $(generated_top_level_build_install_non_primary)) 588endif 589$(eval $(generated_top_level_build_install_non_primary)) 590 591.PHONY: install_non_primary 592 593install_non_primary: build_install_non_primary_bootstrap 594 595generated_top_level_config_install_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install_primary,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS)) 596ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 597$(warning Generate makefile fragment: $(generated_top_level_config_install_primary)) 598endif 599$(eval $(generated_top_level_config_install_primary)) 600 601.PHONY: install_config_primary 602 603install_config_primary: config_install_primary_bootstrap 604 605# config_install_variant iterates through products from all BUILD_CONFIGS so depends on config_all having completed overall 606generated_top_level_config_install_variant = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install_variant,,config_all_bootstrap,,1,$(VARIANT_CONFIGS)) 607ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 608$(warning Generate makefile fragment: $(generated_top_level_config_install_variant)) 609endif 610$(eval $(generated_top_level_config_install_variant)) 611 612.PHONY: install_config_variant 613 614install_config_variant: config_install_variant_bootstrap 615 616# config_install iterates through products from all BUILD_CONFIGS so depends on config_all having completed overall 617generated_top_level_config_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install,,config_all_bootstrap,,1,$(FIRST_BUILD_CONFIG)) 618ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 619$(warning Generate makefile fragment: $(generated_top_level_config_install)) 620endif 621$(eval $(generated_top_level_config_install)) 622 623.PHONY: install_config final_touch_config_timestamps 624 625install_config: config_install_bootstrap install_config_primary install_config_variant final_touch_config_timestamps 626 627 628# Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT 629final_touch_config_timestamps: config_install_bootstrap install_config_primary install_config_variant 630 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp 631 632# 633# Aggregate install targets, which install everything appropriate for the current build alias/make target 634# 635 636.PHONY: install 637 638ifneq ($(filter $(RC_ProjectName),xnu_debug),) 639install: install_kernels 640else ifneq ($(filter $(RC_ProjectName),xnu_kasan),) 641install: install_config install_kernels 642else ifneq ($(filter $(RC_ProjectName),xnu_headers_Sim),) 643install: installhdrs 644else ifneq ($(filter $(RC_ProjectName),xnu_headers_host),) 645install: installhdrs 646export INSTALLHDRS_SKIP_HOST=YES 647export INSTALLHDRS_MODULEMAPS_SKIP_HOST=YES 648else ifneq ($(filter $(RC_ProjectName),xnu_headers_driverkit),) 649install: installhdrs_desktop 650else 651 652install: installhdrs install_textfiles install_config install_kernels install_aliases 653endif 654 655.PHONY: install_embedded install_release_embedded install_development_embedded install_desktop 656 657# By default, all kernel files, headers, text files, and pseudo-kexts are installed 658install_embedded install_release_embedded install_desktop: install 659 660# These special configs only install the kernel files 661install_development_embedded: install_kernels install_aliases 662 663.PHONY: install_kernels final_touch_kernel_timestamps install_aliases 664 665install_kernels: build_install_primary_bootstrap build_install_non_primary_bootstrap final_touch_kernel_timestamps 666 667# Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT 668final_touch_kernel_timestamps: build_install_primary_bootstrap build_install_non_primary_bootstrap 669 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp 670 @echo "done building xnu" 671 672# Copy kernels that are aliases of another configuration 673generated_top_level_install_alias = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,install_alias,,install_kernels,,$(KERNEL_BUILDS_IN_PARALLEL),$(ALIAS_CONFIGS)) 674ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 675$(warning Generate makefile fragment: $(generated_top_level_install_alias)) 676endif 677$(eval $(generated_top_level_install_alias)) 678 679install_aliases: install_alias_bootstrap 680 681# 682# Install source tree 683# 684.PHONY: installsrc 685 686installsrc: 687 @echo INSTALLSRC $(SRCROOT) 688 $(_v)$(MKDIR) $(SRCROOT) 689 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT) 690 $(_v)$(CHMOD) -R go+rX $(SRCROOT) 691 692 693# 694# Clean up source tree 695# 696.PHONY: clean 697 698CLEAN_RM_DIRS= $(OBJROOT) $(SYMROOT) $(DSTROOT) \ 699 $(SRCROOT)/tools/test/BUILD \ 700 $(SRCROOT)/tools/tests/darwintests/build \ 701 $(SRCROOT)/tools/tests/testkext/build \ 702 $(SRCROOT)/libkdd/build \ 703 $(SRCROOT)/tools/tests/unit_tests/BUILD \ 704 $(SRCROOT)/tools/tests/execperf/BUILD \ 705 $(SRCROOT)/tools/tests/packetdrill/BUILD \ 706 $(SRCROOT)/tools/tests/perf_index/BUILD 707 708CLEAN_ACTION_DIRS= $(SRCROOT)/tools/tests/MPMMTest \ 709 $(SRCROOT)/tools/tests/TLBcoherency \ 710 $(SRCROOT)/tools/tests/kqueue_tests \ 711 $(SRCROOT)/tools/tests/mktimer \ 712 $(SRCROOT)/tools/tests/zero-to-n \ 713 $(SRCROOT)/tools/tests/personas 714 715clean: 716 @: 717 $(_v)rm -f cscope.* 2> /dev/null 718 $(_v)rm -f TAGS 2> /dev/null 719 $(_v)for cdir in $(CLEAN_RM_DIRS); do \ 720 if [ -d $${cdir} ] ; then \ 721 echo "Removing $${cdir}"; \ 722 rm -fr $${cdir} 2> /dev/null || true ; \ 723 fi ; \ 724 done 725 726 $(_v)for mcdir in $(CLEAN_ACTION_DIRS); do \ 727 make -C $${mcdir} clean; \ 728 done 729 730 731# 732# Build source file list for cscope database and tags 733# 734.PHONY: cscope.files 735 736cscope.files: 737 @echo "Building file list for cscope and tags" 738 @find . -name '*.h' -type f | grep -v ^..BUILD > _cscope.files 2> /dev/null 739 @find . -name '*.defs' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null 740 @find . -name '*.c' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null 741 @find . -name '*.cpp' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null 742 @find . -name '*.s' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null 743 @find . -name '*.h.template' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null 744 @cat $(OBJROOT)/cscope.genhdrs/* >> _cscope.files 2> /dev/null || true 745 @echo -k -q -c > cscope.files 2> /dev/null 746 @sort -u < _cscope.files >> cscope.files 2> /dev/null 747 @rm -f _cscope.files _cscope.files2 2> /dev/null 748 749# 750# Build cscope database 751# 752cscope: cscope.files 753 @echo "Building cscope database" 754 @cscope -bvU 2> /dev/null 755 756# 757# Build tags 758# 759tags: cscope.files 760 @echo "Building ctags" 761 @-sed 1d cscope.files | xargs ctags -dtw 2> /dev/null || \ 762 echo "Phantom files detected!" 2>&1 > /dev/null 763 @-[ -f TAGS ] || ${MAKE} -f $(firstword $(MAKEFILE_LIST)) TAGS 764 765TAGS: cscope.files 766 @echo "Building etags" 767 @-cat cscope.files | etags -l auto -S - 2> /dev/null 768 @rm -f cscope.files 2> /dev/null 769 770 771.PHONY: help 772 773help: 774 @cat README.md 775 776.PHONY: print_exports 777 778print_exports: 779 $(_v)printenv | sort 780 781generated_top_level_print_exports = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,print_exports,,,,1,$(FIRST_BUILD_CONFIG)) 782ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) 783$(warning Generate makefile fragment: $(generated_top_level_print_exports)) 784endif 785$(eval $(generated_top_level_print_exports)) 786 787.PHONY: print_exports_first_build_config 788 789print_exports_first_build_config: print_exports_bootstrap 790 791# vim: set ft=make: 792