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