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 ifeq ($(RC_ProjectName),xnu_debug)
62 override DEFAULT_KERNEL_CONFIG := DEBUG
63 else ifeq ($(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
90 override DEFAULT_ARM_MACHINE_CONFIG := T8002
91 override DEFAULT_ARM64_MACHINE_CONFIG := T7000
93 # This is typically never specified (TARGET_CONFIGS is used)
94 ifndef MACHINE_CONFIGS
95 MACHINE_CONFIGS := DEFAULT
99 # Target configuration options. NOTE - target configurations will
100 # override ARCH_CONFIGS and KERNEL_CONFIGS and MACHINE_CONFIGS.
102 # Target configs come in groups of three parameters. The first is the
103 # kernel configuration, the second is the architecture configuration,
104 # and the third is the machine configuration. You may pass in as
105 # many groups of configurations as you wish. Each item passed in is
106 # seperated by whitespace.
109 # TARGET_CONFIGS="release ppc default debug i386 default release arm MX31ADS"
110 # Parameters may be in upper or lower case (they are converted to upper).
112 # "default" parameter is a special case. It means use the default value for
113 # that parameter. Here are the default values for each configuration:
115 # default kernel configuration = DEFAULT_KERNEL_CONFIG
116 # default architecture configuration = system architecture where you are running make.
118 ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
120 # Defaults for "make all_embedded"
121 ifeq ($(KERNEL_CONFIGS),DEFAULT)
122 KERNEL_CONFIGS_EMBEDDED := RELEASE DEVELOPMENT
124 KERNEL_CONFIGS_EMBEDDED := $(KERNEL_CONFIGS)
127 ifeq ($(ARCH_CONFIGS),DEFAULT)
128 ARCH_CONFIGS_EMBEDDED := ARM ARM64
130 ARCH_CONFIGS_EMBEDDED := $(strip $(shell echo $(ARCH_CONFIGS) | $(TR) a-z A-Z))
133 # Find supported products from the device map
134 DEVICEMAP_PRODUCTS_ARMV7 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
135 -query 'SELECT DISTINCT TargetType \
137 INNER JOIN Manifests USING (manifestID) \
138 INNER JOIN Targets USING (Target) \
139 WHERE (KernelMachOArchitecture LIKE "armv7" \
140 AND fileType in ("KernelCache", "RestoreKernelCache"))')
141 DEVICEMAP_PRODUCTS_ARMV7S := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
142 -query 'SELECT DISTINCT TargetType \
144 INNER JOIN Manifests USING (manifestID) \
145 INNER JOIN Targets USING (Target) \
146 WHERE (KernelMachOArchitecture LIKE "armv7s" \
147 AND fileType in ("KernelCache", "RestoreKernelCache"))')
148 DEVICEMAP_PRODUCTS_ARMV7K := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
149 -query 'SELECT DISTINCT TargetType \
151 INNER JOIN Manifests USING (manifestID) \
152 INNER JOIN Targets USING (Target) \
153 WHERE (KernelMachOArchitecture LIKE "armv7k" \
154 AND fileType in ("KernelCache", "RestoreKernelCache"))')
155 DEVICEMAP_PRODUCTS_ARM := $(DEVICEMAP_PRODUCTS_ARMV7) $(DEVICEMAP_PRODUCTS_ARMV7S) $(DEVICEMAP_PRODUCTS_ARMV7K)
158 DEVICEMAP_PRODUCTS_ARM64 := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
159 -query 'SELECT DISTINCT TargetType \
161 INNER JOIN Manifests USING (manifestID) \
162 INNER JOIN Targets USING (Target) \
163 WHERE (KernelMachOArchitecture LIKE "arm64" \
164 AND fileType in ("KernelCache", "RestoreKernelCache"))')
167 # Generate a list of mappings of the form "n75:arm;t8002" based on the device map
168 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} }' )
170 # Map a product like "n75" to "arm;t8002"
171 # $(1) is a product name in lower case
172 function_lookup_product = $(call function_substitute_word_with_replacement, \
174 $(DEVICEMAP_PRODUCT_SOC_MAPPINGS), \
175 unknown_arch_for_$(1);unknown_platform_for_$(1) \
178 # Generate a list of mappings for products that use a different platform for their kernel configuration than their true platform
179 # of the form "n71m:arm64;s8000;s8003". The 4th element is the true SoC platform, which will get an on-disk copy, while the
180 # kernel's recursive build system will build the 3rd element as the KernelPlatform
181 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} }' )
183 function_lookup_product_alias = $(call function_substitute_word_with_replacement, \
185 $(DEVICEMAP_PRODUCT_SOC_ALIASES), \
189 ifeq ($(PLATFORM),MacOSX)
191 # Defaults for "make all_desktop"
192 ifeq ($(KERNEL_CONFIGS),DEFAULT)
193 KERNEL_CONFIGS_DESKTOP := RELEASE DEVELOPMENT
195 KERNEL_CONFIGS_DESKTOP := $(KERNEL_CONFIGS)
200 ifndef TARGET_CONFIGS
201 ifneq ($(PRODUCT_CONFIGS),)
202 # generate TARGET_CONFIGS using KERNEL_CONFIGS and PRODUCT_CONFIGS
203 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))))
204 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))))
205 else ifneq ($(filter %_release_embedded,$(MAKECMDGOALS)),)
206 # generate TARGET_CONFIGS for RELEASE kernel configs and products in the device map
207 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))))
208 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))))
209 else ifneq ($(filter %_development_embedded,$(MAKECMDGOALS)),)
210 # generate TARGET_CONFIGS for DEVELOPMENT kernel configs and products in the device map
211 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))))
212 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))))
213 else ifneq ($(filter %_embedded,$(MAKECMDGOALS)),)
214 # generate TARGET_CONFIGS for all kernel configs and products in the device map
215 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))))
216 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))))
217 else ifneq ($(filter %_desktop,$(MAKECMDGOALS)),)
218 # generate TARGET_CONFIGS for all kernel configs for B&I
219 TARGET_CONFIGS := $(foreach my_kern_config, $(KERNEL_CONFIGS_DESKTOP), $(foreach my_arch_config, $(ARCH_CONFIGS), $(foreach my_machine_config, $(MACHINE_CONFIGS), $(my_kern_config) $(my_arch_config) $(my_machine_config))))
220 TARGET_CONFIGS_ALIASES :=
222 # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIGS (which defaults to "DEFAULT")
223 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))))
224 TARGET_CONFIGS_ALIASES :=
228 ifeq ($(TARGET_CONFIGS),)
229 $(error No TARGET_CONFIGS specified)
232 TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z))
233 TARGET_CONFIGS_ALIASES_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS_ALIASES)" | $(TR) a-z A-Z))
236 # Build Configurations
238 # TARGET_CONFIGS is unwieldy for use in Makefiles. Convert them to
239 # "build configurations" which are tuples joined by "^". For
240 # example, "RELEASE I386 DEFAULT DEVELOPMENT ARM DEFAULT" becomes
241 # "RELEASE^I386^NONE DEVELOPMENT^ARM^T8002", which can be looped
242 # over trivially. PRIMARY_BUILD_CONFIGS is the first config
243 # for each architecture, used primarily for machine-dependent recursion.
245 BUILD_CONFIGS = $(call function_create_build_configs, $(TARGET_CONFIGS_UC))
247 PRIMARY_ARCHS = $(strip $(sort $(foreach build_config, $(BUILD_CONFIGS), $(call function_extract_arch_config_from_build_config, $(build_config)))))
248 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), )))))
249 NON_PRIMARY_BUILD_CONFIGS = $(strip $(filter-out $(PRIMARY_BUILD_CONFIGS), $(BUILD_CONFIGS)))
250 FIRST_BUILD_CONFIG = $(firstword $(BUILD_CONFIGS))
252 ifneq ($(TARGET_CONFIGS_ALIASES_UC),)
253 ALIAS_CONFIGS = $(call function_create_alias_configs, $(TARGET_CONFIGS_ALIASES_UC))
258 # $(warning PRIMARY_ARCHS is $(PRIMARY_ARCHS))
259 # $(warning TARGET_CONFIGS is $(TARGET_CONFIGS))
260 # $(warning BUILD_CONFIGS is $(BUILD_CONFIGS))
261 # $(warning PRIMARY_BUILD_CONFIGS is $(PRIMARY_BUILD_CONFIGS))
262 # $(warning NON_PRIMARY_BUILD_CONFIGS is $(NON_PRIMARY_BUILD_CONFIGS))
263 # $(warning TARGET_CONFIGS_ALIASES is $(TARGET_CONFIGS_ALIASES))
264 # $(warning ALIAS_CONFIGS is $(ALIAS_CONFIGS))
266 MEMORY_SIZE := $(shell /usr/sbin/sysctl -n hw.memsize)
268 # Assume LTO scaling by default, unless it is being explicitly passed on the command-line
269 LARGE_BUILD_FOOTPRINT := $(if $(BUILD_LTO),$(BUILD_LTO),1)
271 ifeq ($(LARGE_BUILD_FOOTPRINT),1)
272 RAM_PER_KERNEL_BUILD := 4294967296
274 RAM_PER_KERNEL_BUILD := 268435456
277 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 )
278 # $(warning Building $(KERNEL_BUILDS_IN_PARALLEL) kernels in parallel)
281 # TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template
283 # $(1) is the name of the makefile target to invoke for the each build config
284 # after setting up the parallel hierarchy in the TARGET directory
285 # $(2) is an optional suffix on the TARGET directory, which might even be
287 # $(3) are any dependencies for the bootstrap target
288 # $(4) are any dependencies that are expanded per-build config to another bootstrap target
289 # $(5) is how many build configurations to build in parallel
290 # $(6) is which build configs to build in parallel
292 # Since building many configurations in parallel may overwhelm the system,
293 # we try to throttle behavior into more managable S "stripes" of N/S
294 # configurations by generating sequential dependencies between configs
295 # in each stripe. That ensures that only S kernel builds are occurring
296 # at once at any point in time
298 define TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template
300 # Create a list of synthesized targets for each build config
301 $(1)_bootstrap_target_list = $$(addprefix $(1)_bootstrap_,$(6))
303 .PHONY: $$($(1)_bootstrap_target_list)
305 $(1)_generated_stripe_dependencies = $$(call _function_generate_stripe_groupings,$(1),$(5),$(call reverse,$(6)))
306 ifeq ($$(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
307 $$(warning Generate makefile fragment: $$($(1)_generated_stripe_dependencies))
309 $$(eval $$($(1)_generated_stripe_dependencies))
311 $$($(1)_bootstrap_target_list): $(1)_bootstrap_% : $(1)_stripe_dep_for_% $$(addsuffix _bootstrap_%,$(4)) $(3)
312 $$(_v)$$(MKDIR) $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)
314 -C $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2) \
315 -f $${SRCROOT}/Makefile \
316 CURRENT_KERNEL_CONFIG=$$(call function_extract_kernel_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
317 CURRENT_ARCH_CONFIG=$$(call function_extract_arch_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
318 CURRENT_MACHINE_CONFIG=$$(call function_extract_machine_config_from_build_config,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
319 CURRENT_BUILD_CONFIG=$$(patsubst $(1)_bootstrap_%,%,$$@) \
320 PRIMARY_BUILD_CONFIGS="$(PRIMARY_BUILD_CONFIGS)" \
321 SOURCE=$${SRCROOT}/ \
322 RELATIVE_SOURCE_PATH=. \
323 TARGET=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)/ \
324 OBJPATH=$${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@)) \
327 .PHONY: $(1)_bootstrap
329 $(1)_bootstrap: $$($(1)_bootstrap_target_list)
333 # TOP_LEVEL_STRIPE_DEPENDENCY_template
335 # $(1) is the Makefile target we are building for
336 # $(2) is the build config that must build first
337 # $(3) is the build config that must build after $(2)
339 define TOP_LEVEL_STRIPE_DEPENDENCY_template
341 .PHONY: $(1)_stripe_dep_for_$(3)
343 $(1)_stripe_dep_for_$(3): $(if $(2),$(1)_bootstrap_$(2))
347 # $(1) is the Makefile target we are building for
348 # $(2) is the stripe size
349 # $(3) is the list of the build configs in the current group
350 # $(4) is the list of remaining build configs
351 _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))))
353 # $(1) is the Makefile target we are building for
354 # $(2) is the stripe size
355 # $(3) is the list of the build configs
356 _function_generate_stripe_groupings = $(call _function_generate_stripe_groupings_recursive,$(1),$(2),,$(3))
359 # Setup pass for build system tools
362 generated_top_level_build_setup = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_setup,/..,,,1,$(FIRST_BUILD_CONFIG))
363 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
364 $(warning Generate makefile fragment: $(generated_top_level_build_setup))
366 $(eval $(generated_top_level_build_setup))
370 # invalidate current kernel in $(SYMROOT). Timestamp must be +1 from a previous kernel build
371 setup: build_setup_bootstrap
372 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new
373 $(_v)while [ \! $(OBJROOT)/.mach_kernel.timestamp.new -nt $(OBJROOT)/.mach_kernel.timestamp ]; do \
375 $(TOUCH) $(OBJROOT)/.mach_kernel.timestamp.new; \
377 $(_v)$(MV) $(OBJROOT)/.mach_kernel.timestamp.new $(OBJROOT)/.mach_kernel.timestamp
378 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp.new
379 $(_v)while [ \! $(OBJROOT)/.symbolset.timestamp.new -nt $(OBJROOT)/.symbolset.timestamp ]; do \
381 $(TOUCH) $(OBJROOT)/.symbolset.timestamp.new; \
383 $(_v)$(MV) $(OBJROOT)/.symbolset.timestamp.new $(OBJROOT)/.symbolset.timestamp
386 # Install kernel header files
388 .PHONY: exporthdrs exporthdrs_mi exporthdrs_md
390 exporthdrs: exporthdrs_mi exporthdrs_md
393 # Install machine independent kernel header files
396 generated_top_level_build_exporthdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_mi,,setup,,1,$(FIRST_BUILD_CONFIG))
397 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
398 $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_mi))
400 $(eval $(generated_top_level_build_exporthdrs_mi))
402 exporthdrs_mi: build_exporthdrs_mi_bootstrap
405 # Install machine dependent kernel header files
408 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))
409 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
410 $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_md))
412 $(eval $(generated_top_level_build_exporthdrs_md))
414 exporthdrs_md: build_exporthdrs_md_bootstrap
417 # Install kernel header files
420 .PHONY: installhdrs installhdrs_mi installhdrs_md
422 ifeq ($(RC_ProjectName),xnu_debug)
425 else ifeq ($(RC_ProjectName),xnu_kasan)
430 installhdrs: installhdrs_mi installhdrs_md
433 .PHONY: installhdrs_embedded installhdrs_release_embedded installhdrs_development_embedded installhdrs_desktop
435 installhdrs_embedded installhdrs_release_embedded installhdrs_desktop: installhdrs
437 installhdrs_development_embedded:
440 # Install machine independent header files
443 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))
444 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
445 $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_mi))
447 $(eval $(generated_top_level_build_installhdrs_mi))
449 installhdrs_mi: build_installhdrs_mi_bootstrap
452 # Install machine dependent kernel header files
455 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))
456 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
457 $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_md))
459 $(eval $(generated_top_level_build_installhdrs_md))
461 installhdrs_md: build_installhdrs_md_bootstrap
464 # Install text files (man pages, dtrace scripts, etc.)
467 generated_top_level_textfiles_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install,,setup,,1,$(FIRST_BUILD_CONFIG))
468 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
469 $(warning Generate makefile fragment: $(generated_top_level_textfiles_install))
471 $(eval $(generated_top_level_textfiles_install))
473 .PHONY: install_textfiles
475 install_textfiles: textfiles_install_bootstrap
478 # Build all architectures for all Configuration/Architecture options
481 generated_top_level_build_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_all,,setup exporthdrs,,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS))
482 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
483 $(warning Generate makefile fragment: $(generated_top_level_build_all))
485 $(eval $(generated_top_level_build_all))
489 build: build_all_bootstrap
492 # Post-process build results
495 generated_top_level_config_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_all,,setup,build_all,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS))
496 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
497 $(warning Generate makefile fragment: $(generated_top_level_config_all))
499 $(eval $(generated_top_level_config_all))
503 all config: config_all_bootstrap
505 .PHONY: all_embedded all_release_embedded all_development_embedded all_desktop
507 all_embedded all_release_embedded all_development_embedded all_desktop: all
510 # Install kernel files
513 generated_top_level_build_install_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_install_primary,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS))
514 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
515 $(warning Generate makefile fragment: $(generated_top_level_build_install_primary))
517 $(eval $(generated_top_level_build_install_primary))
519 .PHONY: install_primary
521 install_primary: build_install_primary_bootstrap
523 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))
524 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
525 $(warning Generate makefile fragment: $(generated_top_level_build_install_non_primary))
527 $(eval $(generated_top_level_build_install_non_primary))
529 .PHONY: install_non_primary
531 install_non_primary: build_install_non_primary_bootstrap
533 generated_top_level_config_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS))
534 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
535 $(warning Generate makefile fragment: $(generated_top_level_config_install))
537 $(eval $(generated_top_level_config_install))
539 .PHONY: install_config final_touch_config_timestamps
541 install_config: config_install_bootstrap final_touch_config_timestamps
543 # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT
544 final_touch_config_timestamps: config_install_bootstrap
545 $(_v)$(TOUCH) $(OBJROOT)/.symbolset.timestamp
548 # Aggregate install targets, which install everything appropriate for the current build alias/make target
553 ifeq ($(RC_ProjectName),xnu_debug)
554 install: install_kernels
555 else ifeq ($(RC_ProjectName),xnu_kasan)
556 install: install_config install_kernels
557 else ifeq ($(RC_ProjectName),xnu_headers_Sim)
559 else ifeq ($(RC_ProjectName),xnu_headers_host)
561 export INSTALLHDRS_SKIP_HOST=YES
562 else ifeq ($(RC_ProjectName),xnu_headers_driverkit)
563 install: installhdrs_desktop
566 install: installhdrs install_textfiles install_config install_kernels install_aliases checkstyle
569 .PHONY: install_embedded install_release_embedded install_development_embedded install_desktop
571 # By default, all kernel files, headers, text files, and pseudo-kexts are installed
572 install_embedded install_release_embedded install_desktop: install
574 # These special configs only install the kernel files
575 install_development_embedded: install_kernels install_aliases
577 .PHONY: install_kernels final_touch_kernel_timestamps install_aliases
579 install_kernels: build_install_primary_bootstrap build_install_non_primary_bootstrap final_touch_kernel_timestamps
581 # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT
582 final_touch_kernel_timestamps: build_install_primary_bootstrap build_install_non_primary_bootstrap
583 $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp
585 # Copy kernels that are aliases of another configuration
586 generated_top_level_install_alias = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,install_alias,,install_kernels,,$(KERNEL_BUILDS_IN_PARALLEL),$(ALIAS_CONFIGS))
587 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
588 $(warning Generate makefile fragment: $(generated_top_level_install_alias))
590 $(eval $(generated_top_level_install_alias))
592 install_aliases: install_alias_bootstrap
595 # Install source tree
600 @echo INSTALLSRC $(SRCROOT)
601 $(_v)$(MKDIR) $(SRCROOT)
602 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
603 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
607 # Clean up source tree
611 CLEAN_RM_DIRS= $(OBJROOT) $(SYMROOT) $(DSTROOT) \
612 $(SRCROOT)/tools/test/BUILD \
613 $(SRCROOT)/tools/tests/darwintests/build \
614 $(SRCROOT)/tools/tests/testkext/build \
615 $(SRCROOT)/libkdd/build \
616 $(SRCROOT)/tools/tests/unit_tests/BUILD \
617 $(SRCROOT)/tools/tests/execperf/BUILD \
618 $(SRCROOT)/tools/tests/packetdrill/BUILD \
619 $(SRCROOT)/tools/tests/perf_index/BUILD
621 CLEAN_ACTION_DIRS= $(SRCROOT)/tools/tests/MPMMTest \
622 $(SRCROOT)/tools/tests/TLBcoherency \
623 $(SRCROOT)/tools/tests/kqueue_tests \
624 $(SRCROOT)/tools/tests/mktimer \
625 $(SRCROOT)/tools/tests/zero-to-n \
626 $(SRCROOT)/tools/tests/personas
630 $(_v)rm -f cscope.* 2> /dev/null
631 $(_v)rm -f TAGS 2> /dev/null
632 $(_v)for cdir in $(CLEAN_RM_DIRS); do \
633 if [ -d $${cdir} ] ; then \
634 echo "Removing $${cdir}"; \
635 rm -fr $${cdir} 2> /dev/null || true ; \
639 $(_v)for mcdir in $(CLEAN_ACTION_DIRS); do \
640 make -C $${mcdir} clean; \
645 # Build source file list for cscope database and tags
650 @echo "Building file list for cscope and tags"
651 @find . -name '*.h' -type f | grep -v ^..BUILD > _cscope.files 2> /dev/null
652 @find . -name '*.defs' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
653 @find . -name '*.c' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
654 @find . -name '*.cpp' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
655 @find . -name '*.s' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
656 @find . -name '*.h.template' -type f | grep -v ^..BUILD >> _cscope.files 2> /dev/null
657 @cat $(OBJROOT)/cscope.genhdrs/* >> _cscope.files 2> /dev/null || true
658 @echo -k -q -c > cscope.files 2> /dev/null
659 @sort -u < _cscope.files >> cscope.files 2> /dev/null
660 @rm -f _cscope.files _cscope.files2 2> /dev/null
663 # Build cscope database
666 @echo "Building cscope database"
667 @cscope -bvU 2> /dev/null
673 @echo "Building ctags"
674 @-sed 1d cscope.files | xargs ctags -dtw 2> /dev/null || \
675 echo "Phantom files detected!" 2>&1 > /dev/null
676 @-[ -f TAGS ] || ${MAKE} -f $(firstword $(MAKEFILE_LIST)) TAGS
679 @echo "Building etags"
680 @-cat cscope.files | etags -l auto -S - 2> /dev/null
681 @rm -f cscope.files 2> /dev/null
684 # Check or reformat source code for official xnu code style
686 .PHONY: checkstyle restyle check_uncrustify uncrustify
688 # User-friendly aliases for those who prefer to remember the name of the tool.
689 check_uncrustify: checkstyle
693 ${_V}$(SRCROOT)/tools/uncrustify.sh
696 ${_V}$(SRCROOT)/tools/uncrustify.sh -f
703 .PHONY: print_exports
708 generated_top_level_print_exports = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,print_exports,,,,1,$(FIRST_BUILD_CONFIG))
709 ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
710 $(warning Generate makefile fragment: $(generated_top_level_print_exports))
712 $(eval $(generated_top_level_print_exports))
714 .PHONY: print_exports_first_build_config
716 print_exports_first_build_config: print_exports_bootstrap