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