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