xref: /freebsd/share/mk/dirdeps.mk (revision f9bc005b8ef3b507a5ecbc2d7fe4411ef70eff38)
1# $Id: dirdeps.mk,v 1.178 2026/05/09 20:33:46 sjg Exp $
2
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2010-2026, Simon J. Gerraty
6# Copyright (c) 2010-2018, Juniper Networks, Inc.
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30# Much of the complexity here is for supporting cross-building.
31# If a tree does not support that, simply using plain Makefile.depend
32# should provide sufficient clue.
33# Otherwise the recommendation is to use Makefile.depend.${MACHINE}
34# as expected below.
35
36# Note: this file gets multiply included.
37# This is what we do with DIRDEPS
38
39# DIRDEPS:
40#	This is a list of directories - relative to SRCTOP, it is
41#	normally only of interest to .MAKE.LEVEL 0.
42#	In some cases the entry may be qualified with a .<machine>
43#	or .<target_spec> suffix (see TARGET_SPEC_VARS below),
44#	for example to force building something for the pseudo
45#	machines "host" or "common" regardless of current ${MACHINE}.
46#
47#	All unqualified entries end up being qualified with .${TARGET_SPEC}
48#	and partially qualified (if TARGET_SPEC_VARS has multiple
49#	entries) are also expanded to a full .<target_spec>.
50#	The  _DIRDEP_USE target uses the suffix to set TARGET_SPEC
51#	correctly when visiting each entry.
52#
53#	The fully qualified directory entries are used to construct a
54#	dependency graph that will drive the build later.
55#
56#	Also, for each fully qualified directory target, we will search
57#	using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional
58#	dependencies.  We use Makefile.depend (default value for
59#	.MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to
60#	distinguish them from others.
61#
62#	Before each Makefile.depend file is read, we set
63#	DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for
64#	its directory, and DEP_MACHINE etc according to the .<target_spec>
65#	represented by the suffix of the corresponding target.
66#
67#	Since each Makefile.depend file includes dirdeps.mk, this
68#	processing is recursive and results in .MAKE.LEVEL 0 learning the
69#	dependencies of the tree wrt the initial directory (_DEP_RELDIR).
70#
71#	NOTE: given the extent of processing that DIRDEPS undergoes it
72#	is important that any variables in entries use :U to guard
73#	against surprises when undefined.
74#
75# TARGET_SPEC_VARS
76#	The default value is just MACHINE, and for most environments
77#	this is sufficient.  The _DIRDEP_USE target actually sets
78#	both MACHINE and TARGET_SPEC to the suffix of the current
79#	target so that in the general case TARGET_SPEC can be ignored.
80#
81#	If more than MACHINE is needed then sys.mk needs to decompose
82#	TARGET_SPEC and set the relevant variables accordingly.
83#	It is important that MACHINE be included in and actually be
84#	the first member of TARGET_SPEC_VARS.  This allows other
85#	variables to be considered optional, and some of the treatment
86#	below relies on MACHINE being the first entry.
87#	Note: TARGET_SPEC cannot contain any '.'s so the target
88#	triple used by compiler folk won't work (directly anyway).
89#
90#	For example:
91#
92#		# Always list MACHINE first,
93#		# other variables might be optional.
94#		TARGET_SPEC_VARS = MACHINE TARGET_OS
95#		.if ${TARGET_SPEC:Uno:M*,*} != ""
96#		_tspec := ${TARGET_SPEC:S/,/ /g}
97#		MACHINE := ${_tspec:[1]}
98#		TARGET_OS := ${_tspec:[2]}
99#		# etc.
100#		# We need to stop that TARGET_SPEC affecting any submakes
101#		# and deal with MACHINE=${TARGET_SPEC} in the environment.
102#		TARGET_SPEC =
103#		# export but do not track
104#		.export-env TARGET_SPEC
105#		.export ${TARGET_SPEC_VARS}
106#		.for v in ${TARGET_SPEC_VARS:O:u}
107#		.if empty($v)
108#		.undef $v
109#		.endif
110#		.endfor
111#		.endif
112#		# make sure we know what TARGET_SPEC is
113#		# as we may need it to find Makefile.depend*
114#		TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
115#
116#	The following variables can influence the initial DIRDEPS
117#	computation with regard to the TARGET_SPECs that will be
118#	built.
119#	Most should also be considered by init.mk
120#
121#	ONLY_TARGET_SPEC_LIST
122#		Defines a list of TARGET_SPECs for which the current
123#		directory can be built.
124#		If ALL_MACHINES is defined, we build for all the
125#		TARGET_SPECs listed.
126#
127#	ONLY_MACHINE_LIST
128#		As for ONLY_TARGET_SPEC_LIST but only specifies
129#		MACHINEs.
130#
131#	NOT_TARGET_SPEC_LIST
132#		A list of TARGET_SPECs for which the current
133#		directory should not be built.
134#
135#	NOT_MACHINE_LIST
136#		A list of MACHINEs the current directory should not be
137#		built for.
138#
139# DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS)
140#	It is discouraged, but sometimes necessary for a
141#	Makefile.depend file to influence the environment.
142#	Doing this correctly (especially if using DIRDEPS_CACHE) is
143#	tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS
144#	and dirdeps.mk will do the deed:
145#
146#		MK_UEFI = yes
147#		DIRDEPS_EXPORT_VARS = MK_UEFI
148#
149# _build_xtra_dirs
150#	local.dirdeps.mk can add targets to this variable.
151#	They will be hooked into the build, but independent of
152#	any other DIRDEP.
153#
154#	This allows for adding TESTS to the build, such that the build
155#	will fail if any test fails, but without the risk of introducing
156#	circular dependencies.
157
158now_utc ?= ${%s:L:localtime}
159.if !defined(start_utc)
160start_utc := ${now_utc}
161.endif
162
163.if !target(bootstrap) && (make(bootstrap) || \
164	make(bootstrap-this) || \
165	make(bootstrap-recurse) || \
166	make(bootstrap-empty))
167# disable most of below
168.MAKE.LEVEL = 1
169.endif
170
171# touch this at your peril
172_DIRDEP_USE_LEVEL?= 0
173.if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
174# only the first instance is interested in all this
175
176# the first time we are included the _DIRDEP_USE target will not be defined
177# we can use this as a clue to do initialization and other one time things.
178.if !target(_DIRDEP_USE)
179
180# do some setup we only need once
181_CURDIR ?= ${.CURDIR}
182_OBJDIR ?= ${.OBJDIR}
183
184.if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*[/.]*} != ""
185# This little trick let's us do
186#
187# mk -f dirdeps.mk some/dir.${TARGET_SPEC}
188#
189all:
190${.TARGETS:Nall}: all
191DIRDEPS := ${.TARGETS:M*[/.]*}
192# so that -DNO_DIRDEPS works
193DEP_RELDIR := ${DIRDEPS:[1]:R}
194# this will become DEP_MACHINE below
195TARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//}
196.if ${TARGET_MACHINE:N*/*} == ""
197TARGET_MACHINE := ${MACHINE}
198.endif
199# disable DIRDEPS_CACHE as it does not like this trick
200MK_DIRDEPS_CACHE = no
201# incase anyone needs to know
202_dirdeps_cmdline:
203.endif
204
205# make sure we get the behavior we expect
206.MAKE.SAVE_DOLLARS = no
207
208# make sure these are empty to start with
209_DEP_TARGET_SPEC =
210
211# If TARGET_SPEC_VARS is other than just MACHINE
212# it should be set by sys.mk or similar by now.
213# TARGET_SPEC must not contain any '.'s.
214TARGET_SPEC_VARS ?= MACHINE
215# we allow for this to be a subset
216TARGET_SPEC_VARS.host ?= MACHINE
217TARGET_SPEC_VARS.host32 = ${TARGET_SPEC_VARS.host}
218# this is what we started with
219TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
220# this is what we mostly use below
221DEP_TARGET_SPEC_VARS = ${TARGET_SPEC_VARS.${DEP_MACHINE}:U${TARGET_SPEC_VARS}}
222DEP_TARGET_SPEC = ${DEP_TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,}
223# make sure we have defaults
224.for v in ${DEP_TARGET_SPEC_VARS}
225DEP_$v ?= ${$v}
226.endfor
227
228.if ${TARGET_SPEC_VARS:[#]} > 1
229# Ok, this gets more complex (putting it mildly).
230# In order to stay sane, we need to ensure that all the build_dirs
231# we compute below are fully qualified wrt DEP_TARGET_SPEC.
232# The makefiles may only partially specify (eg. MACHINE only),
233# so we need to construct a set of modifiers to fill in the gaps.
234_tspec_x := ${TARGET_SPEC_VARS:${M_RANGE:Urange}}
235# this handles unqualified entries
236M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC};
237# there needs to be at least one item missing for these to make sense
238.for i in ${_tspec_x:[2..-1]}
239_tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,}
240_tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,}
241M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i};
242.endfor
243TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]}
244.if ${TARGET_SPEC_VARS.host} == ${TARGET_SPEC_VARS}
245M_dep_qual_fixes.host = ${M_dep_qual_fixes}
246.elif ${TARGET_SPEC_VARS.host:[#]} > 1
247_htspec_x := ${TARGET_SPEC_VARS.host:${M_RANGE:Urange}}
248# this handles unqualified entries
249M_dep_qual_fixes.host = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC};
250# there needs to be at least one item missing for these to make sense
251.for i in ${_htspec_x:[2..-1]}
252_htspec_m$i := ${TARGET_SPEC_VARS.host:[2..$i]:@w@[^,]+@:ts,}
253_htspec_a$i := ,${TARGET_SPEC_VARS.host:[$i..-1]:@v@$$$${DEP_$v}@:ts,}
254M_dep_qual_fixes.host += C;(\.${_htspec_m$i})$$;\1${_htspec_a$i};
255.endfor
256.else
257M_dep_qual_fixes.host = U
258.endif
259.else
260# A harmless? default.
261M_dep_qual_fixes = U
262.endif
263M_dep_qual_fixes.host ?= ${M_dep_qual_fixes}
264M_dep_qual_fixes.host32 = ${M_dep_qual_fixes.host}
265
266.if !defined(.MAKE.DEPENDFILE_PREFERENCE)
267# .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater?
268# you really want this set by sys.mk or similar
269.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T}
270.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}"
271.if ${TARGET_SPEC} != ${MACHINE}
272.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE}
273.endif
274.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}
275.endif
276.endif
277
278_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T}
279_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*}
280
281# for machine specific dependfiles we require ${MACHINE} to be at the end
282# also for the sake of sanity we require a common prefix
283.if !defined(.MAKE.DEPENDFILE_PREFIX)
284# knowing .MAKE.DEPENDFILE_PREFIX helps
285.if !empty(_machine_dependfiles)
286.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R}
287.else
288.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T}
289.endif
290.endif
291
292# turn a list into a set of :N modifiers
293# NskipFoo = ${Foo:${M_ListToSkip}}
294M_ListToSkip ?= O:u:S,^,N,:ts:
295
296# this is how we identify non-machine specific dependfiles
297N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}}
298
299# this gets reset for each dirdep we check
300DEP_RELDIR ?= ${RELDIR}
301
302# remember the initial value of DEP_RELDIR - we test for it below.
303_DEP_RELDIR := ${DEP_RELDIR}
304
305# this can cause lots of output!
306# set to a set of glob expressions that might match RELDIR
307DEBUG_DIRDEPS ?= no
308
309# make sure this target exists
310dirdeps: beforedirdeps .WAIT
311beforedirdeps:
312
313.endif				# !target(_DIRDEP_USE)
314
315.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
316_debug_reldir = 1
317.else
318_debug_reldir = 0
319.endif
320.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend depend:L:M$x}@} != ""
321_debug_search = 1
322.else
323_debug_search = 0
324.endif
325.if ${DEBUG_DIRDEPS:Mno*recurse} != ""
326BUILD_DIRDEPS_RECURSE = no
327.endif
328.if ${DEBUG_DIRDEPS:M-V} != ""
329_V_READ_DIRDEPS = yes
330.endif
331
332# First off, we want to know what ${MACHINE} to build for.
333# This can be complicated if we are using a mixture of ${MACHINE} specific
334# and non-specific Makefile.depend*
335
336# if we were included recursively _DEP_TARGET_SPEC should be valid.
337.if empty(_DEP_TARGET_SPEC)
338DEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}}
339_DEP_TARGET_SPEC := ${DEP_TARGET_SPEC}
340.if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != ""
341# record that we've read dependfile for this
342_dirdeps_checked.${_CURDIR}.${TARGET_SPEC}:
343.endif
344.endif
345
346# by now _DEP_TARGET_SPEC should be set, parse it.
347.if ${TARGET_SPEC_VARS:[#]} > 1
348# we need to parse DEP_MACHINE may or may not contain more info
349_tspec := ${_DEP_TARGET_SPEC:S/,/ /g}
350.for i in ${_tspec_x}
351DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]}
352.endfor
353.for v in ${DEP_TARGET_SPEC_VARS:O:u}
354.if empty(DEP_$v)
355.undef DEP_$v
356.endif
357.endfor
358.else
359DEP_MACHINE := ${_DEP_TARGET_SPEC}
360.endif
361
362# reset each time through
363_build_all_dirs =
364_build_xtra_dirs =
365
366# DIRDEPS_CACHE can be very handy for debugging.
367# Also if repeatedly building the same target,
368# we can avoid the overhead of re-computing the tree dependencies.
369MK_DIRDEPS_CACHE ?= no
370BUILD_DIRDEPS_CACHE ?= no
371BUILD_DIRDEPS ?= yes
372
373.if ${MK_DIRDEPS_CACHE} == "yes"
374# this is where we will cache all our work
375DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
376.endif
377
378# sanity check: Makefile.depend.options should *not* include us
379.if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}.options} != ""
380.error ${DEP_RELDIR}/${.MAKE.DEPENDFILE_PREFIX}.options: should include dirdeps-options.mk
381.endif
382
383# pickup customizations
384# as below you can use !target(_DIRDEP_USE) to protect things
385# which should only be done once.
386.-include <local.dirdeps.mk>
387
388.if !target(_DIRDEP_USE)
389# things we skip for host tools
390SKIP_HOSTDIR ?=
391
392NSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${M_ListToSkip}}
393
394# things we always skip
395# SKIP_DIRDEPS allows for adding entries on command line.
396SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS}
397SKIP_DIR.host += ${SKIP_HOSTDIR}
398
399DEP_SKIP_DIR = ${SKIP_DIR} \
400	${SKIP_DIR.${DEP_TARGET_SPEC}:U} \
401	${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \
402	${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \
403	${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@}
404
405
406NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}}
407
408.if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
409NO_DIRDEPS =
410.elif defined(WITHOUT_DIRDEPS_BELOW)
411NO_DIRDEPS_BELOW =
412.endif
413
414.if defined(NO_DIRDEPS)
415# confine ourselves to the original dir and below.
416DIRDEPS_FILTER += M${_DEP_RELDIR}*
417.elif defined(NO_DIRDEPS_BELOW)
418DIRDEPS_FILTER += M${_DEP_RELDIR}
419.endif
420
421# this is what we run below
422DIRDEP_MAKE ?= ${.MAKE}
423DIRDEP_DIR ?= ${.TARGET:R}
424# we normally want the default target
425DIRDEP_TARGETS ?=
426
427# if you want us to report load averages during build
428# DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT};
429
430DIRDEP_LOADAVG_CMD ?= ${UPTIME:Uuptime} | sed 's,.*\(load\),\1,'
431DIRDEP_LOADAVG_LAST = 0
432# yes the expression here is a bit complicated,
433# the trick is to only eval ${DIRDEP_LOADAVG_LAST::=${now_utc}}
434# when we want to report.
435# Note: expr(1) will exit 1 if the expression evaluates to 0
436# hence the  || true
437DIRDEP_LOADAVG_REPORT = \
438	test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTERVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \
439	echo "${TRACER}`${DIRDEP_LOADAVG_CMD}`"
440
441# we suppress SUBDIR when visiting the leaves
442# we assume sys.mk will set MACHINE_ARCH
443# you can add extras to DIRDEP_USE_ENV
444# if there is no makefile in the target directory, we skip it.
445_DIRDEP_USE:	.USE .MAKE
446	@for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \
447		test -s ${.TARGET:R}/$$m || continue; \
448		echo "${TRACER}Checking ${.TARGET:S,^${SRCTOP}/,,} for ${.TARGET:E} ..."; \
449		${DIRDEP_USE_PRELUDE} \
450		MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \
451		TARGET_SPEC=${.TARGET:E} \
452		MACHINE=${.TARGET:E} \
453		${DIRDEP_MAKE} -C ${DIRDEP_DIR} ${DIRDEP_TARGETS} || exit 1; \
454		${DIRDEP_USE_EPILOGUE} \
455		break; \
456	done
457
458.ifdef ALL_MACHINES
459.if empty(ONLY_TARGET_SPEC_LIST) && empty(ONLY_MACHINE_LIST)
460# we start with everything
461_machine_list != echo; 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}* 2> /dev/null
462
463# some things we know we want to ignore
464DIRDEPS_TARGETS_SKIP_LIST += \
465	*~ \
466	*.bak \
467	*.inc \
468	*.old \
469	*.options \
470	*.orig \
471	*.rej \
472
473# first trim things we know we want to skip
474# and provide canonical form
475_machine_list := ${_machine_list:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}:T:E}
476
477# cater for local complexities
478# local.dirdeps.mk can set
479# DIRDEPS_ALL_MACHINES_FILTER and
480# DIRDEPS_ALL_MACHINES_FILTER_XTRAS for final tweaks
481
482.if !empty(ALL_TARGET_SPEC_LIST)
483.if ${_debug_reldir}
484.info ALL_TARGET_SPEC_LIST=${ALL_TARGET_SPEC_LIST}
485.endif
486DIRDEPS_ALL_MACHINES_FILTER += \
487	@x@$${ALL_TARGET_SPEC_LIST:@s@$${x:M$$s}@}@
488.elif !empty(ALL_MACHINE_LIST)
489.if ${_debug_reldir}
490.info ALL_MACHINE_LIST=${ALL_MACHINE_LIST}
491.endif
492.if ${TARGET_SPEC_VARS:[#]} > 1
493# the space below can result in extraneous ':'
494DIRDEPS_ALL_MACHINES_FILTER += \
495	@x@$${ALL_MACHINE_LIST:@m@$${x:M$$m,*} $${x:M$$m}@}@
496.else
497DIRDEPS_ALL_MACHINES_FILTER += \
498	@x@$${ALL_MACHINE_LIST:@m@$${x:M$$m}@}@
499.endif
500.endif
501# add local XTRAS - default to something benign
502DIRDEPS_ALL_MACHINES_FILTER += \
503	${DIRDEPS_ALL_MACHINES_FILTER_XTRAS:UNbak}
504
505.if ${_debug_reldir}
506.info _machine_list=${_machine_list}
507.info DIRDEPS_ALL_MACHINES_FILTER=${DIRDEPS_ALL_MACHINES_FILTER}
508.endif
509
510_only_machines := ${_machine_list:${DIRDEPS_ALL_MACHINES_FILTER:ts:}:S,:, ,g}
511.else
512_only_machines := ${ONLY_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U}
513.endif
514
515.if empty(_only_machines)
516# we must be boot-strapping
517_only_machines := ${TARGET_MACHINE:U${ALL_TARGET_SPEC_LIST:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}}
518.endif
519
520# cleanup the result
521_only_machines := ${_only_machines:O:u}
522
523.if ${_debug_reldir}
524.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: ALL_MACHINES _only_machines=${_only_machines}
525.endif
526
527.else				# ! ALL_MACHINES
528# if ONLY_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that.
529# Note that ONLY_TARGET_SPEC_LIST should be fully qualified.
530# if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST
531# otherwise DEP_MACHINE is it - so DEP_MACHINE will match.
532_only_machines := ${ONLY_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*}
533.if empty(_only_machines)
534_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
535.endif
536.endif
537
538.if !empty(NOT_MACHINE_LIST)
539_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
540.endif
541.if !empty(NOT_TARGET_SPEC_LIST)
542# we must first qualify
543_dm := ${DEP_MACHINE}
544_only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
545DEP_MACHINE := ${_dm}
546_only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}}
547.endif
548# clean up
549_only_machines := ${_only_machines:O:u}
550
551.if ${_debug_reldir}
552.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _only_machines=${_only_machines}
553.endif
554
555# make sure we have a starting place?
556DIRDEPS ?= ${RELDIR}
557.endif				# target
558
559.if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW)
560.if ${MK_DIRDEPS_CACHE} == "yes"
561
562# just ensure this exists
563build-dirdeps:
564
565M_oneperline = @x@\\${.newline}	$$x@
566
567.if ${BUILD_DIRDEPS_CACHE} == "no"
568.if !target(dirdeps-cached)
569# we do this via sub-make
570BUILD_DIRDEPS = no
571
572# ignore anything but these
573.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*
574
575dirdeps: dirdeps-cached
576dirdeps-cached:	${DIRDEPS_CACHE} .MAKE
577	@echo "${TRACER}Using ${DIRDEPS_CACHE}"
578	@${DIRDEPS_CACHED_ENV} MAKELEVEL=${.MAKE.LEVEL} \
579	TARGET_SPEC=${TARGET_SPEC} \
580	${TARGET_SPEC_VARS:@v@$v=${$v}@} \
581	${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \
582		dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no
583
584# leaf makefiles rarely work for building DIRDEPS_CACHE
585.if ${RELDIR} != "."
586BUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk
587.endif
588
589# these should generally do
590BUILD_DIRDEPS_MAKEFILE ?=
591BUILD_DIRDEPS_OVERRIDES ?=
592BUILD_DIRDEPS_TARGETS ?= ${.TARGETS}
593
594# sometimes we temporarily want to block updating of DIRDEPS_CACHE
595.if ${MK_UPDATE_DIRDEPS_CACHE:Uyes} == "no" && exists(${DIRDEPS_CACHE})
596STATIC_DIRDEPS_CACHE ?= ${DIRDEPS_CACHE}
597.endif
598
599.if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == ""
600# export this for dirdeps-cache-update.mk
601DYNAMIC_DIRDEPS_CACHE := ${DIRDEPS_CACHE}
602.export DYNAMIC_DIRDEPS_CACHE
603# we need the .meta file to ensure we update if
604# any of the Makefile.depend* changed.
605# We do not want to compare the command line though.
606${DIRDEPS_CACHE}:	.META .NOMETA_CMP
607	+@{ echo '# Autogenerated - do NOT edit!'; echo; \
608	echo 'BUILD_DIRDEPS=no'; echo; \
609	echo '.include <dirdeps.mk>'; echo; \
610	} > ${.TARGET}.new
611	+@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \
612	DIRDEPS="${DIRDEPS}" \
613	TARGET_SPEC=${TARGET_SPEC} \
614	MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \
615	${BUILD_DIRDEPS_MAKEFILE} \
616	${BUILD_DIRDEPS_TARGETS} \
617	${BUILD_DIRDEPS_OVERRIDES} \
618	BUILD_DIRDEPS_CACHE=yes \
619	.MAKE.DEPENDFILE=.none \
620	${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \
621	${.MAKEFLAGS:S,-D ,-D,gW:M*WITH*} \
622	${.MAKEFLAGS:S,-d ,-d,gW:M-d*} \
623	3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{SRCTOP}/_{SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \
624	{ ${BUILD_DIRDEPS_EPILOGUE} mv ${.TARGET}.new ${.TARGET}; }
625
626.endif
627.endif
628.elif !target(_count_dirdeps)
629# we want to capture the dirdeps count in the cache
630.END: _count_dirdeps
631_count_dirdeps: .NOMETA
632	@{ echo; echo '.info $${.newline}$${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS}'; } >&3
633
634.endif
635.elif !make(dirdeps) && !target(_count_dirdeps)
636beforedirdeps: _count_dirdeps
637_count_dirdeps: .NOMETA
638	@echo "${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} ${DIRDEP_INFO_XTRAS} seconds=`expr ${now_utc} - ${start_utc}`"
639
640.endif
641.endif
642
643.if ${BUILD_DIRDEPS} == "yes"
644
645# the rest is done repeatedly for every Makefile.depend we read.
646# if we are anything but the original dir we care only about the
647# machine type we were included for..
648
649.if ${DEP_RELDIR} == "."
650_this_dir := ${SRCTOP}
651.else
652_this_dir := ${SRCTOP}/${DEP_RELDIR}
653.endif
654
655# on rare occasions, there can be a need for extra help
656_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc
657.-include <${_dep_hack}>
658.-include <${_dep_hack:R}.options>
659
660.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC}
661# this should be all
662_machines := ${DEP_MACHINE}
663.else
664# this is the machine list we actually use below
665_machines := ${_only_machines}
666
667.if defined(HOSTPROG) || ${DEP_MACHINE:Nhost*} == ""
668# we need to build this guy's dependencies for host as well.
669.if ${DEP_MACHINE:Nhost*} == ""
670_machines += ${DEP_MACHINE}
671.else
672_machines += host
673.endif
674.endif
675
676_machines := ${_machines:O:u}
677.endif
678
679.if ${DEP_TARGET_SPEC_VARS:[#]} > 1
680# we need to tweak _machines
681_dm := ${DEP_MACHINE}
682# apply the same filtering that we do when qualifying DIRDEPS.
683# M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
684# Again we expect that any already qualified machines are fully qualified.
685_machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:S,^.,,}
686DEP_MACHINE := ${_dm}
687_machines := ${_machines:${M_dep_qual_fixes.${DEP_MACHINE}:U${M_dep_qual_fixes}:ts:}:O:u}
688.endif
689
690# reset each time through
691_build_dirs =
692
693.if ${DEP_RELDIR} == ${_DEP_RELDIR} && ${_CURDIR} != ${SRCTOP}
694# pickup other machines for this dir if necessary
695_build_dirs += ${_machines:@m@${_CURDIR}.$m@}
696.endif
697
698.if ${_debug_reldir}
699.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]}
700.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS=${DIRDEPS:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
701.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}'
702.endif
703
704.if !empty(DIRDEPS)
705# these we reset each time through as they can depend on DEP_MACHINE
706DEP_DIRDEPS_FILTER = \
707	${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \
708	${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \
709	${DIRDEPS_FILTER:U}
710
711.if empty(DEP_DIRDEPS_FILTER)
712# something harmless
713DEP_DIRDEPS_FILTER = u
714.endif
715
716# this is applied after we have computed build dirs
717# so everything is fully qualified and starts with ${SRCTOP}/
718DEP_DIRDEPS_BUILD_DIR_FILTER = \
719	${DIRDEPS_BUILD_DIR_FILTER.${DEP_TARGET_SPEC}:U} \
720	${TARGET_SPEC_VARS:@v@${DIRDEPS_BUILD_DIR_FILTER.${DEP_$v}:U}@} \
721	${DIRDEPS_BUILD_DIR_FILTER:U}
722
723.if empty(DEP_DIRDEPS_BUILD_DIR_FILTER)
724# something harmless
725DEP_DIRDEPS_BUILD_DIR_FILTER = u
726.endif
727
728# this is what we start with
729__depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:C,//+,/,g:S,/$,,:O:u:@d@${SRCTOP}/$d@}
730
731# some entries may be qualified with .<machine> or .<target_spec>
732# we can tell the unqualified ones easily - because they exist
733__unqual_depdirs := ${__depdirs:@d@${exists($d):?$d:}@}
734__qual_depdirs := ${__depdirs:${__unqual_depdirs:Uno:${M_ListToSkip}}:C,/(\.[^.]*)$,\1,}
735
736.if ${DEP_RELDIR} == ${_DEP_RELDIR}
737# if it was called out - we likely need it.
738__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} \
739	${DPADD:U.:M${HOST_OBJTOP32:Uno}/*:S,${HOST_OBJTOP32:Uno}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host32,:N.*:@d@${SRCTOP}/$d@}
740__qual_depdirs += ${__hostdpadd}
741.endif
742
743.if ${_debug_reldir}
744.info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:}
745.info DEP_DIRDEPS_BUILD_DIR_FILTER=${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:}
746.info depdirs=${__depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
747.info qualified=${__qual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
748.info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
749.endif
750
751# _build_dirs is what we will feed to _DIRDEP_USE
752_build_dirs += \
753	${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \
754	${__qual_depdirs:N*.host} \
755	${_machines:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \
756	${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@}
757
758# qualify everything now
759# make sure we do not mess with qualifying "host" entries
760_build_dirs := ${_build_dirs:M*.host*:${M_dep_qual_fixes.host:ts:}} \
761	${_build_dirs:N*.host*:${M_dep_qual_fixes:ts:}}
762# some filters can only be applied now
763_build_dirs := ${_build_dirs:${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:}:O:u}
764.if ${_debug_reldir}
765.info _build_dirs=${_build_dirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
766.endif
767
768.endif				# empty DIRDEPS
769
770_build_all_dirs += ${_build_dirs} ${_build_xtra_dirs}
771_build_all_dirs := ${_build_all_dirs:O:u}
772
773# we prefer DIRDEPS_EXPORT_VARS
774.if empty(DIRDEPS_EXPORT_VARS) && !empty(DEP_EXPORT_VARS)
775DIRDEPS_EXPORT_VARS = ${DEP_EXPORT_VARS}
776.endif
777
778# Normally if doing make -V something,
779# we do not want to waste time chasing DIRDEPS
780# but if we want to count the number of Makefile.depend* read, we do.
781.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS:U}} == ""
782.if !empty(_build_all_dirs)
783.if ${BUILD_DIRDEPS_CACHE} == "yes"
784# we use _cache_script to minimize the number of times we fork the shell
785_cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}';
786# guard against _new_dirdeps being too big for a single command line
787_new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,}
788_cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,}
789.if !empty(DIRDEPS_EXPORT_VARS)
790# Discouraged, but there are always exceptions.
791# Handle it here rather than explain how.
792_cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo;
793_cache_script += ${_cache_xvars}
794.endif
795.else
796# this makes it all happen
797dirdeps: ${_build_all_dirs}
798.endif
799${_build_all_dirs}:	_DIRDEP_USE
800
801.if ${_debug_reldir}
802.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_all_dirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
803.endif
804
805# this builds the dependency graph
806.for m in ${_machines}
807.if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs)
808_cache_deps =
809_cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \';
810.endif
811# it would be nice to do :N${.TARGET}
812.if !empty(__qual_depdirs)
813.for q in ${__qual_depdirs:M*.host*:${M_dep_qual_fixes.host:ts:}:E:O:u:N$m} \
814	${__qual_depdirs:N*.host*:${M_dep_qual_fixes:ts:}:E:O:u:N$m}
815.if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != ""
816.info ${DEP_RELDIR}.$m: q=$q graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,}
817.endif
818.if ${BUILD_DIRDEPS_CACHE} == "yes"
819_cache_deps += ${_build_dirs:M*.$q:S,^${SRCTOP}/,,}
820.else
821${_this_dir}.$m: ${_build_dirs:M*.$q}
822.endif
823.endfor
824.endif
825.if ${_debug_reldir}
826.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
827.endif
828.if ${BUILD_DIRDEPS_CACHE} == "yes"
829.if !empty(_build_dirs)
830_cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
831# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only
832.if ${MAKE_VERSION} < 20240105
833.if !empty(_cache_deps)
834.export _cache_deps
835_cache_script += for x in $$_cache_deps; do echo "	_{SRCTOP}/$$x \\"; done;
836.endif
837.export _cache_xtra_deps _new_dirdeps
838x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
839	echo; echo 'dirdeps: ${_this_dir}.$m \'; \
840	for x in $$_cache_xtra_deps; do echo "	_{SRCTOP}/$$x \\"; done; \
841	echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3
842.else
843# we do not have the same limits on command lines
844.if !empty(_cache_deps)
845_cache_script += for x in ${_cache_deps}; do echo "	_{SRCTOP}/$$x \\"; done;
846.endif
847x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
848	echo; echo 'dirdeps: ${_this_dir}.$m \'; \
849	for x in ${_cache_xtra_deps}; do echo "	_{SRCTOP}/$$x \\"; done; \
850	echo; for x in ${_new_dirdeps}; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3
851.endif
852.endif
853.else
854${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
855.endif
856.endfor
857
858.endif
859
860.if !empty(DIRDEPS_EXPORT_VARS)
861.if ${BUILD_DIRDEPS_CACHE} == "no"
862.export ${DIRDEPS_EXPORT_VARS}
863.endif
864# Reset these, we are done with them for this iteration.
865DIRDEPS_EXPORT_VARS =
866DEP_EXPORT_VARS =
867.endif
868
869.if ${BUILD_DIRDEPS_RECURSE:Uyes} != "no"
870# Now find more dependencies - and recurse.
871.for d in ${_build_all_dirs}
872.if !target(_dirdeps_checked.$d)
873# once only
874_dirdeps_checked.$d:
875_dr := ${d:S,^${SRCTOP}/,,}
876.if ${_debug_search}
877.info checking ${_dr}
878.endif
879# Note: _build_all_dirs is fully qualifed so d:R is always the directory
880.if exists(${d:R})
881# we pass _DEP_TARGET_SPEC to tell the next step what we want
882_DEP_TARGET_SPEC := ${d:E}
883# some makefiles may still look at this
884_DEP_MACHINE := ${d:E:C/,.*//}
885DEP_MACHINE := ${_DEP_MACHINE}
886# set these too in case Makefile.depend* uses them
887.if ${DEP_TARGET_SPEC_VARS:[#]} > 1
888_dtspec := ${_DEP_TARGET_SPEC:S/,/ /g}
889.for i in ${_tspec_x}
890DEP_${DEP_TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]}
891.endfor
892.endif
893# Warning: there is an assumption here that MACHINE is always
894# the first entry in TARGET_SPEC_VARS.
895# If TARGET_SPEC and MACHINE are insufficient, you have a problem.
896_m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:C;${MACHINE}((,.+)?)$;${d:E:C/,.*//}\1;:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]}
897.if !empty(_m)
898# M_dep_qual_fixes isn't geared to Makefile.depend
899_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes.${d:E}:U${M_dep_qual_fixes}:ts:}}
900# set this "just in case"
901# we can skip :tA since we computed the path above
902DEP_RELDIR := ${_m:H:S,^${SRCTOP}/,,}
903# and reset this
904DIRDEPS =
905.if ${_debug_search} || ${_debug_reldir}
906.info Loading ${_m:S,${SRCTOP}/,,} for ${_dr}
907.endif
908.include <${_m}>
909.else
910# set these as if we found Makefile.depend*
911DEP_RELDIR := ${_dr:R}
912DIRDEPS =
913.if ${_debug_reldir}
914.info loading local.dirdeps-missing.mk for ${_dr}
915.endif
916.-include <local.dirdeps-missing.mk>
917.endif
918.endif
919.endif
920.endfor
921.endif
922
923.endif				# -V
924.endif				# BUILD_DIRDEPS
925
926.elif ${.MAKE.LEVEL} > 42
927.error You should have stopped recursing by now.
928.else
929# we are building something
930DEP_RELDIR := ${RELDIR}
931_DEP_RELDIR := ${RELDIR}
932# Since we are/should be included by .MAKE.DEPENDFILE
933# This is a final opportunity to add/hook global rules.
934.-include <local.dirdeps-build.mk>
935
936# skip _reldir_{finish,failed} if not included from Makefile.depend*
937# or not in meta mode
938.if !defined(WITHOUT_META_STATS) && ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" && ${.MAKE.MODE:Mmeta} != ""
939
940meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \
941	created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}}
942
943.if !target(_reldir_finish)
944.END: _reldir_finish
945_reldir_finish: .NOMETA
946	@echo "${TRACER}Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}"
947.endif
948
949.if !target(_reldir_failed)
950.ERROR: _reldir_failed
951_reldir_failed: .NOMETA
952	@echo "${TRACER}Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}"
953.endif
954
955.endif
956
957# pickup local dependencies
958.if ${MAKE_VERSION} < 20160220
959.-include <.depend>
960.else
961.dinclude <.depend>
962.endif
963.endif
964
965# bootstrapping new dependencies made easy?
966.if !target(bootstrap-empty)
967.if !target(bootstrap) && (make(bootstrap) || \
968	make(bootstrap-this) || \
969	make(bootstrap-recurse) || \
970	make(bootstrap-empty))
971
972# if we are bootstrapping create the default
973_want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T}
974
975.if exists(${_want})
976# stop here
977${.TARGETS:Mboot*}:
978.elif !make(bootstrap-empty)
979# find a Makefile.depend to use as _src
980_src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo
981.if empty(_src)
982.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty
983.endif
984
985_src?= ${.MAKE.DEPENDFILE}
986
987.MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g'
988
989# just create Makefile.depend* for this dir
990bootstrap-this:	.NOTMAIN
991	@echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \
992	echo You need to build ${RELDIR} to correctly populate it.
993.if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T}
994	(cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T})
995.else
996	cp ${.CURDIR}/${_src:T} ${_want}
997.endif
998
999# create Makefile.depend* for this dir and its dependencies
1000bootstrap: bootstrap-recurse
1001bootstrap-recurse: bootstrap-this
1002
1003_mf := ${.PARSEFILE}
1004bootstrap-recurse:	.NOTMAIN .MAKE
1005	@cd ${SRCTOP} && \
1006	for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \
1007		test -d $$d || d=$${d%.*}; \
1008		test -d $$d || continue; \
1009		echo "Checking $$d for bootstrap ..."; \
1010		(cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \
1011	done
1012
1013.endif
1014
1015# create an empty Makefile.depend* to get the ball rolling.
1016bootstrap-empty: .NOTMAIN .NOMETA
1017	@echo Creating empty ${RELDIR}/${_want:T}; \
1018	echo You need to build ${RELDIR} to correctly populate it.
1019	@{ echo DIRDEPS=; echo ".include <dirdeps.mk>"; } > ${_want}
1020
1021.endif
1022.endif
1023