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