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