]>
Commit | Line | Data |
---|---|---|
1 | # -*- mode: makefile;-*- | |
2 | # | |
3 | # Copyright (C) 2010-2016 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 | ||
27 | export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd | |
28 | ||
29 | include $(MakeInc_cmd) | |
30 | ||
31 | ||
32 | # | |
33 | # Architecture Configuration options | |
34 | # | |
35 | ||
36 | # Default to current kernel architecture | |
37 | ||
38 | ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) | |
39 | override DEFAULT_ARCH_CONFIG := ARM | |
40 | else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),) | |
41 | override DEFAULT_ARCH_CONFIG := X86_64 | |
42 | else | |
43 | override DEFAULT_ARCH_CONFIG := X86_64 | |
44 | endif | |
45 | ||
46 | # Accept either explicit ARCH_CONFIGS or XBS-style RC_ARCHS | |
47 | ifndef ARCH_CONFIGS | |
48 | ifdef RC_ARCHS | |
49 | ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z | $(TR) " " "\n" | sort -u | $(TR) "\n" " ") | |
50 | else | |
51 | ARCH_CONFIGS := DEFAULT | |
52 | endif | |
53 | endif | |
54 | ||
55 | # | |
56 | # Kernel Configuration options | |
57 | # | |
58 | ||
59 | DEFAULT_PRODUCT_CONFIGS := | |
60 | ||
61 | ifeq ($(RC_ProjectName),xnu_debug) | |
62 | override DEFAULT_KERNEL_CONFIG := DEBUG | |
63 | else ifeq ($(RC_ProjectName),xnu_kasan) | |
64 | override KERNEL_CONFIGS := KASAN | |
65 | else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) | |
66 | override DEFAULT_KERNEL_CONFIG := DEVELOPMENT | |
67 | else ifeq ($(PLATFORM),MacOSX) | |
68 | override DEFAULT_KERNEL_CONFIG := DEVELOPMENT | |
69 | else | |
70 | override DEFAULT_KERNEL_CONFIG := RELEASE | |
71 | endif | |
72 | ||
73 | # If KERNEL_CONFIGS is specified it should override default | |
74 | ifndef KERNEL_CONFIGS | |
75 | KERNEL_CONFIGS := DEFAULT | |
76 | endif | |
77 | ||
78 | # If PRODUCT_CONFIGS is specified it should override default | |
79 | ifndef PRODUCT_CONFIGS | |
80 | PRODUCT_CONFIGS := $(DEFAULT_PRODUCT_CONFIGS) | |
81 | endif | |
82 | ||
83 | # | |
84 | # Machine Configuration options | |
85 | # | |
86 | ||
87 | override DEFAULT_I386_MACHINE_CONFIG := NONE | |
88 | override DEFAULT_X86_64_MACHINE_CONFIG := NONE | |
89 | override DEFAULT_X86_64H_MACHINE_CONFIG := NONE | |
90 | override DEFAULT_ARM_MACHINE_CONFIG := T8002 | |
91 | override DEFAULT_ARM64_MACHINE_CONFIG := T7000 | |
92 | ||
93 | # This is typically never specified (TARGET_CONFIGS is used) | |
94 | ifndef MACHINE_CONFIGS | |
95 | MACHINE_CONFIGS := DEFAULT | |
96 | endif | |
97 | ||
98 | # | |
99 | # Target configuration options. NOTE - target configurations will | |
100 | # override ARCH_CONFIGS and KERNEL_CONFIGS and MACHINE_CONFIGS. | |
101 | # | |
102 | # Target configs come in groups of three parameters. The first is the | |
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 | # | |
112 | # "default" parameter is a special case. It means use the default value for | |
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 | ||
118 | ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) | |
119 | ||
120 | # Defaults for "make all_embedded" | |
121 | ifeq ($(KERNEL_CONFIGS),DEFAULT) | |
122 | KERNEL_CONFIGS_EMBEDDED := RELEASE DEVELOPMENT | |
123 | else | |
124 | KERNEL_CONFIGS_EMBEDDED := $(KERNEL_CONFIGS) | |
125 | endif | |
126 | ||
127 | ifeq ($(ARCH_CONFIGS),DEFAULT) | |
128 | ARCH_CONFIGS_EMBEDDED := ARM ARM64 | |
129 | else | |
130 | ARCH_CONFIGS_EMBEDDED := $(strip $(shell echo $(ARCH_CONFIGS) | $(TR) a-z A-Z)) | |
131 | endif | |
132 | ||
133 | # Find supported products from the device map | |
134 | DEVICEMAP_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"))') | |
141 | DEVICEMAP_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"))') | |
148 | DEVICEMAP_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"))') | |
155 | DEVICEMAP_PRODUCTS_ARM := $(DEVICEMAP_PRODUCTS_ARMV7) $(DEVICEMAP_PRODUCTS_ARMV7S) $(DEVICEMAP_PRODUCTS_ARMV7K) | |
156 | ||
157 | ||
158 | DEVICEMAP_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 | |
168 | DEVICEMAP_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 | |
172 | function_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 | |
181 | DEVICEMAP_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 | ||
183 | function_lookup_product_alias = $(call function_substitute_word_with_replacement, \ | |
184 | $(1), \ | |
185 | $(DEVICEMAP_PRODUCT_SOC_ALIASES), \ | |
186 | ) | |
187 | endif | |
188 | ||
189 | ifeq ($(PLATFORM),MacOSX) | |
190 | ||
191 | # Defaults for "make all_desktop" | |
192 | ifeq ($(KERNEL_CONFIGS),DEFAULT) | |
193 | KERNEL_CONFIGS_DESKTOP := RELEASE DEVELOPMENT | |
194 | else | |
195 | KERNEL_CONFIGS_DESKTOP := $(KERNEL_CONFIGS) | |
196 | endif | |
197 | ||
198 | endif | |
199 | ||
200 | ifndef TARGET_CONFIGS | |
201 | ifneq ($(PRODUCT_CONFIGS),) | |
202 | # generate TARGET_CONFIGS using KERNEL_CONFIGS and PRODUCT_CONFIGS | |
203 | TARGET_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)))) | |
204 | TARGET_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)))) | |
205 | else ifneq ($(filter %_release_embedded,$(MAKECMDGOALS)),) | |
206 | # generate TARGET_CONFIGS for RELEASE kernel configs and products in the device map | |
207 | TARGET_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)))) | |
208 | TARGET_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)))) | |
209 | else ifneq ($(filter %_development_embedded,$(MAKECMDGOALS)),) | |
210 | # generate TARGET_CONFIGS for DEVELOPMENT kernel configs and products in the device map | |
211 | TARGET_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)))) | |
212 | TARGET_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)))) | |
213 | else ifneq ($(filter %_embedded,$(MAKECMDGOALS)),) | |
214 | # generate TARGET_CONFIGS for all kernel configs and products in the device map | |
215 | TARGET_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)))) | |
216 | TARGET_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)))) | |
217 | else ifneq ($(filter %_desktop,$(MAKECMDGOALS)),) | |
218 | # generate TARGET_CONFIGS for all kernel configs for B&I | |
219 | TARGET_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)))) | |
220 | TARGET_CONFIGS_ALIASES := | |
221 | else | |
222 | # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIGS (which defaults to "DEFAULT") | |
223 | TARGET_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)))) | |
224 | TARGET_CONFIGS_ALIASES := | |
225 | endif | |
226 | endif | |
227 | ||
228 | ifeq ($(TARGET_CONFIGS),) | |
229 | $(error No TARGET_CONFIGS specified) | |
230 | endif | |
231 | ||
232 | TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z)) | |
233 | TARGET_CONFIGS_ALIASES_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS_ALIASES)" | $(TR) a-z A-Z)) | |
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 | |
241 | # "RELEASE^I386^NONE DEVELOPMENT^ARM^T8002", which can be looped | |
242 | # over trivially. PRIMARY_BUILD_CONFIGS is the first config | |
243 | # for each architecture, used primarily for machine-dependent recursion. | |
244 | ||
245 | BUILD_CONFIGS = $(call function_create_build_configs, $(TARGET_CONFIGS_UC)) | |
246 | ||
247 | PRIMARY_ARCHS = $(strip $(sort $(foreach build_config, $(BUILD_CONFIGS), $(call function_extract_arch_config_from_build_config, $(build_config))))) | |
248 | PRIMARY_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), ))))) | |
249 | NON_PRIMARY_BUILD_CONFIGS = $(strip $(filter-out $(PRIMARY_BUILD_CONFIGS), $(BUILD_CONFIGS))) | |
250 | FIRST_BUILD_CONFIG = $(firstword $(BUILD_CONFIGS)) | |
251 | ||
252 | ifneq ($(TARGET_CONFIGS_ALIASES_UC),) | |
253 | ALIAS_CONFIGS = $(call function_create_alias_configs, $(TARGET_CONFIGS_ALIASES_UC)) | |
254 | else | |
255 | ALIAS_CONFIGS = | |
256 | endif | |
257 | ||
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)) | |
263 | # $(warning TARGET_CONFIGS_ALIASES is $(TARGET_CONFIGS_ALIASES)) | |
264 | # $(warning ALIAS_CONFIGS is $(ALIAS_CONFIGS)) | |
265 | ||
266 | MEMORY_SIZE := $(shell /usr/sbin/sysctl -n hw.memsize) | |
267 | ||
268 | # Assume LTO scaling by default, unless it is being explicitly passed on the command-line | |
269 | LARGE_BUILD_FOOTPRINT := $(if $(BUILD_LTO),$(BUILD_LTO),1) | |
270 | ||
271 | ifeq ($(LARGE_BUILD_FOOTPRINT),1) | |
272 | RAM_PER_KERNEL_BUILD := 4294967296 | |
273 | else | |
274 | RAM_PER_KERNEL_BUILD := 268435456 | |
275 | endif | |
276 | ||
277 | KERNEL_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) | |
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, | |
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 | |
297 | ||
298 | define 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 | ||
305 | $(1)_generated_stripe_dependencies = $$(call _function_generate_stripe_groupings,$(1),$(5),$(call reverse,$(6))) | |
306 | ifeq ($$(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
307 | $$(warning Generate makefile fragment: $$($(1)_generated_stripe_dependencies)) | |
308 | endif | |
309 | $$(eval $$($(1)_generated_stripe_dependencies)) | |
310 | ||
311 | $$($(1)_bootstrap_target_list): $(1)_bootstrap_% : $(1)_stripe_dep_for_% $$(addsuffix _bootstrap_%,$(4)) $(3) | |
312 | $$(_v)$$(MKDIR) $${OBJROOT}/$$(call function_convert_build_config_to_objdir,$$(patsubst $(1)_bootstrap_%,%,$$@))$(2) | |
313 | $$(_v)$${MAKE} \ | |
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) | |
330 | endef | |
331 | ||
332 | # | |
333 | # TOP_LEVEL_STRIPE_DEPENDENCY_template | |
334 | # | |
335 | # $(1) is the Makefile target we are building for | |
336 | # $(2) is the build config that must build first | |
337 | # $(3) is the build config that must build after $(2) | |
338 | ||
339 | define TOP_LEVEL_STRIPE_DEPENDENCY_template | |
340 | ||
341 | .PHONY: $(1)_stripe_dep_for_$(3) | |
342 | ||
343 | $(1)_stripe_dep_for_$(3): $(if $(2),$(1)_bootstrap_$(2)) | |
344 | ||
345 | endef | |
346 | ||
347 | # $(1) is the Makefile target we are building for | |
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 | ||
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)) | |
357 | ||
358 | # | |
359 | # Setup pass for build system tools | |
360 | # | |
361 | ||
362 | generated_top_level_build_setup = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_setup,/..,,,1,$(FIRST_BUILD_CONFIG)) | |
363 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
364 | $(warning Generate makefile fragment: $(generated_top_level_build_setup)) | |
365 | endif | |
366 | $(eval $(generated_top_level_build_setup)) | |
367 | ||
368 | .PHONY: setup | |
369 | ||
370 | # invalidate current kernel in $(SYMROOT). Timestamp must be +1 from a previous kernel build | |
371 | setup: build_setup_bootstrap | |
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 | |
384 | ||
385 | # | |
386 | # Install kernel header files | |
387 | # | |
388 | .PHONY: exporthdrs exporthdrs_mi exporthdrs_md | |
389 | ||
390 | exporthdrs: exporthdrs_mi exporthdrs_md | |
391 | ||
392 | # | |
393 | # Install machine independent kernel header files | |
394 | # | |
395 | ||
396 | generated_top_level_build_exporthdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_mi,,setup,,1,$(FIRST_BUILD_CONFIG)) | |
397 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
398 | $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_mi)) | |
399 | endif | |
400 | $(eval $(generated_top_level_build_exporthdrs_mi)) | |
401 | ||
402 | exporthdrs_mi: build_exporthdrs_mi_bootstrap | |
403 | ||
404 | # | |
405 | # Install machine dependent kernel header files | |
406 | # | |
407 | ||
408 | generated_top_level_build_exporthdrs_md = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_exporthdrs_md,,setup,,$(KERNEL_BUILDS_IN_PARALLEL),$(PRIMARY_BUILD_CONFIGS)) | |
409 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
410 | $(warning Generate makefile fragment: $(generated_top_level_build_exporthdrs_md)) | |
411 | endif | |
412 | $(eval $(generated_top_level_build_exporthdrs_md)) | |
413 | ||
414 | exporthdrs_md: build_exporthdrs_md_bootstrap | |
415 | ||
416 | # | |
417 | # Install kernel header files | |
418 | # | |
419 | ||
420 | .PHONY: installhdrs installhdrs_mi installhdrs_md | |
421 | ||
422 | ifeq ($(RC_ProjectName),xnu_debug) | |
423 | installhdrs: | |
424 | @: | |
425 | else ifeq ($(RC_ProjectName),xnu_kasan) | |
426 | installhdrs: | |
427 | @: | |
428 | else | |
429 | ||
430 | installhdrs: installhdrs_mi installhdrs_md | |
431 | endif | |
432 | ||
433 | .PHONY: installhdrs_embedded installhdrs_release_embedded installhdrs_development_embedded installhdrs_desktop | |
434 | ||
435 | installhdrs_embedded installhdrs_release_embedded installhdrs_desktop: installhdrs | |
436 | ||
437 | installhdrs_development_embedded: | |
438 | ||
439 | # | |
440 | # Install machine independent header files | |
441 | # | |
442 | ||
443 | generated_top_level_build_installhdrs_mi = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_installhdrs_mi,,setup,build_exporthdrs_mi,1,$(FIRST_BUILD_CONFIG)) | |
444 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
445 | $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_mi)) | |
446 | endif | |
447 | $(eval $(generated_top_level_build_installhdrs_mi)) | |
448 | ||
449 | installhdrs_mi: build_installhdrs_mi_bootstrap | |
450 | ||
451 | # | |
452 | # Install machine dependent kernel header files | |
453 | # | |
454 | ||
455 | generated_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)) | |
456 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
457 | $(warning Generate makefile fragment: $(generated_top_level_build_installhdrs_md)) | |
458 | endif | |
459 | $(eval $(generated_top_level_build_installhdrs_md)) | |
460 | ||
461 | installhdrs_md: build_installhdrs_md_bootstrap | |
462 | ||
463 | # | |
464 | # Install text files (man pages, dtrace scripts, etc.) | |
465 | # | |
466 | ||
467 | generated_top_level_textfiles_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,textfiles_install,,setup,,1,$(FIRST_BUILD_CONFIG)) | |
468 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
469 | $(warning Generate makefile fragment: $(generated_top_level_textfiles_install)) | |
470 | endif | |
471 | $(eval $(generated_top_level_textfiles_install)) | |
472 | ||
473 | .PHONY: install_textfiles | |
474 | ||
475 | install_textfiles: textfiles_install_bootstrap | |
476 | ||
477 | # | |
478 | # Build all architectures for all Configuration/Architecture options | |
479 | # | |
480 | ||
481 | generated_top_level_build_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_all,,setup exporthdrs,,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS)) | |
482 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
483 | $(warning Generate makefile fragment: $(generated_top_level_build_all)) | |
484 | endif | |
485 | $(eval $(generated_top_level_build_all)) | |
486 | ||
487 | .PHONY: build | |
488 | ||
489 | build: build_all_bootstrap | |
490 | ||
491 | # | |
492 | # Post-process build results | |
493 | # | |
494 | ||
495 | generated_top_level_config_all = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_all,,setup,build_all,$(KERNEL_BUILDS_IN_PARALLEL),$(BUILD_CONFIGS)) | |
496 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
497 | $(warning Generate makefile fragment: $(generated_top_level_config_all)) | |
498 | endif | |
499 | $(eval $(generated_top_level_config_all)) | |
500 | ||
501 | .PHONY: all config | |
502 | ||
503 | all config: config_all_bootstrap | |
504 | ||
505 | .PHONY: all_embedded all_release_embedded all_development_embedded all_desktop | |
506 | ||
507 | all_embedded all_release_embedded all_development_embedded all_desktop: all | |
508 | ||
509 | # | |
510 | # Install kernel files | |
511 | # | |
512 | ||
513 | generated_top_level_build_install_primary = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,build_install_primary,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS)) | |
514 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
515 | $(warning Generate makefile fragment: $(generated_top_level_build_install_primary)) | |
516 | endif | |
517 | $(eval $(generated_top_level_build_install_primary)) | |
518 | ||
519 | .PHONY: install_primary | |
520 | ||
521 | install_primary: build_install_primary_bootstrap | |
522 | ||
523 | generated_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)) | |
524 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
525 | $(warning Generate makefile fragment: $(generated_top_level_build_install_non_primary)) | |
526 | endif | |
527 | $(eval $(generated_top_level_build_install_non_primary)) | |
528 | ||
529 | .PHONY: install_non_primary | |
530 | ||
531 | install_non_primary: build_install_non_primary_bootstrap | |
532 | ||
533 | generated_top_level_config_install = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,config_install,,setup,config_all,1,$(PRIMARY_BUILD_CONFIGS)) | |
534 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
535 | $(warning Generate makefile fragment: $(generated_top_level_config_install)) | |
536 | endif | |
537 | $(eval $(generated_top_level_config_install)) | |
538 | ||
539 | .PHONY: install_config final_touch_config_timestamps | |
540 | ||
541 | install_config: config_install_bootstrap final_touch_config_timestamps | |
542 | ||
543 | # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT | |
544 | final_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 | # | |
550 | ||
551 | .PHONY: install | |
552 | ||
553 | ifeq ($(RC_ProjectName),xnu_debug) | |
554 | install: install_kernels | |
555 | else ifeq ($(RC_ProjectName),xnu_kasan) | |
556 | install: install_config install_kernels | |
557 | else ifeq ($(RC_ProjectName),xnu_headers_Sim) | |
558 | install: installhdrs | |
559 | else ifeq ($(RC_ProjectName),xnu_headers_host) | |
560 | install: installhdrs | |
561 | export INSTALLHDRS_SKIP_HOST=YES | |
562 | else ifeq ($(RC_ProjectName),xnu_headers_driverkit) | |
563 | install: installhdrs_desktop | |
564 | else | |
565 | ||
566 | install: installhdrs install_textfiles install_config install_kernels install_aliases checkstyle | |
567 | endif | |
568 | ||
569 | .PHONY: install_embedded install_release_embedded install_development_embedded install_desktop | |
570 | ||
571 | # By default, all kernel files, headers, text files, and pseudo-kexts are installed | |
572 | install_embedded install_release_embedded install_desktop: install | |
573 | ||
574 | # These special configs only install the kernel files | |
575 | install_development_embedded: install_kernels install_aliases | |
576 | ||
577 | .PHONY: install_kernels final_touch_kernel_timestamps install_aliases | |
578 | ||
579 | install_kernels: build_install_primary_bootstrap build_install_non_primary_bootstrap final_touch_kernel_timestamps | |
580 | ||
581 | # Tell the next build the latest timestamp of any potential file in DSTROOT/SYMROOT | |
582 | final_touch_kernel_timestamps: build_install_primary_bootstrap build_install_non_primary_bootstrap | |
583 | $(_v)$(TOUCH) $(OBJROOT)/.mach_kernel.timestamp | |
584 | ||
585 | # Copy kernels that are aliases of another configuration | |
586 | generated_top_level_install_alias = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,install_alias,,install_kernels,,$(KERNEL_BUILDS_IN_PARALLEL),$(ALIAS_CONFIGS)) | |
587 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
588 | $(warning Generate makefile fragment: $(generated_top_level_install_alias)) | |
589 | endif | |
590 | $(eval $(generated_top_level_install_alias)) | |
591 | ||
592 | install_aliases: install_alias_bootstrap | |
593 | ||
594 | # | |
595 | # Install source tree | |
596 | # | |
597 | .PHONY: installsrc | |
598 | ||
599 | installsrc: | |
600 | @echo INSTALLSRC $(SRCROOT) | |
601 | $(_v)$(MKDIR) $(SRCROOT) | |
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) | |
604 | ||
605 | ||
606 | # | |
607 | # Clean up source tree | |
608 | # | |
609 | .PHONY: clean | |
610 | ||
611 | CLEAN_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 | ||
621 | CLEAN_ACTION_DIRS= $(SRCROOT)/tools/tests/MPMMTest \ | |
622 | $(SRCROOT)/tools/tests/TLBcoherency \ | |
623 | $(SRCROOT)/tools/tests/kqueue_tests \ | |
624 | $(SRCROOT)/tools/tests/mktimer \ | |
625 | $(SRCROOT)/tools/tests/zero-to-n \ | |
626 | $(SRCROOT)/tools/tests/personas | |
627 | ||
628 | clean: | |
629 | @: | |
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 | ||
643 | ||
644 | # | |
645 | # Build source file list for cscope database and tags | |
646 | # | |
647 | .PHONY: cscope.files | |
648 | ||
649 | cscope.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 | |
657 | @cat $(OBJROOT)/cscope.genhdrs/* >> _cscope.files 2> /dev/null || true | |
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 | # | |
665 | cscope: cscope.files | |
666 | @echo "Building cscope database" | |
667 | @cscope -bvU 2> /dev/null | |
668 | ||
669 | # | |
670 | # Build tags | |
671 | # | |
672 | tags: 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 | ||
678 | TAGS: cscope.files | |
679 | @echo "Building etags" | |
680 | @-cat cscope.files | etags -l auto -S - 2> /dev/null | |
681 | @rm -f cscope.files 2> /dev/null | |
682 | ||
683 | # | |
684 | # Check or reformat source code for official xnu code style | |
685 | # | |
686 | .PHONY: checkstyle restyle check_uncrustify uncrustify | |
687 | ||
688 | # User-friendly aliases for those who prefer to remember the name of the tool. | |
689 | check_uncrustify: checkstyle | |
690 | uncrustify: restyle | |
691 | ||
692 | checkstyle: | |
693 | ${_V}$(SRCROOT)/tools/uncrustify.sh | |
694 | ||
695 | restyle: | |
696 | ${_V}$(SRCROOT)/tools/uncrustify.sh -f | |
697 | ||
698 | .PHONY: help | |
699 | ||
700 | help: | |
701 | @cat README.md | |
702 | ||
703 | .PHONY: print_exports | |
704 | ||
705 | print_exports: | |
706 | $(_v)printenv | sort | |
707 | ||
708 | generated_top_level_print_exports = $(call TOP_LEVEL_EACH_BUILD_CONFIG_BOOTSTRAP_template,print_exports,,,,1,$(FIRST_BUILD_CONFIG)) | |
709 | ifeq ($(VERBOSE_GENERATED_MAKE_FRAGMENTS),YES) | |
710 | $(warning Generate makefile fragment: $(generated_top_level_print_exports)) | |
711 | endif | |
712 | $(eval $(generated_top_level_print_exports)) | |
713 | ||
714 | .PHONY: print_exports_first_build_config | |
715 | ||
716 | print_exports_first_build_config: print_exports_bootstrap |