]> git.saurik.com Git - apple/xnu.git/blame_incremental - makedefs/MakeInc.top
xnu-7195.101.1.tar.gz
[apple/xnu.git] / makedefs / MakeInc.top
... / ...
CommitLineData
1# -*- mode: makefile;-*-
2#
3# Copyright (C) 2010-2020 Apple Inc. All rights reserved.
4#
5# MakeInc.top is the top-level makefile for the xnu
6# build system. All the main XBS targets
7# (like "installhdrs") are defined here, as
8# well as globals that can be overridden on
9# the command-line by the user.
10#
11# This makefile's main purpose is to bootstrap
12# the user's intent ("build these 3 kernels")
13# into 3 single-architecture builds that each
14# invoke the recursive make build system.
15# As such, we have no knowledge of how to build
16# a kernel or perform actions other than
17# invoking a sub-make with a different
18# current directory, makefile, and target. One
19# side effect of this is that each
20# single-architecture build is responsible for
21# inserting its build products into the final
22# multi-architecture output files. To avoid
23# races, these aggregating stages for
24# "primary" build configs are done in serial.
25#
26
27export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd
28
29include $(MakeInc_cmd)
30
31
32#
33# Architecture Configuration options
34#
35
36# Default to current kernel architecture
37
38ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
39 override DEFAULT_ARCH_CONFIG := ARM
40else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
41 override DEFAULT_ARCH_CONFIG := X86_64
42else
43 override DEFAULT_ARCH_CONFIG := X86_64
44endif
45
46# Accept either explicit ARCH_CONFIGS or XBS-style RC_ARCHS
47ifndef ARCH_CONFIGS
48ifdef RC_ARCHS
49ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z | $(TR) " " "\n" | sort -u | $(TR) "\n" " ")
50else
51ARCH_CONFIGS := DEFAULT
52endif
53endif
54
55#
56# Kernel Configuration options
57#
58
59DEFAULT_PRODUCT_CONFIGS :=
60
61ifneq ($(filter $(RC_ProjectName),xnu_debug),)
62override DEFAULT_KERNEL_CONFIG := DEBUG
63else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
64override KERNEL_CONFIGS := KASAN
65else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
66override DEFAULT_KERNEL_CONFIG := DEVELOPMENT
67else ifeq ($(PLATFORM),MacOSX)
68override DEFAULT_KERNEL_CONFIG := DEVELOPMENT
69else
70override DEFAULT_KERNEL_CONFIG := RELEASE
71endif
72
73# If KERNEL_CONFIGS is specified it should override default
74ifndef KERNEL_CONFIGS
75KERNEL_CONFIGS := DEFAULT
76endif
77
78# If PRODUCT_CONFIGS is specified it should override default
79ifndef PRODUCT_CONFIGS
80PRODUCT_CONFIGS := $(DEFAULT_PRODUCT_CONFIGS)
81endif
82
83#
84# Machine Configuration options
85#
86
87override DEFAULT_I386_MACHINE_CONFIG := NONE
88override DEFAULT_X86_64_MACHINE_CONFIG := NONE
89override DEFAULT_X86_64H_MACHINE_CONFIG := NONE
90
91ifneq ($(findstring _Sim,$(RC_ProjectName)),)
92override DEFAULT_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
98override DEFAULT_ARM_MACHINE_CONFIG := T8002
99override DEFAULT_ARM64_MACHINE_CONFIG := T7000
100endif
101
102# This is typically never specified (TARGET_CONFIGS is used)
103ifndef MACHINE_CONFIGS
104MACHINE_CONFIGS := DEFAULT
105endif
106
107#
108# Target configuration options. NOTE - target configurations will
109# override ARCH_CONFIGS and KERNEL_CONFIGS and MACHINE_CONFIGS.
110#
111# Target configs come in groups of three parameters. The first is the
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#
121# "default" parameter is a special case. It means use the default value for
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
127ifneq ($(filter $(SUPPORTED_PLATFORMS),$(PLATFORM)),)
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
138ARCH_CONFIGS_DESKTOP := X86_64
139else
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))
142endif
143
144# Find supported products from the device map
145ifneq ($(EMBEDDED_DEVICE_MAP),)
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"))')
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")')
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
190# use embedded_device_map
191endif
192
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
201ifneq ($(PLATFORM),MacOSX)
202ifneq ($(EMBEDDED_DEVICE_MAP),)
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
208endif
209endif
210
211function_lookup_product_alias = $(call function_substitute_word_with_replacement, \
212 $(1), \
213 $(DEVICEMAP_PRODUCT_SOC_ALIASES), \
214 )
215endif
216
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
228ifndef TARGET_CONFIGS
229ifneq ($(PRODUCT_CONFIGS),)
230# generate TARGET_CONFIGS using KERNEL_CONFIGS and PRODUCT_CONFIGS
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))))
233else ifneq ($(filter %_release_embedded,$(MAKECMDGOALS)),)
234# generate TARGET_CONFIGS for RELEASE kernel configs and products in the device map
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))))
237else ifneq ($(filter %_development_embedded,$(MAKECMDGOALS)),)
238# generate TARGET_CONFIGS for DEVELOPMENT kernel configs and products in the device map
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))))
241else ifneq ($(filter %_embedded,$(MAKECMDGOALS)),)
242# generate TARGET_CONFIGS for all kernel configs and products in the device map
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))))
245else ifneq ($(filter %_desktop,$(MAKECMDGOALS)),)
246# generate TARGET_CONFIGS for all kernel configs for B&I
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))))
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))))
253TARGET_CONFIGS_ALIASES :=
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))
262TARGET_CONFIGS_ALIASES_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS_ALIASES)" | $(TR) a-z A-Z))
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
270# "RELEASE^I386^NONE DEVELOPMENT^ARM^T8002", which can be looped
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
281ifneq ($(TARGET_CONFIGS_ALIASES_UC),)
282ALIAS_CONFIGS = $(call function_create_alias_configs, $(TARGET_CONFIGS_ALIASES_UC))
283else
284ALIAS_CONFIGS =
285endif
286
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))
292# $(warning TARGET_CONFIGS_ALIASES is $(TARGET_CONFIGS_ALIASES))
293# $(warning ALIAS_CONFIGS is $(ALIAS_CONFIGS))
294
295MEMORY_SIZE := $(shell /usr/sbin/sysctl -n hw.memsize)
296
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)
299
300ifeq ($(LARGE_BUILD_FOOTPRINT),1)
301RAM_PER_KERNEL_BUILD := 4294967296
302else
303RAM_PER_KERNEL_BUILD := 268435456
304endif
305
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)
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,
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
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
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
340$$($(1)_bootstrap_target_list): $(1)_bootstrap_% : $(1)_stripe_dep_for_% $$(addsuffix _bootstrap_%,$(4)) $(3)
341 $$(_v)$$(MKDIR) $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2)
342 $$(_v)$${MAKE} \
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#
362# TOP_LEVEL_STRIPE_DEPENDENCY_template
363#
364# $(1) is the Makefile target we are building for
365# $(2) is the build config that must build first
366# $(3) is the build config that must build after $(2)
367
368define TOP_LEVEL_STRIPE_DEPENDENCY_template
369
370.PHONY: $(1)_stripe_dep_for_$(3)
371
372 $(1)_stripe_dep_for_$(3): $(if $(2),$(1)_bootstrap_$(2))
373
374endef
375
376# $(1) is the Makefile target we are building for
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
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))
386
387#
388# Setup pass for build system tools
389#
390
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)
393$(warning Generate makefile fragment: $(generated_top_level_build_setup))
394endif
395$(eval $(generated_top_level_build_setup))
396
397.PHONY: setup
398
399# invalidate current kernel in $(SYMROOT). Timestamp must be +1 from a previous kernel build
400setup: build_setup_bootstrap
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
413
414#
415# Install kernel header files
416#
417.PHONY: exporthdrs exporthdrs_mi exporthdrs_md
418
419exporthdrs: exporthdrs_mi exporthdrs_md
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))
426ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
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#
434# Install machine dependent kernel header files
435#
436
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)
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
451ifneq ($(filter $(RC_ProjectName),xnu_debug),)
452installhdrs:
453 @:
454else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
455installhdrs:
456 @:
457else
458
459installhdrs: installhdrs_mi installhdrs_md
460endif
461
462.PHONY: installhdrs_embedded installhdrs_release_embedded installhdrs_development_embedded installhdrs_desktop
463
464installhdrs_embedded installhdrs_release_embedded installhdrs_desktop: installhdrs
465
466installhdrs_development_embedded:
467
468#
469# Install machine independent header files
470#
471
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)
474$(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_mi))
475endif
476$(eval $(generated_top_level_build_installhdrs_mi))
477
478installhdrs_mi: build_installhdrs_mi_bootstrap
479
480#
481# Install machine dependent kernel header files
482#
483
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)
486$(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_md))
487endif
488$(eval $(generated_top_level_build_installhdrs_md))
489
490installhdrs_md: build_installhdrs_md_bootstrap
491
492.PHONY: install_textfiles install_textfiles_mi install_textfiles_md
493
494install_textfiles: install_textfiles_mi install_textfiles_md
495
496#
497# Install machine independent text files (man pages, dtrace scripts, etc.)
498#
499
500generated_top_level_textfiles_install_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install_mi,,setup,,1,$(FIRST_BUILD_CONFIG))
501ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
502$(warning Generate makefile fragment: $(generated_top_level_textfiles_install_mi))
503endif
504$(eval $(generated_top_level_textfiles_install_mi))
505
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))
517
518install_textfiles_md: textfiles_install_md_bootstrap
519
520#
521# Build all architectures for all Configuration/Architecture options
522#
523
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)
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
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)
540$(warning Generate makefile fragment: $(generated_top_level_config_all))
541endif
542$(eval $(generated_top_level_config_all))
543
544.PHONY: all config
545
546all config: config_all_bootstrap
547
548.PHONY: all_embedded all_release_embedded all_development_embedded all_desktop
549
550all_embedded all_release_embedded all_development_embedded all_desktop: all
551
552#
553# Install kernel files
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))
557ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
558$(warning Generate makefile fragment: $(generated_top_level_build_install_primary))
559endif
560$(eval $(generated_top_level_build_install_primary))
561
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)
568$(warning Generate makefile fragment: $(generated_top_level_build_install_non_primary))
569endif
570$(eval $(generated_top_level_build_install_non_primary))
571
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#
593
594.PHONY: install
595
596ifneq ($(filter $(RC_ProjectName),xnu_debug),)
597install: install_kernels
598else ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
599install: install_config install_kernels
600else ifneq ($(filter $(RC_ProjectName),xnu_headers_Sim),)
601install: installhdrs
602else ifneq ($(filter $(RC_ProjectName),xnu_headers_host),)
603install: installhdrs
604export INSTALLHDRS_SKIP_HOST=YES
605else ifneq ($(filter $(RC_ProjectName),xnu_headers_driverkit),)
606install: installhdrs_desktop
607else
608
609install: installhdrs install_textfiles install_config install_kernels install_aliases
610endif
611
612.PHONY: install_embedded install_release_embedded install_development_embedded install_desktop
613
614# By default, all kernel files, headers, text files, and pseudo-kexts are installed
615install_embedded install_release_embedded install_desktop: install
616
617# These special configs only install the kernel files
618install_development_embedded: install_kernels install_aliases
619
620.PHONY: install_kernels final_touch_kernel_timestamps install_aliases
621
622install_kernels: build_install_primary_bootstrap build_install_non_primary_bootstrap final_touch_kernel_timestamps
623
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
627 @echo "done building xnu"
628
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
638#
639# Install source tree
640#
641.PHONY: installsrc
642
643installsrc:
644 @echo INSTALLSRC $(SRCROOT)
645 $(_v)$(MKDIR) $(SRCROOT)
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)
648
649
650#
651# Clean up source tree
652#
653.PHONY: clean
654
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 \
668 $(SRCROOT)/tools/tests/mktimer \
669 $(SRCROOT)/tools/tests/zero-to-n \
670 $(SRCROOT)/tools/tests/personas
671
672clean:
673 @:
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
687
688#
689# Build source file list for cscope database and tags
690#
691.PHONY: cscope.files
692
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
701 @cat $(OBJROOT)/cscope.genhdrs/* >> _cscope.files 2> /dev/null || true
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
725 @rm -f cscope.files 2> /dev/null
726
727
728.PHONY: help
729
730help:
731 @cat README.md
732
733.PHONY: print_exports
734
735print_exports:
736 $(_v)printenv | sort
737
738generated_top_level_print_exports = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,print_exports,,,,1,$(FIRST_BUILD_CONFIG))
739ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES)
740$(warning Generate makefile fragment: $(generated_top_level_print_exports))
741endif
742$(eval $(generated_top_level_print_exports))
743
744.PHONY: print_exports_first_build_config
745
746print_exports_first_build_config: print_exports_bootstrap
747
748# vim: set ft=make: