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