1*a1e26a70SApple OSS Distributions# -*- mode: makefile;-*- 2*a1e26a70SApple OSS Distributions# 3*a1e26a70SApple OSS Distributions# Copyright (C) 1999-2016 Apple Inc. All rights reserved. 4*a1e26a70SApple OSS Distributions# 5*a1e26a70SApple OSS Distributions# MakeInc.dir allows makefiles throughout the XNU codebase to leverage recursive 6*a1e26a70SApple OSS Distributions# build behavior with minimal effort while promoting code reuse. 7*a1e26a70SApple OSS Distributions# 8*a1e26a70SApple OSS Distributions# For instance, a makefile need only define the special variable SETUP_SUBDIRS 9*a1e26a70SApple OSS Distributions# to be a list of subdirectories in order for the build system to automatically 10*a1e26a70SApple OSS Distributions# (1) go into those subdirectories building the target `build_setup`, (2) wait 11*a1e26a70SApple OSS Distributions# for those targets to be built, and then (3) build the target `do_build_setup` 12*a1e26a70SApple OSS Distributions# in the current directory. 13*a1e26a70SApple OSS Distributions# 14*a1e26a70SApple OSS Distributions# There are a number of other such special variables including (but not limited 15*a1e26a70SApple OSS Distributions# to): INSTINC_SUBDIRS, EXPINC_SUBDIRS, COMP_SUBDIRS, and CONFIG_SUBDIRS. For 16*a1e26a70SApple OSS Distributions# some of these special variables, there are are also architecture-specific 17*a1e26a70SApple OSS Distributions# variants if a makefile needs to specify architecture-dependent builds. 18*a1e26a70SApple OSS Distributions# 19*a1e26a70SApple OSS Distributions 20*a1e26a70SApple OSS Distributions# 21*a1e26a70SApple OSS Distributions# This function/template provides generic recursive build functionality that 22*a1e26a70SApple OSS Distributions# allows you to specify a list of subdirectories, a target to build in those 23*a1e26a70SApple OSS Distributions# subdirectories, and a target to build in the current directory afterwards. 24*a1e26a70SApple OSS Distributions# 25*a1e26a70SApple OSS Distributions# Parameters: 26*a1e26a70SApple OSS Distributions# 27*a1e26a70SApple OSS Distributions# $(1): The target to build in each subdirectory. 28*a1e26a70SApple OSS Distributions# $(2): A list of subdirectories. 29*a1e26a70SApple OSS Distributions# $(3): The target to build in the current directory _after_ the subdirectory 30*a1e26a70SApple OSS Distributions# targets have already been built. 31*a1e26a70SApple OSS Distributions# $(4): This parameter controls the value of the TARGET make variable that's 32*a1e26a70SApple OSS Distributions# passed down to the sub-makes for each subdirectory. If it's anything 33*a1e26a70SApple OSS Distributions# but the empty string (but please just use 1 for consistency), then 34*a1e26a70SApple OSS Distributions# the TARGET variable is BUILD/obj/<CURRENT_BUILD_CONFIG>/<COMPONENT>. 35*a1e26a70SApple OSS Distributions# Otherwise, the TARGET variable is <TARGET>/<subdirectory>. 36*a1e26a70SApple OSS Distributions# 37*a1e26a70SApple OSS Distributionsdefine RECURSIVE_BUILD_RULES_template 38*a1e26a70SApple OSS Distributions$(1)_recurse_target_list := $(addprefix $(1)_recurse_into_,$(2)) 39*a1e26a70SApple OSS Distributions 40*a1e26a70SApple OSS Distributions.PHONY: $$($(1)_recurse_target_list) 41*a1e26a70SApple OSS Distributions 42*a1e26a70SApple OSS Distributions$$($(1)_recurse_target_list): 43*a1e26a70SApple OSS Distributions $(_v)$(MKDIR) $(CURDIR)/$$(patsubst $(1)_recurse_into_%,%,$$@) 44*a1e26a70SApple OSS Distributions $(_v)$(MAKE) \ 45*a1e26a70SApple OSS Distributions -C $(CURDIR)/$$(patsubst $(1)_recurse_into_%,%,$$@) \ 46*a1e26a70SApple OSS Distributions -f $(SOURCE)$$(patsubst $(1)_recurse_into_%,%,$$@)/Makefile \ 47*a1e26a70SApple OSS Distributions CURRENT_KERNEL_CONFIG=$(CURRENT_KERNEL_CONFIG) \ 48*a1e26a70SApple OSS Distributions CURRENT_ARCH_CONFIG=$(CURRENT_ARCH_CONFIG) \ 49*a1e26a70SApple OSS Distributions CURRENT_MACHINE_CONFIG=$(CURRENT_MACHINE_CONFIG) \ 50*a1e26a70SApple OSS Distributions CURRENT_BUILD_CONFIG=$(CURRENT_BUILD_CONFIG) \ 51*a1e26a70SApple OSS Distributions SOURCE=$(SOURCE)$$(patsubst $(1)_recurse_into_%,%,$$@)/ \ 52*a1e26a70SApple OSS Distributions RELATIVE_SOURCE_PATH=$(RELATIVE_SOURCE_PATH)/$$(patsubst $(1)_recurse_into_%,%,$$@) \ 53*a1e26a70SApple OSS Distributions TARGET=$(if $(4),$(OBJPATH)/$(COMPONENT),$(TARGET)$$(patsubst $(1)_recurse_into_%,%,$$@)/) \ 54*a1e26a70SApple OSS Distributions OBJPATH=$(OBJPATH) \ 55*a1e26a70SApple OSS Distributions $(1) 56*a1e26a70SApple OSS Distributions 57*a1e26a70SApple OSS Distributions.PHONY: $(1) 58*a1e26a70SApple OSS Distributions 59*a1e26a70SApple OSS Distributions$(1): $$($(1)_recurse_target_list) 60*a1e26a70SApple OSS Distributions $(_v)$(MAKE) \ 61*a1e26a70SApple OSS Distributions -f $(firstword $(MAKEFILE_LIST)) \ 62*a1e26a70SApple OSS Distributions CURRENT_KERNEL_CONFIG=$(CURRENT_KERNEL_CONFIG) \ 63*a1e26a70SApple OSS Distributions CURRENT_ARCH_CONFIG=$(CURRENT_ARCH_CONFIG) \ 64*a1e26a70SApple OSS Distributions CURRENT_MACHINE_CONFIG=$(CURRENT_MACHINE_CONFIG) \ 65*a1e26a70SApple OSS Distributions CURRENT_BUILD_CONFIG=$(CURRENT_BUILD_CONFIG) \ 66*a1e26a70SApple OSS Distributions SOURCE=$(SOURCE) \ 67*a1e26a70SApple OSS Distributions RELATIVE_SOURCE_PATH=$(RELATIVE_SOURCE_PATH) \ 68*a1e26a70SApple OSS Distributions TARGET=$(TARGET) \ 69*a1e26a70SApple OSS Distributions OBJPATH=$(OBJPATH) \ 70*a1e26a70SApple OSS Distributions $(3) 71*a1e26a70SApple OSS Distributionsendef 72*a1e26a70SApple OSS Distributions 73*a1e26a70SApple OSS Distributions# 74*a1e26a70SApple OSS Distributions# Setup pass for all architectures for all Configuration/Architecture options 75*a1e26a70SApple OSS Distributions# 76*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_setup,$(SETUP_SUBDIRS),do_build_setup,)) 77*a1e26a70SApple OSS Distributions 78*a1e26a70SApple OSS Distributions# 79*a1e26a70SApple OSS Distributions# Install machine independent kernel header files 80*a1e26a70SApple OSS Distributions# 81*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_installhdrs_mi,$(INSTINC_SUBDIRS),do_installhdrs_mi,)) 82*a1e26a70SApple OSS Distributions 83*a1e26a70SApple OSS Distributions# 84*a1e26a70SApple OSS Distributions# Install machine dependent kernel header files 85*a1e26a70SApple OSS Distributions# 86*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_installhdrs_md,$(INSTINC_SUBDIRS_$(CURRENT_ARCH_CONFIG)),do_installhdrs_md,)) 87*a1e26a70SApple OSS Distributions 88*a1e26a70SApple OSS Distributions# 89*a1e26a70SApple OSS Distributions# Install machine independent kernel header files 90*a1e26a70SApple OSS Distributions# 91*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_exporthdrs_mi,$(EXPINC_SUBDIRS),do_exporthdrs_mi,)) 92*a1e26a70SApple OSS Distributions 93*a1e26a70SApple OSS Distributions# 94*a1e26a70SApple OSS Distributions# Install machine dependent kernel header files 95*a1e26a70SApple OSS Distributions# 96*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_exporthdrs_md,$(EXPINC_SUBDIRS_$(CURRENT_ARCH_CONFIG)),do_exporthdrs_md,)) 97*a1e26a70SApple OSS Distributions 98*a1e26a70SApple OSS Distributions# 99*a1e26a70SApple OSS Distributions# Build all architectures for all Configuration/Architecture options 100*a1e26a70SApple OSS Distributions# 101*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_all,$(COMP_SUBDIRS) $(COMP_SUBDIRS_$(CURRENT_ARCH_CONFIG)),do_build_all,1)) 102*a1e26a70SApple OSS Distributions 103*a1e26a70SApple OSS Distributions# 104*a1e26a70SApple OSS Distributions# Post-process build results 105*a1e26a70SApple OSS Distributions# 106*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,config_all,$(CONFIG_SUBDIRS),do_config_all,1)) 107*a1e26a70SApple OSS Distributions 108*a1e26a70SApple OSS Distributions# 109*a1e26a70SApple OSS Distributions# Install for all architectures for all Configuration/Architecture options 110*a1e26a70SApple OSS Distributions# 111*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_install_primary,$(INST_SUBDIRS),do_build_install_primary,1)) 112*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,build_install_non_primary,$(INST_SUBDIRS),do_build_install_non_primary,1)) 113*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,config_install_primary,$(CONFIG_SUBDIRS),do_config_install_primary,1)) 114*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,config_install_variant,$(CONFIG_SUBDIRS),do_config_install_variant,1)) 115*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,config_install,$(CONFIG_SUBDIRS),do_config_install,1)) 116*a1e26a70SApple OSS Distributions 117*a1e26a70SApple OSS Distributions# 118*a1e26a70SApple OSS Distributions# Install machine independent text files 119*a1e26a70SApple OSS Distributions# 120*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,textfiles_install_mi,$(INSTTEXTFILES_SUBDIRS),do_textfiles_install_mi,)) 121*a1e26a70SApple OSS Distributions 122*a1e26a70SApple OSS Distributions# 123*a1e26a70SApple OSS Distributions# Install machine dependent text files 124*a1e26a70SApple OSS Distributions# 125*a1e26a70SApple OSS Distributions$(eval $(call RECURSIVE_BUILD_RULES_template,textfiles_install_md,$(INSTTEXTFILES_SUBDIRS_$(CURRENT_ARCH_CONFIG)),do_textfiles_install_md,)) 126*a1e26a70SApple OSS Distributions 127*a1e26a70SApple OSS Distributions# vim: set ft=make: 128