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