Backed out 3 changesets (bug 1039064, bug 1040446, bug 1034124) for ASAN xpcshell...
[gecko.git] / config / recurse.mk
blobc2ce51adc38001ef4c2f6aa79e1193963126067c
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, binaries, libs and tools) call recurse_* rules.
40 # This wrapping is only really useful for build status.
41 compile binaries libs export tools::
42 $(call BUILDSTATUS,TIER_START $@)
43 +$(MAKE) recurse_$@
44 $(call BUILDSTATUS,TIER_FINISH $@)
46 # Carefully avoid $(eval) type of rule generation, which makes pymake slower
47 # than necessary.
48 # Get current tier and corresponding subtiers from the data in root.mk.
49 CURRENT_TIER := $(filter $(foreach tier,compile binaries libs export tools,recurse_$(tier) $(tier)-deps),$(MAKECMDGOALS))
50 ifneq (,$(filter-out 0 1,$(words $(CURRENT_TIER))))
51 $(error $(CURRENT_TIER) not supported on the same make command line)
52 endif
53 CURRENT_TIER := $(subst recurse_,,$(CURRENT_TIER:-deps=))
54 CURRENT_SUBTIERS := $($(CURRENT_TIER)_subtiers)
56 # The rules here are doing directory traversal, so we don't want further
57 # recursion to happen when running make -C subdir $tier. But some make files
58 # further call make -C something else, and sometimes expect recursion to
59 # happen in that case (see browser/metro/locales/Makefile.in for example).
60 # Conveniently, every invocation of make increases MAKELEVEL, so only stop
61 # recursion from happening at current MAKELEVEL + 1.
62 ifdef CURRENT_TIER
63 ifeq (0,$(MAKELEVEL))
64 export NO_RECURSE_MAKELEVEL=1
65 else
66 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)
67 endif
68 endif
70 # Get all directories traversed for all subtiers in the current tier, or use
71 # directly the $(*_dirs) variables available in root.mk when there is no
72 # TIERS (like for js/src).
73 TIER_DIRS = $(or $($(1)_dirs),$(foreach subtier,$($(1)_subtiers),$($(1)_subtier_$(subtier))))
74 CURRENT_DIRS := $(call TIER_DIRS,$(CURRENT_TIER))
76 ifneq (,$(filter binaries libs,$(CURRENT_TIER)))
77 WANT_STAMPS = 1
78 STAMP_TOUCH = $(TOUCH) $(@D)/binaries
79 endif
81 # Subtier delimiter rules
82 $(addprefix subtiers/,$(addsuffix _start/$(CURRENT_TIER),$(CURRENT_SUBTIERS))): subtiers/%_start/$(CURRENT_TIER): $(if $(WANT_STAMPS),$(call mkdir_deps,subtiers/%_start))
83 @$(STAMP_TOUCH)
85 $(addprefix subtiers/,$(addsuffix _finish/$(CURRENT_TIER),$(CURRENT_SUBTIERS))): subtiers/%_finish/$(CURRENT_TIER): $(if $(WANT_STAMPS),$(call mkdir_deps,subtiers/%_finish))
86 @$(STAMP_TOUCH)
88 $(addprefix subtiers/,$(addsuffix /$(CURRENT_TIER),$(CURRENT_SUBTIERS))): %/$(CURRENT_TIER): $(if $(WANT_STAMPS),$(call mkdir_deps,%))
89 @$(STAMP_TOUCH)
91 GARBAGE_DIRS += subtiers
93 # Recursion rule for all directories traversed for all subtiers in the
94 # current tier.
95 # root.mk defines subtier_of_* variables, that map a normalized subdir path to
96 # a subtier name (e.g. subtier_of_memory_jemalloc = base)
97 $(addsuffix /$(CURRENT_TIER),$(CURRENT_DIRS)): %/$(CURRENT_TIER):
98 $(call SUBMAKE,$(if $(filter $*,$(tier_$(subtier_of_$(subst /,_,$*))_staticdirs)),,$(CURRENT_TIER)),$*)
99 # Ensure existing stamps are up-to-date, but don't create one if submake didn't create one.
100 $(if $(wildcard $@),@$(STAMP_TOUCH))
102 # Dummy rules for possibly inexisting dependencies for the above tier targets
103 $(addsuffix /Makefile,$(CURRENT_DIRS)) $(addsuffix /backend.mk,$(CURRENT_DIRS)):
105 # The export tier requires nsinstall, which is built from config. So every
106 # subdirectory traversal needs to happen after traversing config.
107 ifeq ($(CURRENT_TIER),export)
108 $(addsuffix /$(CURRENT_TIER),$(filter-out config,$(CURRENT_DIRS))): config/$(CURRENT_TIER)
109 endif
111 ifdef COMPILE_ENVIRONMENT
112 # Disable dependency aggregation on PGO builds because of bug 934166.
113 ifeq (,$(MOZ_PGO)$(MOZ_PROFILE_USE)$(MOZ_PROFILE_GENERATE))
114 ifneq (,$(filter libs binaries,$(CURRENT_TIER)))
115 # When doing a "libs" build, target_libs.mk ensures the interesting dependency data
116 # is available in the "binaries" stamp. Once recursion is done, aggregate all that
117 # dependency info so that stamps depend on relevant files and relevant other stamps.
118 # When doing a "binaries" build, the aggregate dependency file and those stamps are
119 # used and allow to skip recursing directories where changes are not going to require
120 # rebuild. A few directories, however, are still traversed all the time, mostly, the
121 # gyp managed ones and js/src.
122 # A few things that are not traversed by a "binaries" build, but should, in an ideal
123 # world, are nspr, nss, icu and ffi.
124 recurse_$(CURRENT_TIER):
125 @$(MAKE) binaries-deps
127 # Creating binaries-deps.mk directly would make us build it twice: once when beginning
128 # the build because of the include, and once at the end because of the stamps.
129 binaries-deps:
130 @$(call py_action,link_deps,-o $@.mk --group-by-depfile --topsrcdir $(topsrcdir) --topobjdir $(DEPTH) --dist $(DIST) --guard $(addprefix ',$(addsuffix ', $(wildcard $(addsuffix /binaries,$(CURRENT_DIRS))))))
131 @$(TOUCH) $@
133 ifeq (recurse_binaries,$(MAKECMDGOALS))
134 $(call include_deps,binaries-deps.mk)
135 endif
137 endif
139 DIST_GARBAGE += binaries-deps.mk binaries-deps
141 endif
143 endif
145 else
147 # Don't recurse if MAKELEVEL is NO_RECURSE_MAKELEVEL as defined above
148 ifeq ($(NO_RECURSE_MAKELEVEL),$(MAKELEVEL))
150 compile binaries libs export tools::
152 else
153 #########################
154 # Tier traversal handling
155 #########################
157 ifdef TIERS
159 libs export tools::
160 $(call BUILDSTATUS,TIER_START $@)
161 $(foreach tier,$(TIERS), $(if $(filter-out libs_precompile tools_precompile,$@_$(tier)), \
162 $(if $(filter libs,$@),$(foreach dir, $(tier_$(tier)_staticdirs), $(call TIER_DIR_SUBMAKE,$@,$(tier),$(dir),,1))) \
163 $(foreach dir, $(tier_$(tier)_dirs), $(call TIER_DIR_SUBMAKE,$@,$(tier),$(dir),$@))))
164 $(call BUILDSTATUS,TIER_FINISH $@)
166 else
168 define CREATE_SUBTIER_TRAVERSAL_RULE
169 PARALLEL_DIRS_$(1) = $$(addsuffix _$(1),$$(PARALLEL_DIRS))
171 .PHONY: $(1) $$(PARALLEL_DIRS_$(1))
173 ifdef PARALLEL_DIRS
174 $$(PARALLEL_DIRS_$(1)): %_$(1): %/Makefile
175 +@$$(call SUBMAKE,$(1),$$*)
176 endif
178 $(1):: $$(SUBMAKEFILES)
179 ifdef PARALLEL_DIRS
180 +@$(MAKE) $$(PARALLEL_DIRS_$(1))
181 endif
182 $$(LOOP_OVER_DIRS)
184 endef
186 $(foreach subtier,export compile binaries libs tools,$(eval $(call CREATE_SUBTIER_TRAVERSAL_RULE,$(subtier))))
188 tools export:: $(SUBMAKEFILES)
189 $(LOOP_OVER_TOOL_DIRS)
191 endif # ifdef TIERS
193 endif # ifeq ($(NO_RECURSE_MAKELEVEL),$(MAKELEVEL))
195 endif # ifeq (.,$(DEPTH))
197 ifdef COMPILE_ENVIRONMENT
199 # Aggregate all dependency files relevant to a binaries build except in
200 # the mozilla top-level directory.
201 ifneq (.,$(DEPTH))
202 ALL_DEP_FILES := \
203 $(BINARIES_PP) \
204 $(addsuffix .pp,$(addprefix $(MDDEPDIR)/,$(sort \
205 $(TARGETS) \
206 $(filter-out $(SOBJS) $(ASOBJS) $(EXCLUDED_OBJS),$(OBJ_TARGETS)) \
207 ))) \
208 $(NULL)
209 endif
211 binaries libs:: $(TARGETS) $(BINARIES_PP)
212 # Disable dependency aggregation on PGO builds because of bug 934166.
213 ifeq (,$(MOZ_PGO)$(MOZ_PROFILE_USE)$(MOZ_PROFILE_GENERATE))
214 ifneq (.,$(DEPTH))
215 @$(if $^,$(call py_action,link_deps,-o binaries --group-all --topsrcdir $(topsrcdir) --topobjdir $(DEPTH) --dist $(DIST) $(ALL_DEP_FILES)))
216 endif
217 endif
219 endif
221 recurse:
222 @$(RECURSED_COMMAND)
223 $(LOOP_OVER_PARALLEL_DIRS)
224 $(LOOP_OVER_DIRS)
225 $(LOOP_OVER_TOOL_DIRS)