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
9 # The traditional model of directory traversal with make is as follows:
19 # Pseudo derecurse transforms the above into:
25 # MOZ_PSEUDO_DERECURSE can have values other than 1.
26 ifeq (1_.
,$(if
$(MOZ_PSEUDO_DERECURSE
),1)_
$(DEPTH
))
30 # Disable build status for mach in top directories without TIERS.
31 # In practice this disables it when recursing under js/src, which confuses mach.
36 # Main rules (export, compile, binaries, libs and tools) call recurse_* rules.
37 # This wrapping is only really useful for build status.
38 compile binaries libs
export tools
::
39 $(call BUILDSTATUS
,TIER_START
$@
)
41 $(call BUILDSTATUS
,TIER_FINISH
$@
)
43 # Carefully avoid $(eval) type of rule generation, which makes pymake slower
45 # Get current tier and corresponding subtiers from the data in root.mk.
46 CURRENT_TIER
:= $(filter $(foreach tier
,compile binaries libs
export tools
,recurse_
$(tier
) $(tier
)-deps
),$(MAKECMDGOALS
))
47 ifneq (,$(filter-out 0 1,$(words $(CURRENT_TIER
))))
48 $(error
$(CURRENT_TIER
) not supported on the same make command line
)
50 CURRENT_TIER
:= $(subst recurse_
,,$(CURRENT_TIER
:-deps
=))
51 CURRENT_SUBTIERS
:= $($(CURRENT_TIER
)_subtiers
)
53 # The rules here are doing directory traversal, so we don't want further
54 # recursion to happen when running make -C subdir $tier. But some make files
55 # further call make -C something else, and sometimes expect recursion to
56 # happen in that case (see browser/metro/locales/Makefile.in for example).
57 # Conveniently, every invocation of make increases MAKELEVEL, so only stop
58 # recursion from happening at current MAKELEVEL + 1.
61 export NO_RECURSE_MAKELEVEL
=1
63 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 # Get all directories traversed for all subtiers in the current tier, or use
68 # directly the $(*_dirs) variables available in root.mk when there is no
69 # TIERS (like for js/src).
70 TIER_DIRS
= $(or
$($(1)_dirs
),$(foreach subtier
,$($(1)_subtiers
),$($(1)_subtier_
$(subtier
))))
71 CURRENT_DIRS
:= $(call TIER_DIRS
,$(CURRENT_TIER
))
73 ifneq (,$(filter binaries libs
,$(CURRENT_TIER
)))
75 STAMP_TOUCH
= $(TOUCH
) $(@D
)/binaries
78 # Subtier delimiter rules
79 $(addprefix subtiers
/,$(addsuffix _start
/$(CURRENT_TIER
),$(CURRENT_SUBTIERS
))): subtiers
/%_start
/$(CURRENT_TIER
): $(if
$(WANT_STAMPS
),$(call mkdir_deps
,subtiers
/%_start
))
82 $(addprefix subtiers
/,$(addsuffix _finish
/$(CURRENT_TIER
),$(CURRENT_SUBTIERS
))): subtiers
/%_finish
/$(CURRENT_TIER
): $(if
$(WANT_STAMPS
),$(call mkdir_deps
,subtiers
/%_finish
))
85 $(addprefix subtiers
/,$(addsuffix /$(CURRENT_TIER
),$(CURRENT_SUBTIERS
))): %/$(CURRENT_TIER
): $(if
$(WANT_STAMPS
),$(call mkdir_deps
,%))
88 GARBAGE_DIRS
+= subtiers
90 # Recursion rule for all directories traversed for all subtiers in the
92 # root.mk defines subtier_of_* variables, that map a normalized subdir path to
93 # a subtier name (e.g. subtier_of_memory_jemalloc = base)
94 $(addsuffix /$(CURRENT_TIER
),$(CURRENT_DIRS
)): %/$(CURRENT_TIER
):
95 +@
$(MAKE
) -C
$* $(if
$(filter $*,$(tier_
$(subtier_of_
$(subst /,_
,$*))_staticdirs
)),,$(CURRENT_TIER
))
96 # Ensure existing stamps are up-to-date, but don't create one if submake didn't create one.
97 $(if
$(wildcard $@
),@
$(STAMP_TOUCH
))
99 # Dummy rules for possibly inexisting dependencies for the above tier targets
100 $(addsuffix /Makefile
,$(CURRENT_DIRS
)) $(addsuffix /backend.mk
,$(CURRENT_DIRS
)):
102 # The export tier requires nsinstall, which is built from config. So every
103 # subdirectory traversal needs to happen after traversing config.
104 ifeq ($(CURRENT_TIER
),export)
105 $(addsuffix /$(CURRENT_TIER
),$(filter-out config
,$(CURRENT_DIRS
))): config
/$(CURRENT_TIER
)
108 ifdef COMPILE_ENVIRONMENT
109 ifneq (,$(filter libs binaries
,$(CURRENT_TIER
)))
110 # When doing a "libs" build, target_libs.mk ensures the interesting dependency data
111 # is available in the "binaries" stamp. Once recursion is done, aggregate all that
112 # dependency info so that stamps depend on relevant files and relevant other stamps.
113 # When doing a "binaries" build, the aggregate dependency file and those stamps are
114 # used and allow to skip recursing directories where changes are not going to require
115 # rebuild. A few directories, however, are still traversed all the time, mostly, the
116 # gyp managed ones and js/src.
117 # A few things that are not traversed by a "binaries" build, but should, in an ideal
118 # world, are nspr, nss, icu and ffi.
119 recurse_
$(CURRENT_TIER
):
120 @
$(MAKE
) binaries-deps
122 # Creating binaries-deps.mk directly would make us build it twice: once when beginning
123 # the build because of the include, and once at the end because of the stamps.
124 binaries-deps
: $(addsuffix /binaries
,$(CURRENT_DIRS
))
125 @
$(call py_action
,link_deps
,-o
$@.mk
--group-by-depfile
--topsrcdir
$(topsrcdir
) --topobjdir
$(DEPTH
) --dist $(DIST
) --guard
$(addprefix ',$(addsuffix ',$^
)))
128 ifeq (recurse_binaries
,$(MAKECMDGOALS
))
129 $(call include_deps
,binaries-deps.mk
)
134 DIST_GARBAGE
+= binaries-deps.mk binaries-deps
140 # Don't recurse if MAKELEVEL is NO_RECURSE_MAKELEVEL as defined above
141 ifeq ($(NO_RECURSE_MAKELEVEL
),$(MAKELEVEL
))
143 compile binaries libs
export tools
::
146 #########################
147 # Tier traversal handling
148 #########################
153 $(call BUILDSTATUS
,TIER_START
$@
)
154 $(foreach tier
,$(TIERS
), $(if
$(filter-out libs_precompile tools_precompile
,$@_
$(tier
)), \
155 $(if
$(filter libs
,$@
),$(foreach dir, $(tier_
$(tier
)_staticdirs
), $(call TIER_DIR_SUBMAKE
,$@
,$(tier
),$(dir),,1))) \
156 $(foreach dir, $(tier_
$(tier
)_dirs
), $(call TIER_DIR_SUBMAKE
,$@
,$(tier
),$(dir),$@
))))
157 $(call BUILDSTATUS
,TIER_FINISH
$@
)
161 define CREATE_SUBTIER_TRAVERSAL_RULE
162 PARALLEL_DIRS_
$(1) = $$(addsuffix _
$(1),$$(PARALLEL_DIRS
))
164 .PHONY
: $(1) $$(PARALLEL_DIRS_
$(1))
167 $$(PARALLEL_DIRS_
$(1)): %_
$(1): %/Makefile
168 +@
$$(call SUBMAKE
,$(1),$$*)
171 $(1):: $$(SUBMAKEFILES
)
173 +@
$(MAKE
) $$(PARALLEL_DIRS_
$(1))
179 $(foreach subtier
,export compile binaries libs tools
,$(eval
$(call CREATE_SUBTIER_TRAVERSAL_RULE
,$(subtier
))))
181 tools
export:: $(SUBMAKEFILES
)
182 $(LOOP_OVER_TOOL_DIRS
)
186 endif # ifeq ($(NO_RECURSE_MAKELEVEL),$(MAKELEVEL))
188 endif # ifeq (1_.,$(MOZ_PSEUDO_DERECURSE)_$(DEPTH))
190 ifdef MOZ_PSEUDO_DERECURSE
192 ifdef COMPILE_ENVIRONMENT
194 # Aggregate all dependency files relevant to a binaries build except in
195 # the mozilla top-level directory.
199 $(addsuffix .pp
,$(addprefix $(MDDEPDIR
)/,$(sort \
201 $(filter-out $(SOBJS
) $(ASOBJS
) $(EXCLUDED_OBJS
),$(OBJ_TARGETS
)) \
206 binaries libs
:: $(TARGETS
) $(BINARIES_PP
)
208 @
$(if
$^
,$(call py_action
,link_deps
,-o binaries
--group-all
--topsrcdir
$(topsrcdir
) --topobjdir
$(DEPTH
) --dist $(DIST
) $(ALL_DEP_FILES
)))
213 endif # ifdef MOZ_PSEUDO_DERECURSE
217 $(LOOP_OVER_PARALLEL_DIRS
)
219 $(LOOP_OVER_TOOL_DIRS
)