1 # -*- mode: makefile;-*-
3 # Copyright (C) 2010-2016 Apple Inc. All rights reserved.
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.
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.
27 export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd
29 include $(MakeInc_cmd)
33 # Architecture Configuration options
36 # Default to current kernel architecture
38 ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
39 override DEFAULT_ARCH_CONFIG := ARM
40 else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
41 override DEFAULT_ARCH_CONFIG := X86_64
43 override DEFAULT_ARCH_CONFIG := X86_64
46 # Accept either explicit ARCH_CONFIGS or XBS-style RC_ARCHS
49 ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z | $(TR) " " "\n" | sort -u | $(TR) "\n" " ")
51 ARCH_CONFIGS := DEFAULT
56 # Kernel Configuration options
59 DEFAULT_PRODUCT_CONFIGS :=
61 ifneq ($(filter $(RC_ProjectName),xnu_debug),)
62 override DEFAULT_KERNEL_CONFIG := DEBUG
63 else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
64 override KERNEL_CONFIGS := KASAN
65 else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
66 override DEFAULT_KERNEL_CONFIG := DEVELOPMENT
67 else ifeq ($(PLATFORM),MacOSX)
68 override DEFAULT_KERNEL_CONFIG := DEVELOPMENT
70 override DEFAULT_KERNEL_CONFIG := RELEASE
73 # If KERNEL_CONFIGS is specified it should override default
75 KERNEL_CONFIGS := DEFAULT
78 # If PRODUCT_CONFIGS is specified it should override default
79 ifndef PRODUCT_CONFIGS
80 PRODUCT_CONFIGS := $(DEFAULT_PRODUCT_CONFIGS)
84 # Machine Configuration options
87 override DEFAULT_I386_MACHINE_CONFIG := NONE
88 override DEFAULT_X86_64_MACHINE_CONFIG := NONE
89 override DEFAULT_X86_64H_MACHINE_CONFIG := NONE
91 ifneq ($(findstring _Sim,$(RC_ProjectName)),)
92 override DEFAULT_ARM_MACHINE_CONFIG := NONE
93 override DEFAULT_ARM64_MACHINE_CONFIG := NONE
94 else ifneq ($(findstring _host,$(RC_ProjectName)),)
95 override DEFAULT_ARM_MACHINE_CONFIG := NONE
96 override DEFAULT_ARM64_MACHINE_CONFIG := NONE
98 override DEFAULT_ARM_MACHINE_CONFIG := T8002
99 override DEFAULT_ARM64_MACHINE_CONFIG := T7000
102 # This is typically never specified (TARGET_CONFIGS is used)
103 ifndef MACHINE_CONFIGS
104 MACHINE_CONFIGS := DEFAULT
108 # Target configuration options. NOTE - target configurations will
109 # override ARCH_CONFIGS and KERNEL_CONFIGS and MACHINE_CONFIGS.
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.
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).
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:
124 # default kernel configuration = DEFAULT_KERNEL_CONFIG
125 # default architecture configuration = system architecture where you are running make.
127 ifneq ($(filter $(SUPPORTED_PLATFORMS),$(PLATFORM)),)
129 # Defaults for "make all_embedded"
130 ifeq ($(KERNEL_CONFIGS),DEFAULT)
131 KERNEL_CONFIGS_EMBEDDED := RELEASE DEVELOPMENT
133 KERNEL_CONFIGS_EMBEDDED := $(KERNEL_CONFIGS)
136 ifeq ($(ARCH_CONFIGS),DEFAULT)
137 ARCH_CONFIGS_EMBEDDED := ARM ARM64
138 ARCH_CONFIGS_DESKTOP := X86_64
140 ARCH_CONFIGS_EMBEDDED := $(strip $(shell echo $(filter-out X86_64, $(ARCH_CONFIGS)) | $(TR) a-z A-Z))
141 ARCH_CONFIGS_DESKTOP := $(strip $(shell echo $(filter X86_64, $(ARCH_CONFIGS)) | $(TR) a-z A-Z))
144 # Find supported products from the device map
145 ifneq ($(EMBEDDED_DEVICE_MAP),)
146 DEVICEMAP_PRODUCTS_ARMV7 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
147 -query 'SELECT DISTINCT TargetType \
149 INNER JOIN Manifests USING (manifestID) \
150 INNER JOIN Targets USING (Target) \
151 WHERE (KernelMachOArchitecture LIKE "armv7" \
152 AND fileType in ("KernelCache", "RestoreKernelCache"))')
153 DEVICEMAP_PRODUCTS_ARMV7S := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
154 -query 'SELECT DISTINCT TargetType \
156 INNER JOIN Manifests USING (manifestID) \
157 INNER JOIN Targets USING (Target) \
158 WHERE (KernelMachOArchitecture LIKE "armv7s" \
159 AND fileType in ("KernelCache", "RestoreKernelCache"))')
160 DEVICEMAP_PRODUCTS_ARMV7K := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
161 -query 'SELECT DISTINCT TargetType \
163 INNER JOIN Manifests USING (manifestID) \
164 INNER JOIN Targets USING (Target) \
165 WHERE (KernelMachOArchitecture LIKE "armv7k" \
166 AND fileType in ("KernelCache", "RestoreKernelCache"))')
167 DEVICEMAP_PRODUCTS_ARM := $(DEVICEMAP_PRODUCTS_ARMV7) $(DEVICEMAP_PRODUCTS_ARMV7S) $(DEVICEMAP_PRODUCTS_ARMV7K)
170 DEVICEMAP_PRODUCTS_ARM64 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
171 -query 'SELECT DISTINCT TargetType \
173 INNER JOIN Manifests USING (manifestID) \
174 INNER JOIN Targets USING (Target) \
175 WHERE (KernelMachOArchitecture LIKE "arm64" \
176 AND fileType in ("KernelCache", "RestoreKernelCache"))')
177 DEVICEMAP_PRODUCTS_OSX_ARM64 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
178 -query 'SELECT DISTINCT TargetType \
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")')
187 # Generate a list of mappings of the form "n75:arm;t8002" based on the device map
188 DEVICEMAP_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} }' )
190 # use embedded_device_map
193 # Map a product like "n75" to "arm;t8002"
194 # $(1) is a product name in lower case
195 function_lookup_product = $(call function_substitute_word_with_replacement, \
197 $(DEVICEMAP_PRODUCT_SOC_MAPPINGS), \
198 unknown_arch_for_$(1);unknown_platform_for_$(1) \
201 ifneq ($(PLATFORM),MacOSX)
202 ifneq ($(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
206 DEVICEMAP_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} }' )
211 function_lookup_product_alias = $(call function_substitute_word_with_replacement, \
213 $(DEVICEMAP_PRODUCT_SOC_ALIASES), \
217 ifeq ($(PLATFORM),MacOSX)
219 # Defaults for "make all_desktop"
220 ifeq ($(KERNEL_CONFIGS),DEFAULT)
221 KERNEL_CONFIGS_DESKTOP := RELEASE DEVELOPMENT
223 KERNEL_CONFIGS_DESKTOP := $(KERNEL_CONFIGS)
228 ifndef TARGET_CONFIGS
229 ifneq ($(PRODUCT_CONFIGS),)
230 # generate TARGET_CONFIGS using KERNEL_CONFIGS and PRODUCT_CONFIGS
231 TARGET_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))))
232 TARGET_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))))
233 else ifneq ($(filter %_release_embedded,$(MAKECMDGOALS)),)
234 # generate TARGET_CONFIGS for RELEASE kernel configs and products in the device map
235 TARGET_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))))
236 TARGET_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))))
237 else ifneq ($(filter %_development_embedded,$(MAKECMDGOALS)),)
238 # generate TARGET_CONFIGS for DEVELOPMENT kernel configs and products in the device map
239 TARGET_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))))
240 TARGET_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))))
241 else ifneq ($(filter %_embedded,$(MAKECMDGOALS)),)
242 # generate TARGET_CONFIGS for all kernel configs and products in the device map
243 TARGET_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))))
244 TARGET_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))))
245 else ifneq ($(filter %_desktop,$(MAKECMDGOALS)),)
246 # generate TARGET_CONFIGS for all kernel configs for B&I
247 TARGET_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))))
248 TARGET_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))))
249 TARGET_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))))
251 # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIGS (which defaults to "DEFAULT")
252 TARGET_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))))
253 TARGET_CONFIGS_ALIASES :=
257 ifeq ($(TARGET_CONFIGS),)
258 $(error No TARGET_CONFIGS specified)
261 TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z))
262 TARGET_CONFIGS_ALIASES_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS_ALIASES)" | $(TR) a-z A-Z))
265 # Build Configurations
267 # TARGET_CONFIGS is unwieldy for use in Makefiles. Convert them to
268 # "build configurations" which are tuples joined by "^". For
269 # example, "RELEASE I386 DEFAULT DEVELOPMENT ARM DEFAULT" becomes
270 # "RELEASE^I386^NONE DEVELOPMENT^ARM^T8002", which can be looped
271 # over trivially. PRIMARY_BUILD_CONFIGS is the first config
272 # for each architecture, used primarily for machine-dependent recursion.
274 BUILD_CONFIGS = $(call function_create_build_configs, $(TARGET_CONFIGS_UC))
276 PRIMARY_ARCHS = $(strip $(sort $(foreach build_config, $(BUILD_CONFIGS), $(call function_extract_arch_config_from_build_config, $(build_config)))))
277 PRIMARY_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), )))))
278 NON_PRIMARY_BUILD_CONFIGS = $(strip $(filter-out $(PRIMARY_BUILD_CONFIGS), $(BUILD_CONFIGS)))
279 FIRST_BUILD_CONFIG = $(firstword $(BUILD_CONFIGS))
281 ifneq ($(TARGET_CONFIGS_ALIASES_UC),)
282 ALIAS_CONFIGS = $(call function_create_alias_configs, $(TARGET_CONFIGS_ALIASES_UC))
287 # $(warning PRIMARY_ARCHS is $(PRIMARY_ARCHS))
288 # $(warning TARGET_CONFIGS is $(TARGET_CONFIGS))
289 # $(warning BUILD_CONFIGS is $(BUILD_CONFIGS))
290 # $(warning PRIMARY_BUILD_CONFIGS is $(PRIMARY_BUILD_CONFIGS))
291 # $(warning NON_PRIMARY_BUILD_CONFIGS is $(NON_PRIMARY_BUILD_CONFIGS))
292 # $(warning TARGET_CONFIGS_ALIASES is $(TARGET_CONFIGS_ALIASES))
293 # $(warning ALIAS_CONFIGS is $(ALIAS_CONFIGS))
295 MEMORY_SIZE := $(shell /usr/sbin/sysctl -n hw.memsize)
297 # Assume LTO scaling by default, unless it is being explicitly passed on the command-line
298 LARGE_BUILD_FOOTPRINT := $(if $(BUILD_LTO),$(BUILD_LTO),1)
300 ifeq ($(LARGE_BUILD_FOOTPRINT),1)
301 RAM_PER_KERNEL_BUILD := 4294967296
303 RAM_PER_KERNEL_BUILD := 268435456
306 KERNEL_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 )
307 # $(warning Building $(KERNEL_BUILDS_IN_PARALLEL) kernels in parallel)
310 # TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template
312 # $(1) is the name of the makefile target to invoke for the each build config
313 # after setting up the parallel hierarchy in the TARGET directory
314 # $(2) is an optional suffix on the TARGET directory, which might even be
316 # $(3) are any dependencies for the bootstrap target
317 # $(4) are any dependencies that are expanded per-build config to another bootstrap target
318 # $(5) is how many build configurations to build in parallel
319 # $(6) is which build configs to build in parallel
321 # Since building many configurations in parallel may overwhelm the system,
322 # we try to throttle behavior into more managable S "stripes" of N/S
323 # configurations by generating sequential dependencies between configs
324 # in each stripe. That ensures that only S kernel builds are occurring
325 # at once at any point in time
327 define TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template
329 # Create a list of synthesized targets for each build config
330 $(1)_bootstrap_target_list = $$(addprefix $(1)_bootstrap_,$(6))
332 .PHONY: $$($(1)_bootstrap_target_list)
334 $(1)_generated_stripe_dependencies = $$(call _function_generate_stripe_groupings,$(1),$(5),$(call reverse,$(6)))
335 ifeq ($$(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
336 $$(warning Generate makefile fragment: $$($(1)_generated_stripe_dependencies))
338 $$(eval $$($(1)_generated_stripe_dependencies))
340 $$($(1)_bootstrap_target_list): $(1)_bootstrap_% : $(1)_stripe_dep_for_% $$(addsuffix _bootstrap_%,$(4)) $(3)
341 $$(_v)$$(MKDIR) $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)
343 -C $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2) \
344 -f $${SRCROOT}/Makefile \
345 CURRENT_KERNEL_CONFIG=$$(call function_extract_kernel_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
346 CURRENT_ARCH_CONFIG=$$(call function_extract_arch_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
347 CURRENT_MACHINE_CONFIG=$$(call function_extract_machine_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
348 CURRENT_BUILD_CONFIG=$$(patsubst $(1)_bootstrap_%,%,$$@) \
349 PRIMARY_BUILD_CONFIGS="$(PRIMARY_BUILD_CONFIGS)" \
350 SOURCE=$${SRCROOT}/ \
351 RELATIVE_SOURCE_PATH=. \
352 TARGET=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)/ \
353 OBJPATH=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
356 .PHONY: $(1)_bootstrap
358 $(1)_bootstrap: $$($(1)_bootstrap_target_list)
362 # TOP_LEVEL_STRIPE_DEPENDENCY_template
364 # $(1) is the Makefile target we are building for
365 # $(2) is the build config that must build first
366 # $(3) is the build config that must build after $(2)
368 define TOP_LEVEL_STRIPE_DEPENDENCY_template
370 .PHONY: $(1)_stripe_dep_for_$(3)
372 $(1)_stripe_dep_for_$(3): $(if $(2),$(1)_bootstrap_$(2))
376 # $(1) is the Makefile target we are building for
377 # $(2) is the stripe size
378 # $(3) is the list of the build configs in the current group
379 # $(4) is the list of remaining build configs
380 _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))))
382 # $(1) is the Makefile target we are building for
383 # $(2) is the stripe size
384 # $(3) is the list of the build configs
385 _function_generate_stripe_groupings = $(call _function_generate_stripe_groupings_recursive,$(1),$(2),,$(3))
388 # Setup pass for build system tools
391 generated_top_level_build_setup = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_setup,/..,,,1,$(FIRST_BUILD_CONFIG))
392 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
393 $(warning Generate makefile fragment: $(generated_top_level_build_setup))
395 $(eval $(generated_top_level_build_setup))
399 # invalidate current kernel in $(SYMROOT). Timestamp must be +1 from a previous kernel build
400 setup: build_setup_bootstrap
401 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new
402 $(_v)while [ \! $(OBJROOT)/.mach_kernel.timestamp.new -nt $(OBJROOT)/.mach_kernel.timestamp ]; do \
404 $(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new; \
406 $(_v)$(MV) $(OBJROOT)/.mach_kernel.timestamp.new $(OBJROOT)/.mach_kernel.timestamp
407 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp.new
408 $(_v)while [ \! $(OBJROOT)/.symbolset.timestamp.new -nt $(OBJROOT)/.symbolset.timestamp ]; do \
410 $(TOUCH) $(OBJROOT)/.symbolset.timestamp.new; \
412 $(_v)$(MV) $(OBJROOT)/.symbolset.timestamp.new $(OBJROOT)/.symbolset.timestamp
415 # Install kernel header files
417 .PHONY: exporthdrs exporthdrs_mi exporthdrs_md
419 exporthdrs: exporthdrs_mi exporthdrs_md
422 # Install machine independent kernel header files
425 generated_top_level_build_exporthdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_mi,,setup,,1,$(FIRST_BUILD_CONFIG))
426 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
427 $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_mi))
429 $(eval $(generated_top_level_build_exporthdrs_mi))
431 exporthdrs_mi: build_exporthdrs_mi_bootstrap
434 # Install machine dependent kernel header files
437 generated_top_level_build_exporthdrs_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_md,,setup,,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS))
438 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
439 $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_md))
441 $(eval $(generated_top_level_build_exporthdrs_md))
443 exporthdrs_md: build_exporthdrs_md_bootstrap
446 # Install kernel header files
449 .PHONY: installhdrs installhdrs_mi installhdrs_md
451 ifneq ($(filter $(RC_ProjectName),xnu_debug),)
454 else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
459 installhdrs: installhdrs_mi installhdrs_md
462 .PHONY: installhdrs_embedded installhdrs_release_embedded installhdrs_development_embedded installhdrs_desktop
464 installhdrs_embedded installhdrs_release_embedded installhdrs_desktop: installhdrs
466 installhdrs_development_embedded:
469 # Install machine independent header files
472 generated_top_level_build_installhdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_installhdrs_mi,,setup,build_exporthdrs_mi,1,$(FIRST_BUILD_CONFIG))
473 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
474 $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_mi))
476 $(eval $(generated_top_level_build_installhdrs_mi))
478 installhdrs_mi: build_installhdrs_mi_bootstrap
481 # Install machine dependent kernel header files
484 generated_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))
485 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
486 $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_md))
488 $(eval $(generated_top_level_build_installhdrs_md))
490 installhdrs_md: build_installhdrs_md_bootstrap
492 .PHONY: install_textfiles install_textfiles_mi install_textfiles_md
494 install_textfiles: install_textfiles_mi install_textfiles_md
497 # Install machine independent text files (man pages, dtrace scripts, etc.)
500 generated_top_level_textfiles_install_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install_mi,,setup,,1,$(FIRST_BUILD_CONFIG))
501 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
502 $(warning Generate makefile fragment: $(generated_top_level_textfiles_install_mi))
504 $(eval $(generated_top_level_textfiles_install_mi))
506 install_textfiles_mi: textfiles_install_mi_bootstrap
509 # Install machine dependent text files (man pages, dtrace scripts, etc.)
512 generated_top_level_textfiles_install_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install_md,,setup,,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS))
513 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
514 $(warning Generate makefile fragment: $(generated_top_level_textfiles_install_md))
516 $(eval $(generated_top_level_textfiles_install_md))
518 install_textfiles_md: textfiles_install_md_bootstrap
521 # Build all architectures for all Configuration/Architecture options
524 generated_top_level_build_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_all,,setup exporthdrs,,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS))
525 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
526 $(warning Generate makefile fragment: $(generated_top_level_build_all))
528 $(eval $(generated_top_level_build_all))
532 build: build_all_bootstrap
535 # Post-process build results
538 generated_top_level_config_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_all,,setup,build_all,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS))
539 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
540 $(warning Generate makefile fragment: $(generated_top_level_config_all))
542 $(eval $(generated_top_level_config_all))
546 all config: config_all_bootstrap
548 .PHONY: all_embedded all_release_embedded all_development_embedded all_desktop
550 all_embedded all_release_embedded all_development_embedded all_desktop: all
553 # Install kernel files
556 generated_top_level_build_install_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_install_primary,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS))
557 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
558 $(warning Generate makefile fragment: $(generated_top_level_build_install_primary))
560 $(eval $(generated_top_level_build_install_primary))
562 .PHONY: install_primary
564 install_primary: build_install_primary_bootstrap
566 generated_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))
567 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
568 $(warning Generate makefile fragment: $(generated_top_level_build_install_non_primary))
570 $(eval $(generated_top_level_build_install_non_primary))
572 .PHONY: install_non_primary
574 install_non_primary: build_install_non_primary_bootstrap
576 generated_top_level_config_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS))
577 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
578 $(warning Generate makefile fragment: $(generated_top_level_config_install))
580 $(eval $(generated_top_level_config_install))
582 .PHONY: install_config final_touch_config_timestamps
584 install_config: config_install_bootstrap final_touch_config_timestamps
586 # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT
587 final_touch_config_timestamps: config_install_bootstrap
588 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp
591 # Aggregate install targets, which install everything appropriate for the current build alias/make target
596 ifneq ($(filter $(RC_ProjectName),xnu_debug),)
597 install: install_kernels
598 else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
599 install: install_config install_kernels
600 else ifneq ($(filter $(RC_ProjectName),xnu_headers_Sim),)
602 else ifneq ($(filter $(RC_ProjectName),xnu_headers_host),)
604 export INSTALLHDRS_SKIP_HOST=YES
605 else ifneq ($(filter $(RC_ProjectName),xnu_headers_driverkit),)
606 install: installhdrs_desktop
609 install: installhdrs install_textfiles install_config install_kernels install_aliases checkstyle
612 .PHONY: install_embedded install_release_embedded install_development_embedded install_desktop
614 # By default, all kernel files, headers, text files, and pseudo-kexts are installed
615 install_embedded install_release_embedded install_desktop: install
617 # These special configs only install the kernel files
618 install_development_embedded: install_kernels install_aliases
620 .PHONY: install_kernels final_touch_kernel_timestamps install_aliases
622 install_kernels: build_install_primary_bootstrap build_install_non_primary_bootstrap final_touch_kernel_timestamps
624 # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT
625 final_touch_kernel_timestamps: build_install_primary_bootstrap build_install_non_primary_bootstrap
626 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp
627 @echo "done building xnu"
629 # Copy kernels that are aliases of another configuration
630 generated_top_level_install_alias = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,install_alias,,install_kernels,,$(KERNEL_BUILDS_IN_PARALLEL),$(ALIAS_CONFIGS))
631 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
632 $(warning Generate makefile fragment: $(generated_top_level_install_alias))
634 $(eval $(generated_top_level_install_alias))
636 install_aliases: install_alias_bootstrap
639 # Install source tree
644 @echo INSTALLSRC $(SRCROOT)
645 $(_v)$(MKDIR) $(SRCROOT)
646 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
647 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
651 # Clean up source tree
655 CLEAN_RM_DIRS= $(OBJROOT) $(SYMROOT) $(DSTROOT) \
656 $(SRCROOT)/tools/test/BUILD \
657 $(SRCROOT)/tools/tests/darwintests/build \
658 $(SRCROOT)/tools/tests/testkext/build \
659 $(SRCROOT)/libkdd/build \
660 $(SRCROOT)/tools/tests/unit_tests/BUILD \
661 $(SRCROOT)/tools/tests/execperf/BUILD \
662 $(SRCROOT)/tools/tests/packetdrill/BUILD \
663 $(SRCROOT)/tools/tests/perf_index/BUILD
665 CLEAN_ACTION_DIRS= $(SRCROOT)/tools/tests/MPMMTest \
666 $(SRCROOT)/tools/tests/TLBcoherency \
667 $(SRCROOT)/tools/tests/kqueue_tests \
668 $(SRCROOT)/tools/tests/mktimer \
669 $(SRCROOT)/tools/tests/zero-to-n \
670 $(SRCROOT)/tools/tests/personas
674 $(_v)rm -f cscope.* 2> /dev/null
675 $(_v)rm -f TAGS 2> /dev/null
676 $(_v)for cdir in $(CLEAN_RM_DIRS); do \
677 if [ -d $${cdir} ] ; then \
678 echo "Removing $${cdir}"; \
679 rm -fr $${cdir} 2> /dev/null || true ; \
683 $(_v)for mcdir in $(CLEAN_ACTION_DIRS); do \
684 make -C $${mcdir} clean; \
689 # Build source file list for cscope database and tags
694 @echo "Building file list for cscope and tags"
695 @find . -name '*.h' -type f | grep -v ^..BUILD > _cscope.files 2> /dev/null
696 @find . -name '*.defs' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
697 @find . -name '*.c' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
698 @find . -name '*.cpp' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
699 @find . -name '*.s' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
700 @find . -name '*.h.template' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
701 @cat $(OBJROOT)/cscope.genhdrs/* >> _cscope.files 2> /dev/null || true
702 @echo -k -q -c > cscope.files 2> /dev/null
703 @sort -u < _cscope.files >> cscope.files 2> /dev/null
704 @rm -f _cscope.files _cscope.files2 2> /dev/null
707 # Build cscope database
710 @echo "Building cscope database"
711 @cscope -bvU 2> /dev/null
717 @echo "Building ctags"
718 @-sed 1d cscope.files | xargs ctags -dtw 2> /dev/null || \
719 echo "Phantom files detected!" 2>&1 > /dev/null
720 @-[ -f TAGS ] || ${MAKE} -f $(firstword $(MAKEFILE_LIST)) TAGS
723 @echo "Building etags"
724 @-cat cscope.files | etags -l auto -S - 2> /dev/null
725 @rm -f cscope.files 2> /dev/null
728 # Check or reformat source code for official xnu code style
730 .PHONY: checkstyle restyle check_uncrustify uncrustify
732 # User-friendly aliases for those who prefer to remember the name of the tool.
733 check_uncrustify: checkstyle
737 ${_V}$(SRCROOT)/tools/uncrustify.sh
740 ${_V}$(SRCROOT)/tools/uncrustify.sh -f
747 .PHONY: print_exports
752 generated_top_level_print_exports = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,print_exports,,,,1,$(FIRST_BUILD_CONFIG))
753 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
754 $(warning Generate makefile fragment: $(generated_top_level_print_exports))
756 $(eval $(generated_top_level_print_exports))
758 .PHONY: print_exports_first_build_config
760 print_exports_first_build_config: print_exports_bootstrap