Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / config / recurse.mk
blobd8c2485a497acaa4c1bafe678489e86da3b40101
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 ifndef INCLUDED_RULES_MK
6 include $(topsrcdir)/config/rules.mk
7 endif
9 # Make sure that anything that needs to be defined in moz.build wasn't
10 # overwritten after including rules.mk.
11 _eval_for_side_effects := $(CHECK_MOZBUILD_VARIABLES)
13 # The traditional model of directory traversal with make is as follows:
14 # make -C foo
15 # Entering foo
16 # make -C bar
17 # Entering foo/bar
18 # make -C baz
19 # Entering foo/baz
20 # make -C qux
21 # Entering qux
23 # Pseudo derecurse transforms the above into:
24 # make -C foo
25 # make -C foo/bar
26 # make -C foo/baz
27 # make -C qux
29 ifeq (.,$(DEPTH))
31 include root.mk
33 # Disable build status for mach in top directories without TIERS.
34 # In practice this disables it when recursing under js/src, which confuses mach.
35 ifndef TIERS
36 BUILDSTATUS =
37 endif
39 # Main rules (export, compile, libs and tools) call recurse_* rules.
40 # This wrapping is only really useful for build status.
41 compile libs export tools::
42 $(call BUILDSTATUS,TIER_START $@)
43 +$(MAKE) recurse_$@
44 $(call BUILDSTATUS,TIER_FINISH $@)
46 # Special rule that does install-manifests (cf. Makefile.in) + compile
47 binaries::
48 +$(MAKE) recurse_compile
50 # Carefully avoid $(eval) type of rule generation, which makes pymake slower
51 # than necessary.
52 # Get current tier and corresponding subtiers from the data in root.mk.
53 CURRENT_TIER := $(filter $(foreach tier,compile libs export tools,recurse_$(tier) $(tier)-deps),$(MAKECMDGOALS))
54 ifneq (,$(filter-out 0 1,$(words $(CURRENT_TIER))))
55 $(error $(CURRENT_TIER) not supported on the same make command line)
56 endif
57 CURRENT_TIER := $(subst recurse_,,$(CURRENT_TIER:-deps=))
59 # The rules here are doing directory traversal, so we don't want further
60 # recursion to happen when running make -C subdir $tier. But some make files
61 # further call make -C something else, and sometimes expect recursion to
62 # happen in that case (see browser/metro/locales/Makefile.in for example).
63 # Conveniently, every invocation of make increases MAKELEVEL, so only stop
64 # recursion from happening at current MAKELEVEL + 1.
65 ifdef CURRENT_TIER
66 ifeq (0,$(MAKELEVEL))
67 export NO_RECURSE_MAKELEVEL=1
68 else
69 export NO_RECURSE_MAKELEVEL=$(word $(MAKELEVEL),2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
70 endif
71 endif
73 # Get all directories traversed for all subtiers in the current tier, or use
74 # directly the $(*_dirs) variables available in root.mk when there is no
75 # TIERS (like for js/src).
76 CURRENT_DIRS := $($(CURRENT_TIER)_dirs)
78 # The compile tier has different rules from other tiers.
79 ifeq ($(CURRENT_TIER),compile)
81 # Need a list of compile targets because we can't use pattern rules:
82 # https://savannah.gnu.org/bugs/index.php?42833
83 .PHONY: $(compile_targets)
84 $(compile_targets):
85 $(call SUBMAKE,$(@F),$(@D))
87 else
89 # Recursion rule for all directories traversed for all subtiers in the
90 # current tier.
91 $(addsuffix /$(CURRENT_TIER),$(CURRENT_DIRS)): %/$(CURRENT_TIER):
92 $(call SUBMAKE,$(CURRENT_TIER),$*)
94 .PHONY: $(addsuffix /$(CURRENT_TIER),$(CURRENT_DIRS))
96 # Dummy rules for possibly inexisting dependencies for the above tier targets
97 $(addsuffix /Makefile,$(CURRENT_DIRS)) $(addsuffix /backend.mk,$(CURRENT_DIRS)):
99 ifeq ($(CURRENT_TIER),export)
100 # At least build/export requires config/export for buildid, but who knows what
101 # else, so keep this global dependency to make config/export first for now.
102 $(addsuffix /$(CURRENT_TIER),$(filter-out config,$(CURRENT_DIRS))): config/$(CURRENT_TIER)
104 # The export tier requires nsinstall, which is built from config. So every
105 # subdirectory traversal needs to happen after building nsinstall in config, which
106 # is done with the config/host target. Note the config/host target only exists if
107 # nsinstall is actually built, which it is not on Windows, because we use
108 # nsinstall.py there.
109 ifneq (,$(filter config/host, $(compile_targets)))
110 $(addsuffix /$(CURRENT_TIER),$(CURRENT_DIRS)): config/host
112 # Ensure rules for config/host and its possible dependencies.
113 .PHONY: $(filter %/host, $(compile_targets))
114 $(filter %/host, $(compile_targets)):
115 $(call SUBMAKE,host,$(@D))
116 endif
117 endif
119 endif # ifeq ($(CURRENT_TIER),compile)
121 else
123 # Don't recurse if MAKELEVEL is NO_RECURSE_MAKELEVEL as defined above
124 ifeq ($(NO_RECURSE_MAKELEVEL),$(MAKELEVEL))
126 compile libs export tools::
128 else
129 #########################
130 # Tier traversal handling
131 #########################
133 ifdef TIERS
135 libs export tools::
136 $(call BUILDSTATUS,TIER_START $@)
137 $(foreach tier,$(TIERS), $(if $(filter-out libs_precompile tools_precompile,$@_$(tier)), \
138 $(foreach dir, $(tier_$(tier)_dirs), $(call TIER_DIR_SUBMAKE,$@,$(tier),$(dir),$@))))
139 $(call BUILDSTATUS,TIER_FINISH $@)
141 else
143 define CREATE_SUBTIER_TRAVERSAL_RULE
144 .PHONY: $(1)
146 $(1):: $$(SUBMAKEFILES)
147 $$(LOOP_OVER_DIRS)
149 endef
151 $(foreach subtier,export libs tools,$(eval $(call CREATE_SUBTIER_TRAVERSAL_RULE,$(subtier))))
153 ifndef TOPLEVEL_BUILD
154 libs:: target host
155 endif
157 endif # ifdef TIERS
159 endif # ifeq ($(NO_RECURSE_MAKELEVEL),$(MAKELEVEL))
161 endif # ifeq (.,$(DEPTH))
163 recurse:
164 @$(RECURSED_COMMAND)
165 $(LOOP_OVER_DIRS)