xref: /dragonfly/contrib/bmake/mk/dirdeps.mk (revision 31524921)
1# $Id: dirdeps.mk,v 1.37 2014/10/15 06:31:43 sjg Exp $
2
3# Copyright (c) 2010-2013, Juniper Networks, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27# Much of the complexity here is for supporting cross-building.
28# If a tree does not support that, simply using plain Makefile.depend
29# should provide sufficient clue.
30# Otherwise the recommendation is to use Makefile.depend.${MACHINE}
31# as expected below.
32
33# Note: this file gets multiply included.
34# This is what we do with DIRDEPS
35
36# DIRDEPS:
37#	This is a list of directories - relative to SRCTOP, it is
38#	normally only of interest to .MAKE.LEVEL 0.
39#	In some cases the entry may be qualified with a .<machine>
40#	or .<target_spec> suffix (see TARGET_SPEC_VARS below),
41#	for example to force building something for the pseudo
42#	machines "host" or "common" regardless of current ${MACHINE}.
43#
44#	All unqualified entries end up being qualified with .${TARGET_SPEC}
45#	and partially qualified (if TARGET_SPEC_VARS has multiple
46#	entries) are also expanded to a full .<target_spec>.
47#	The  _DIRDEP_USE target uses the suffix to set TARGET_SPEC
48#	correctly when visiting each entry.
49#
50#	The fully qualified directory entries are used to construct a
51#	dependency graph that will drive the build later.
52#
53#	Also, for each fully qualified directory target, we will search
54#	using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional
55#	dependencies.  We use Makefile.depend (default value for
56#	.MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to
57#	distinguish them from others.
58#
59#	Each Makefile.depend file sets DEP_RELDIR to be the
60#	the RELDIR (path relative to SRCTOP) for its directory, and
61#	since each Makefile.depend file includes dirdeps.mk, this
62#	processing is recursive and results in .MAKE.LEVEL 0 learning the
63#	dependencies of the tree wrt the initial directory (_DEP_RELDIR).
64#
65# BUILD_AT_LEVEL0
66#	Indicates whether .MAKE.LEVEL 0 builds anything:
67#	if "no" sub-makes are used to build everything,
68#	if "yes" sub-makes are only used to build for other machines.
69#	It is best to use "no", but this can require fixing some
70#	makefiles to not do anything at .MAKE.LEVEL 0.
71#
72# TARGET_SPEC_VARS
73#	The default value is just MACHINE, and for most environments
74#	this is sufficient.  The _DIRDEP_USE target actually sets
75#	both MACHINE and TARGET_SPEC to the suffix of the current
76#	target so that in the general case TARGET_SPEC can be ignored.
77#
78#	If more than MACHINE is needed then sys.mk needs to decompose
79#	TARGET_SPEC and set the relevant variables accordingly.
80#	It is important that MACHINE be included in and actually be
81#	the first member of TARGET_SPEC_VARS.  This allows other
82#	variables to be considered optional, and some of the treatment
83#	below relies on MACHINE being the first entry.
84#	Note: TARGET_SPEC cannot contain any '.'s so the target
85#	triple used by compiler folk won't work (directly anyway).
86#
87#	For example:
88#
89#		# Always list MACHINE first,
90#		# other variables might be optional.
91#		TARGET_SPEC_VARS = MACHINE TARGET_OS
92#		.if ${TARGET_SPEC:Uno:M*,*} != ""
93#		_tspec := ${TARGET_SPEC:S/,/ /g}
94#		MACHINE := ${_tspec:[1]}
95#		TARGET_OS := ${_tspec:[2]}
96#		# etc.
97#		# We need to stop that TARGET_SPEC affecting any submakes
98#		# and deal with MACHINE=${TARGET_SPEC} in the environment.
99#		TARGET_SPEC =
100#		# export but do not track
101#		.export-env TARGET_SPEC
102#		.export ${TARGET_SPEC_VARS}
103#		.for v in ${TARGET_SPEC_VARS:O:u}
104#		.if empty($v)
105#		.undef $v
106#		.endif
107#		.endfor
108#		.endif
109#		# make sure we know what TARGET_SPEC is
110#		# as we may need it to find Makefile.depend*
111#		TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
112#
113
114.if ${.MAKE.LEVEL} == 0
115# only the first instance is interested in all this
116
117# First off, we want to know what ${MACHINE} to build for.
118# This can be complicated if we are using a mixture of ${MACHINE} specific
119# and non-specific Makefile.depend*
120
121.if !target(_DIRDEP_USE)
122# do some setup we only need once
123_CURDIR ?= ${.CURDIR}
124
125# make sure these are empty to start with
126_DEP_TARGET_SPEC =
127_DIRDEP_CHECKED =
128
129# If TARGET_SPEC_VARS is other than just MACHINE
130# it should be set by sys.mk or similar by now.
131# TARGET_SPEC must not contain any '.'s.
132TARGET_SPEC_VARS ?= MACHINE
133# this is what we started with
134TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
135# this is what we mostly use below
136DEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,}
137# make sure we have defaults
138.for v in ${TARGET_SPEC_VARS}
139DEP_$v ?= ${$v}
140.endfor
141
142.if ${TARGET_SPEC_VARS:[#]} > 1
143# Ok, this gets more complex (putting it mildly).
144# In order to stay sane, we need to ensure that all the build_dirs
145# we compute below are fully qualified wrt DEP_TARGET_SPEC.
146# The makefiles may only partially specify (eg. MACHINE only),
147# so we need to construct a set of modifiers to fill in the gaps.
148# jot 10 should output 1 2 3 .. 10
149JOT ?= jot
150_tspec_x := ${${JOT} ${TARGET_SPEC_VARS:[#]}:L:sh}
151# this handles unqualified entries
152M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC};
153# there needs to be at least one item missing for these to make sense
154.for i in ${_tspec_x:[2..-1]}
155_tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,}
156_tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,}
157M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i};
158.endfor
159.else
160# A harmless? default.
161M_dep_qual_fixes = U
162.endif
163
164.if !defined(.MAKE.DEPENDFILE_PREFERENCE)
165# .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater?
166# you really want this set by sys.mk or similar
167.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T}
168.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}"
169.if ${TARGET_SPEC} != ${MACHINE}
170.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE}
171.endif
172.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}
173.endif
174.endif
175
176_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T}
177_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*}
178
179# for machine specific dependfiles we require ${MACHINE} to be at the end
180# also for the sake of sanity we require a common prefix
181.if !defined(.MAKE.DEPENDFILE_PREFIX)
182# knowing .MAKE.DEPENDFILE_PREFIX helps
183.if !empty(_machine_dependfiles)
184.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R}
185.else
186.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T}
187.endif
188.endif
189
190
191# this is how we identify non-machine specific dependfiles
192N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}}
193
194.endif				# !target(_DIRDEP_USE)
195
196# if we were included recursively _DEP_TARGET_SPEC should be valid.
197.if empty(_DEP_TARGET_SPEC)
198# we may or may not have included a dependfile yet
199.if defined(.INCLUDEDFROMFILE)
200_last_dependfile := ${.INCLUDEDFROMFILE:M${.MAKE.DEPENDFILE_PREFIX}*}
201.else
202_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]}
203.endif
204.if ${_debug_reldir:U0}
205.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _last_dependfile='${_last_dependfile}'
206.endif
207
208.if empty(_last_dependfile) || ${_last_dependfile:E:${N_notmachine}} == ""
209# this is all we have to work with
210DEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}}
211_DEP_TARGET_SPEC := ${DEP_TARGET_SPEC}
212.else
213_DEP_TARGET_SPEC = ${_last_dependfile:${M_dep_qual_fixes:ts:}:E}
214.endif
215.if !empty(_last_dependfile)
216# record that we've read dependfile for this
217_DIRDEP_CHECKED += ${_CURDIR}.${TARGET_SPEC}
218.endif
219.endif
220
221# by now _DEP_TARGET_SPEC should be set, parse it.
222.if ${TARGET_SPEC_VARS:[#]} > 1
223# we need to parse DEP_MACHINE may or may not contain more info
224_tspec := ${_DEP_TARGET_SPEC:S/,/ /g}
225.for i in ${_tspec_x}
226DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]}
227.endfor
228.for v in ${TARGET_SPEC_VARS:O:u}
229.if empty(DEP_$v)
230.undef DEP_$v
231.endif
232.endfor
233.else
234DEP_MACHINE := ${_DEP_TARGET_SPEC}
235.endif
236
237# pickup customizations
238# as below you can use !target(_DIRDEP_USE) to protect things
239# which should only be done once.
240.-include "local.dirdeps.mk"
241
242# the first time we are included the _DIRDEP_USE target will not be defined
243# we can use this as a clue to do initialization and other one time things.
244.if !target(_DIRDEP_USE)
245# make sure this target exists
246dirdeps: beforedirdeps .WAIT
247beforedirdeps:
248
249# We normally expect to be included by Makefile.depend.*
250# which sets the DEP_* macros below.
251DEP_RELDIR ?= ${RELDIR}
252
253# this can cause lots of output!
254# set to a set of glob expressions that might match RELDIR
255DEBUG_DIRDEPS ?= no
256
257# remember the initial value of DEP_RELDIR - we test for it below.
258_DEP_RELDIR := ${DEP_RELDIR}
259
260# things we skip for host tools
261SKIP_HOSTDIR ?=
262
263NSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${M_ListToSkip}}
264
265# things we always skip
266# SKIP_DIRDEPS allows for adding entries on command line.
267SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS}
268SKIP_DIR.host += ${SKIP_HOSTDIR}
269
270DEP_SKIP_DIR = ${SKIP_DIR} \
271	${SKIP_DIR.${DEP_TARGET_SPEC}:U} \
272	${SKIP_DIR.${DEP_MACHINE}:U} \
273	${SKIP_DIRDEPS.${DEP_MACHINE}:U}
274
275NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}}
276
277.if defined(NO_DIRDEPS) || defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
278# confine ourselves to the original dir
279DIRDEPS_FILTER += M${_DEP_RELDIR}*
280.endif
281
282# this is what we run below
283DIRDEP_MAKE?= ${.MAKE}
284
285# we suppress SUBDIR when visiting the leaves
286# we assume sys.mk will set MACHINE_ARCH
287# you can add extras to DIRDEP_USE_ENV
288# if there is no makefile in the target directory, we skip it.
289_DIRDEP_USE:	.USE .MAKE
290	@for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \
291		test -s ${.TARGET:R}/$$m || continue; \
292		echo "${TRACER}Checking ${.TARGET:R} for ${.TARGET:E} ..."; \
293		MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \
294		TARGET_SPEC=${.TARGET:E} \
295		MACHINE=${.TARGET:E} \
296		${DIRDEP_MAKE} -C ${.TARGET:R} || exit 1; \
297		break; \
298	done
299
300.ifdef ALL_MACHINES
301# this is how you limit it to only the machines we have been built for
302# previously.
303.if empty(ONLY_MACHINE_LIST)
304.if !empty(ALL_MACHINE_LIST)
305# ALL_MACHINE_LIST is the list of all legal machines - ignore anything else
306_machine_list != cd ${_CURDIR} && 'ls' -1 ${ALL_MACHINE_LIST:O:u:@m@${.MAKE.DEPENDFILE:T:R}.$m@} 2> /dev/null; echo
307.else
308_machine_list != 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.* 2> /dev/null; echo
309.endif
310_only_machines := ${_machine_list:${NIgnoreFiles:UN*.bak}:E:O:u}
311.else
312_only_machines := ${ONLY_MACHINE_LIST}
313.endif
314
315.if empty(_only_machines)
316# we must be boot-strapping
317_only_machines := ${TARGET_MACHINE:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}
318.endif
319
320.else				# ! ALL_MACHINES
321# if ONLY_MACHINE_LIST is set, we are limited to that
322# if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST
323# otherwise DEP_MACHINE is it - so DEP_MACHINE will match.
324_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
325.endif
326
327.if !empty(NOT_MACHINE_LIST)
328_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
329.endif
330
331# make sure we have a starting place?
332DIRDEPS ?= ${RELDIR}
333.endif				# target
334
335.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
336_debug_reldir = 1
337.else
338_debug_reldir = 0
339.endif
340.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@} != ""
341_debug_search = 1
342.else
343_debug_search = 0
344.endif
345
346# the rest is done repeatedly for every Makefile.depend we read.
347# if we are anything but the original dir we care only about the
348# machine type we were included for..
349
350.if ${DEP_RELDIR} == "."
351_this_dir := ${SRCTOP}
352.else
353_this_dir := ${SRCTOP}/${DEP_RELDIR}
354.endif
355
356# on rare occasions, there can be a need for extra help
357_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc
358.-include "${_dep_hack}"
359
360.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC}
361# this should be all
362_machines := ${DEP_MACHINE}
363.else
364# this is the machine list we actually use below
365_machines := ${_only_machines}
366
367.if defined(HOSTPROG) || ${DEP_MACHINE} == "host"
368# we need to build this guy's dependencies for host as well.
369_machines += host
370.endif
371
372_machines := ${_machines:O:u}
373.endif
374
375.if ${TARGET_SPEC_VARS:[#]} > 1
376# we need to tweak _machines
377_dm := ${DEP_MACHINE}
378# apply the same filtering that we do when qualifying DIRDEPS.
379# M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
380_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
381DEP_MACHINE := ${_dm}
382.endif
383
384# reset each time through
385_build_dirs =
386
387.if ${DEP_RELDIR} == ${_DEP_RELDIR}
388# pickup other machines for this dir if necessary
389.if ${BUILD_AT_LEVEL0:Uyes} == "no"
390_build_dirs += ${_machines:@m@${_CURDIR}.$m@}
391.else
392_build_dirs += ${_machines:N${DEP_TARGET_SPEC}:@m@${_CURDIR}.$m@}
393.if ${DEP_TARGET_SPEC} == ${TARGET_SPEC}
394# pickup local dependencies now
395.-include <.depend>
396.endif
397.endif
398.endif
399
400.if ${_debug_reldir}
401.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}'
402.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}'
403.endif
404
405.if !empty(DIRDEPS)
406# these we reset each time through as they can depend on DEP_MACHINE
407DEP_DIRDEPS_FILTER = \
408	${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \
409	${DIRDEPS_FILTER.${DEP_MACHINE}:U} \
410	${DIRDEPS_FILTER:U}
411.if empty(DEP_DIRDEPS_FILTER)
412# something harmless
413DEP_DIRDEPS_FILTER = U
414.endif
415
416# this is what we start with
417__depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:C,//+,/,g:O:u:@d@${SRCTOP}/$d@}
418
419# some entries may be qualified with .<machine>
420# the :M*/*/*.* just tries to limit the dirs we check to likely ones.
421# the ${d:E:M*/*} ensures we don't consider junos/usr.sbin/mgd
422__qual_depdirs := ${__depdirs:M*/*/*.*:@d@${exists($d):?:${"${d:E:M*/*}":?:${exists(${d:R}):?$d:}}}@}
423__unqual_depdirs := ${__depdirs:${__qual_depdirs:Uno:${M_ListToSkip}}}
424
425.if ${DEP_RELDIR} == ${_DEP_RELDIR}
426# if it was called out - we likely need it.
427__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@}
428__qual_depdirs += ${__hostdpadd}
429.endif
430
431.if ${_debug_reldir}
432.info depdirs=${__depdirs}
433.info qualified=${__qual_depdirs}
434.info unqualified=${__unqual_depdirs}
435.endif
436
437# _build_dirs is what we will feed to _DIRDEP_USE
438_build_dirs += \
439	${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \
440	${__qual_depdirs:N*.host} \
441	${_machines:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \
442	${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@}
443
444# qualify everything now
445_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u}
446
447.endif				# empty DIRDEPS
448
449# Normally if doing make -V something,
450# we do not want to waste time chasing DIRDEPS
451# but if we want to count the number of Makefile.depend* read, we do.
452.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS}} == ""
453.if !empty(_build_dirs)
454# this makes it all happen
455dirdeps: ${_build_dirs}
456${_build_dirs}:	_DIRDEP_USE
457
458.if ${_debug_reldir}
459.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs}
460.endif
461
462# this builds the dependency graph
463.for m in ${_machines}
464# it would be nice to do :N${.TARGET}
465.if !empty(__qual_depdirs)
466.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m}
467.if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != ""
468.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q}
469.endif
470${_this_dir}.$m: ${_build_dirs:M*.$q}
471.endfor
472.endif
473.if ${_debug_reldir}
474.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m}
475.endif
476${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
477.endfor
478
479.endif
480
481# Now find more dependencies - and recurse.
482.for d in ${_build_dirs}
483.if ${_DIRDEP_CHECKED:M$d} == ""
484# once only
485_DIRDEP_CHECKED += $d
486.if ${_debug_search}
487.info checking $d
488.endif
489# Note: _build_dirs is fully qualifed so d:R is always the directory
490.if exists(${d:R})
491# Warning: there is an assumption here that MACHINE is always
492# the first entry in TARGET_SPEC_VARS.
493# If TARGET_SPEC and MACHINE are insufficient, you have a problem.
494_m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:S;${MACHINE};${d:E:C/,.*//};:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]}
495.if !empty(_m)
496# M_dep_qual_fixes isn't geared to Makefile.depend
497_qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}}
498.if ${_debug_search}
499.info Looking for ${_qm}
500.endif
501# we pass _DEP_TARGET_SPEC to tell the next step what we want
502_DEP_TARGET_SPEC := ${d:E}
503# some makefiles may still look at this
504_DEP_MACHINE := ${d:E:C/,.*//}
505.if ${_debug_reldir} && ${_qm} != ${_m}
506.info loading ${_m} for ${d:E}
507.endif
508.include <${_m}>
509.endif
510.endif
511.endif
512.endfor
513
514.endif				# -V
515
516.elif ${.MAKE.LEVEL} > 42
517.error You should have stopped recursing by now.
518.else
519_DEP_RELDIR := ${DEP_RELDIR}
520# pickup local dependencies
521.-include <.depend>
522.endif
523
524# bootstrapping new dependencies made easy?
525.if make(bootstrap*) && !target(bootstrap)
526
527.if exists(${.CURDIR}/${.MAKE.DEPENDFILE:T})
528# stop here
529${.TARGETS:Mboot*}:
530.else
531# find a Makefile.depend to use as _src
532_src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo
533.if empty(_src)
534.error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}
535.endif
536
537_src?= ${.MAKE.DEPENDFILE:T}
538
539bootstrap-this:	.NOTMAIN
540	@echo Bootstrapping ${RELDIR}/${.MAKE.DEPENDFILE:T} from ${_src:T}
541	(cd ${.CURDIR} && sed 's,${_src:E},${MACHINE},g' ${_src} > ${.MAKE.DEPENDFILE:T})
542
543bootstrap: bootstrap-recurse
544bootstrap-recurse: bootstrap-this
545
546_mf := ${.PARSEFILE}
547bootstrap-recurse:	.NOTMAIN .MAKE
548	@cd ${SRCTOP} && \
549	for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \
550		test -d $$d || d=$${d%.*}; \
551		test -d $$d || continue; \
552		echo "Checking $$d for bootstrap ..."; \
553		(cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \
554	done
555
556.endif
557.endif
558