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