1 # $Id: dirdeps.mk,v 1.152 2022/08/01 23:09:19 sjg Exp $
3 # Copyright (c) 2010-2022, Simon J. Gerraty
4 # Copyright (c) 2010-2018, Juniper Networks, Inc.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Much of the complexity here is for supporting cross-building.
29 # If a tree does not support that, simply using plain Makefile.depend
30 # should provide sufficient clue.
31 # Otherwise the recommendation is to use Makefile.depend.${MACHINE}
34 # Note: this file gets multiply included.
35 # This is what we do with DIRDEPS
38 # This is a list of directories - relative to SRCTOP, it is
39 # normally only of interest to .MAKE.LEVEL 0.
40 # In some cases the entry may be qualified with a .<machine>
41 # or .<target_spec> suffix (see TARGET_SPEC_VARS below),
42 # for example to force building something for the pseudo
43 # machines "host" or "common" regardless of current ${MACHINE}.
45 # All unqualified entries end up being qualified with .${TARGET_SPEC}
46 # and partially qualified (if TARGET_SPEC_VARS has multiple
47 # entries) are also expanded to a full .<target_spec>.
48 # The _DIRDEP_USE target uses the suffix to set TARGET_SPEC
49 # correctly when visiting each entry.
51 # The fully qualified directory entries are used to construct a
52 # dependency graph that will drive the build later.
54 # Also, for each fully qualified directory target, we will search
55 # using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional
56 # dependencies. We use Makefile.depend (default value for
57 # .MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to
58 # distinguish them from others.
60 # Before each Makefile.depend file is read, we set
61 # DEP_RELDIR to be the RELDIR (path relative to SRCTOP) for
62 # its directory, and DEP_MACHINE etc according to the .<target_spec>
63 # represented by the suffix of the corresponding target.
65 # Since each Makefile.depend file includes dirdeps.mk, this
66 # processing is recursive and results in .MAKE.LEVEL 0 learning the
67 # dependencies of the tree wrt the initial directory (_DEP_RELDIR).
69 # NOTE: given the extent of processing that DIRDEPS undergoes it
70 # is important that any variables in entries use :U to guard
71 # against surprises when undefined.
74 # The default value is just MACHINE, and for most environments
75 # this is sufficient. The _DIRDEP_USE target actually sets
76 # both MACHINE and TARGET_SPEC to the suffix of the current
77 # target so that in the general case TARGET_SPEC can be ignored.
79 # If more than MACHINE is needed then sys.mk needs to decompose
80 # TARGET_SPEC and set the relevant variables accordingly.
81 # It is important that MACHINE be included in and actually be
82 # the first member of TARGET_SPEC_VARS. This allows other
83 # variables to be considered optional, and some of the treatment
84 # below relies on MACHINE being the first entry.
85 # Note: TARGET_SPEC cannot contain any '.'s so the target
86 # triple used by compiler folk won't work (directly anyway).
90 # # Always list MACHINE first,
91 # # other variables might be optional.
92 # TARGET_SPEC_VARS = MACHINE TARGET_OS
93 # .if ${TARGET_SPEC:Uno:M*,*} != ""
94 # _tspec := ${TARGET_SPEC:S/,/ /g}
95 # MACHINE := ${_tspec:[1]}
96 # TARGET_OS := ${_tspec:[2]}
98 # # We need to stop that TARGET_SPEC affecting any submakes
99 # # and deal with MACHINE=${TARGET_SPEC} in the environment.
101 # # export but do not track
102 # .export-env TARGET_SPEC
103 # .export ${TARGET_SPEC_VARS}
104 # .for v in ${TARGET_SPEC_VARS:O:u}
110 # # make sure we know what TARGET_SPEC is
111 # # as we may need it to find Makefile.depend*
112 # TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
114 # The following variables can influence the initial DIRDEPS
115 # computation with regard to the TARGET_SPECs that will be
117 # Most should also be considered by init.mk
119 # ONLY_TARGET_SPEC_LIST
120 # Defines a list of TARGET_SPECs for which the current
121 # directory can be built.
122 # If ALL_MACHINES is defined, we build for all the
123 # TARGET_SPECs listed.
126 # As for ONLY_TARGET_SPEC_LIST but only specifies
129 # NOT_TARGET_SPEC_LIST
130 # A list of TARGET_SPECs for which the current
131 # directory should not be built.
134 # A list of MACHINEs the current directory should not be
137 # DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS)
138 # It is discouraged, but sometimes necessary for a
139 # Makefile.depend file to influence the environment.
140 # Doing this is correctly (especially if using DIRDEPS_CACHE) is
141 # tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS
142 # and dirdeps.mk will do the deed:
145 # DIRDEPS_EXPORT_VARS = MK_UEFI
148 # local.dirdeps.mk can add targets to this variable.
149 # They will be hooked into the build, but independent of
152 # This allows for adding TESTS to the build, such that the build
153 # if any test fails, but without the risk of introducing
154 # circular dependencies.
156 now_utc ?= ${%s:L:gmtime}
157 .if !defined(start_utc)
158 start_utc := ${now_utc}
161 .if !target(bootstrap) && (make(bootstrap) || \
162 make(bootstrap-this) || \
163 make(bootstrap-recurse) || \
164 make(bootstrap-empty))
165 # disable most of below
169 # touch this at your peril
170 _DIRDEP_USE_LEVEL?= 0
171 .if ${.MAKE.LEVEL} == ${_DIRDEP_USE_LEVEL}
172 # only the first instance is interested in all this
174 # the first time we are included the _DIRDEP_USE target will not be defined
175 # we can use this as a clue to do initialization and other one time things.
176 .if !target(_DIRDEP_USE)
178 # do some setup we only need once
179 _CURDIR ?= ${.CURDIR}
180 _OBJDIR ?= ${.OBJDIR}
182 .if ${MAKEFILE:T} == ${.PARSEFILE} && empty(DIRDEPS) && ${.TARGETS:Uall:M*/*} != ""
183 # This little trick let's us do
185 # mk -f dirdeps.mk some/dir.${TARGET_SPEC}
188 ${.TARGETS:Nall}: all
189 DIRDEPS := ${.TARGETS:M*[/.]*}
190 # so that -DNO_DIRDEPS works
191 DEP_RELDIR := ${DIRDEPS:[1]:R}
192 # this will become DEP_MACHINE below
193 TARGET_MACHINE := ${DIRDEPS:[1]:E:C/,.*//}
194 .if ${TARGET_MACHINE:N*/*} == ""
195 TARGET_MACHINE := ${MACHINE}
197 # disable DIRDEPS_CACHE as it does not like this trick
198 MK_DIRDEPS_CACHE = no
199 # incase anyone needs to know
203 # make sure we get the behavior we expect
204 .MAKE.SAVE_DOLLARS = no
206 # make sure these are empty to start with
209 # If TARGET_SPEC_VARS is other than just MACHINE
210 # it should be set by sys.mk or similar by now.
211 # TARGET_SPEC must not contain any '.'s.
212 TARGET_SPEC_VARS ?= MACHINE
213 # this is what we started with
214 TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
215 # this is what we mostly use below
216 DEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,}
217 # make sure we have defaults
218 .for v in ${TARGET_SPEC_VARS}
222 .if ${TARGET_SPEC_VARS:[#]} > 1
223 # Ok, this gets more complex (putting it mildly).
224 # In order to stay sane, we need to ensure that all the build_dirs
225 # we compute below are fully qualified wrt DEP_TARGET_SPEC.
226 # The makefiles may only partially specify (eg. MACHINE only),
227 # so we need to construct a set of modifiers to fill in the gaps.
228 .if ${MAKE_VERSION} >= 20170130
229 _tspec_x := ${TARGET_SPEC_VARS:range}
232 _tspec_x := ${TARGET_SPEC_VARS:[#]:@x@i=1;while [ $$i -le $x ]; do echo $$i; i=$$((i + 1)); done;@:sh}
234 # this handles unqualified entries
235 M_dep_qual_fixes = C;(/[^/.,]+)$$;\1.$${DEP_TARGET_SPEC};
236 # there needs to be at least one item missing for these to make sense
237 .for i in ${_tspec_x:[2..-1]}
238 _tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,}
239 _tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$$$${DEP_$v}@:ts,}
240 M_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i};
242 TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]}
244 # A harmless? default.
248 .if !defined(.MAKE.DEPENDFILE_PREFERENCE)
249 # .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater?
250 # you really want this set by sys.mk or similar
251 .MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T}
252 .if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}"
253 .if ${TARGET_SPEC} != ${MACHINE}
254 .MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE}
256 .MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}
260 _default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T}
261 _machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*}
263 # for machine specific dependfiles we require ${MACHINE} to be at the end
264 # also for the sake of sanity we require a common prefix
265 .if !defined(.MAKE.DEPENDFILE_PREFIX)
266 # knowing .MAKE.DEPENDFILE_PREFIX helps
267 .if !empty(_machine_dependfiles)
268 .MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R}
270 .MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T}
274 # this is how we identify non-machine specific dependfiles
275 N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}}
277 # this gets reset for each dirdep we check
278 DEP_RELDIR ?= ${RELDIR}
280 # remember the initial value of DEP_RELDIR - we test for it below.
281 _DEP_RELDIR := ${DEP_RELDIR}
283 # this can cause lots of output!
284 # set to a set of glob expressions that might match RELDIR
287 # make sure this target exists
288 dirdeps: beforedirdeps .WAIT
291 .endif # !target(_DIRDEP_USE)
293 .if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
298 .if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend depend:L:M$x}@} != ""
304 # First off, we want to know what ${MACHINE} to build for.
305 # This can be complicated if we are using a mixture of ${MACHINE} specific
306 # and non-specific Makefile.depend*
308 # if we were included recursively _DEP_TARGET_SPEC should be valid.
309 .if empty(_DEP_TARGET_SPEC)
310 DEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}}
311 _DEP_TARGET_SPEC := ${DEP_TARGET_SPEC}
312 .if ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != ""
313 # record that we've read dependfile for this
314 _dirdeps_checked.${_CURDIR}.${TARGET_SPEC}:
318 # by now _DEP_TARGET_SPEC should be set, parse it.
319 .if ${TARGET_SPEC_VARS:[#]} > 1
320 # we need to parse DEP_MACHINE may or may not contain more info
321 _tspec := ${_DEP_TARGET_SPEC:S/,/ /g}
322 .for i in ${_tspec_x}
323 DEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]}
325 .for v in ${TARGET_SPEC_VARS:O:u}
331 DEP_MACHINE := ${_DEP_TARGET_SPEC}
334 # reset each time through
338 # DIRDEPS_CACHE can be very handy for debugging.
339 # Also if repeatedly building the same target,
340 # we can avoid the overhead of re-computing the tree dependencies.
341 MK_DIRDEPS_CACHE ?= no
342 BUILD_DIRDEPS_CACHE ?= no
345 .if ${MK_DIRDEPS_CACHE} == "yes"
346 # this is where we will cache all our work
347 DIRDEPS_CACHE ?= ${_OBJDIR:tA}/dirdeps.cache${_TARGETS:U${.TARGETS}:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
351 # pickup customizations
352 # as below you can use !target(_DIRDEP_USE) to protect things
353 # which should only be done once.
354 .-include <local.dirdeps.mk>
356 .if !target(_DIRDEP_USE)
357 # things we skip for host tools
360 NSkipHostDir = ${SKIP_HOSTDIR:N*.host*:S,$,.host*,:N.host*:S,^,${SRCTOP}/,:${M_ListToSkip}}
362 # things we always skip
363 # SKIP_DIRDEPS allows for adding entries on command line.
364 SKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS}
365 SKIP_DIR.host += ${SKIP_HOSTDIR}
367 DEP_SKIP_DIR = ${SKIP_DIR} \
368 ${SKIP_DIR.${DEP_TARGET_SPEC}:U} \
369 ${TARGET_SPEC_VARS:@v@${SKIP_DIR.${DEP_$v}:U}@} \
370 ${SKIP_DIRDEPS.${DEP_TARGET_SPEC}:U} \
371 ${TARGET_SPEC_VARS:@v@${SKIP_DIRDEPS.${DEP_$v}:U}@}
374 NSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}}
376 .if defined(NODIRDEPS) || defined(WITHOUT_DIRDEPS)
378 .elif defined(WITHOUT_DIRDEPS_BELOW)
382 .if defined(NO_DIRDEPS)
383 # confine ourselves to the original dir and below.
384 DIRDEPS_FILTER += M${_DEP_RELDIR}*
385 .elif defined(NO_DIRDEPS_BELOW)
386 DIRDEPS_FILTER += M${_DEP_RELDIR}
389 # this is what we run below
390 DIRDEP_MAKE ?= ${.MAKE}
391 DIRDEP_DIR ?= ${.TARGET:R}
393 # if you want us to report load averages during build
394 # DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT};
396 DIRDEP_LOADAVG_CMD ?= ${UPTIME:Uuptime} | sed 's,.*\(load\),\1,'
397 DIRDEP_LOADAVG_LAST = 0
398 # yes the expression here is a bit complicated,
399 # the trick is to only eval ${DIRDEP_LOADAVG_LAST::=${now_utc}}
400 # when we want to report.
401 # Note: expr(1) will exit 1 if the expression evaluates to 0
403 DIRDEP_LOADAVG_REPORT = \
404 test -z "${"${expr ${now_utc} - ${DIRDEP_LOADAVG_INTERVAL:U60} - ${DIRDEP_LOADAVG_LAST} || true:L:sh:N-*}":?yes${DIRDEP_LOADAVG_LAST::=${now_utc}}:}" || \
405 echo "${TRACER}`${DIRDEP_LOADAVG_CMD}`"
407 # we suppress SUBDIR when visiting the leaves
408 # we assume sys.mk will set MACHINE_ARCH
409 # you can add extras to DIRDEP_USE_ENV
410 # if there is no makefile in the target directory, we skip it.
411 _DIRDEP_USE: .USE .MAKE
412 @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \
413 test -s ${.TARGET:R}/$$m || continue; \
414 echo "${TRACER}Checking ${.TARGET:S,^${SRCTOP}/,,} for ${.TARGET:E} ..."; \
415 ${DIRDEP_USE_PRELUDE} \
416 MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \
417 TARGET_SPEC=${.TARGET:E} \
418 MACHINE=${.TARGET:E} \
419 ${DIRDEP_MAKE} -C ${DIRDEP_DIR} || exit 1; \
424 .if empty(ONLY_TARGET_SPEC_LIST) && empty(ONLY_MACHINE_LIST)
425 # we start with everything
426 _machine_list != echo; 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}* 2> /dev/null
428 # some things we know we want to ignore
429 DIRDEPS_TARGETS_SKIP_LIST += \
438 # first trim things we know we want to skip
439 # and provide canonical form
440 _machine_list := ${_machine_list:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}:T:E}
442 # cater for local complexities
443 # local.dirdeps.mk can set
444 # DIRDEPS_ALL_MACHINES_FILTER and
445 # DIRDEPS_ALL_MACHINES_FILTER_XTRAS for final tweaks
447 .if !empty(ALL_TARGET_SPEC_LIST)
449 .info ALL_TARGET_SPEC_LIST=${ALL_TARGET_SPEC_LIST}
451 DIRDEPS_ALL_MACHINES_FILTER += \
452 @x@$${ALL_TARGET_SPEC_LIST:@s@$${x:M$$s}@}@
453 .elif !empty(ALL_MACHINE_LIST)
455 .info ALL_MACHINE_LIST=${ALL_MACHINE_LIST}
457 .if ${TARGET_SPEC_VARS:[#]} > 1
458 # the space below can result in extraneous ':'
459 DIRDEPS_ALL_MACHINES_FILTER += \
460 @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m,*} $${x:M$$m}@}@
462 DIRDEPS_ALL_MACHINES_FILTER += \
463 @x@$${ALL_MACHINE_LIST:@m@$${x:M$$m}@}@
466 # add local XTRAS - default to something benign
467 DIRDEPS_ALL_MACHINES_FILTER += \
468 ${DIRDEPS_ALL_MACHINES_FILTER_XTRAS:UNbak}
471 .info _machine_list=${_machine_list}
472 .info DIRDEPS_ALL_MACHINES_FILTER=${DIRDEPS_ALL_MACHINES_FILTER}
475 _only_machines := ${_machine_list:${DIRDEPS_ALL_MACHINES_FILTER:ts:}:S,:, ,g}
477 _only_machines := ${ONLY_TARGET_SPEC_LIST:U} ${ONLY_MACHINE_LIST:U}
480 .if empty(_only_machines)
481 # we must be boot-strapping
482 _only_machines := ${TARGET_MACHINE:U${ALL_TARGET_SPEC_LIST:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}}}
486 _only_machines := ${_only_machines:O:u}
489 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: ALL_MACHINES _only_machines=${_only_machines}
492 .else # ! ALL_MACHINES
493 # if ONLY_TARGET_SPEC_LIST or ONLY_MACHINE_LIST is set, we are limited to that.
494 # Note that ONLY_TARGET_SPEC_LIST should be fully qualified.
495 # if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST
496 # otherwise DEP_MACHINE is it - so DEP_MACHINE will match.
497 _only_machines := ${ONLY_TARGET_SPEC_LIST:U:M${DEP_MACHINE},*}
498 .if empty(_only_machines)
499 _only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}}
503 .if !empty(NOT_MACHINE_LIST)
504 _only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}}
506 .if !empty(NOT_TARGET_SPEC_LIST)
507 # we must first qualify
508 _dm := ${DEP_MACHINE}
509 _only_machines := ${_only_machines:M*,*} ${_only_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
510 DEP_MACHINE := ${_dm}
511 _only_machines := ${_only_machines:${NOT_TARGET_SPEC_LIST:${M_ListToSkip}}}
514 _only_machines := ${_only_machines:O:u}
517 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _only_machines=${_only_machines}
520 # make sure we have a starting place?
524 .if !defined(NO_DIRDEPS) && !defined(NO_DIRDEPS_BELOW)
525 .if ${MK_DIRDEPS_CACHE} == "yes"
527 # just ensure this exists
530 M_oneperline = @x@\\${.newline} $$x@
532 .if ${BUILD_DIRDEPS_CACHE} == "no"
533 .if !target(dirdeps-cached)
534 # we do this via sub-make
537 # ignore anything but these
538 .MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*
540 dirdeps: dirdeps-cached
541 dirdeps-cached: ${DIRDEPS_CACHE} .MAKE
542 @echo "${TRACER}Using ${DIRDEPS_CACHE}"
543 @MAKELEVEL=${.MAKE.LEVEL} \
544 TARGET_SPEC=${TARGET_SPEC} \
545 ${TARGET_SPEC_VARS:@v@$v=${$v}@} \
546 ${.MAKE} -C ${_CURDIR} -f ${DIRDEPS_CACHE} \
547 dirdeps MK_DIRDEPS_CACHE=no BUILD_DIRDEPS=no
549 # leaf makefiles rarely work for building DIRDEPS_CACHE
551 BUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk
554 # these should generally do
555 BUILD_DIRDEPS_MAKEFILE ?=
556 BUILD_DIRDEPS_TARGETS ?= ${.TARGETS}
558 .if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == ""
559 # export this for dirdeps-cache-update.mk
560 DYNAMIC_DIRDEPS_CACHE := ${DIRDEPS_CACHE}
561 .export DYNAMIC_DIRDEPS_CACHE
562 # we need the .meta file to ensure we update if
563 # any of the Makefile.depend* changed.
564 # We do not want to compare the command line though.
565 ${DIRDEPS_CACHE}: .META .NOMETA_CMP
566 +@{ echo '# Autogenerated - do NOT edit!'; echo; \
567 echo 'BUILD_DIRDEPS=no'; echo; \
568 echo '.include <dirdeps.mk>'; echo; \
570 +@MAKELEVEL=${.MAKE.LEVEL} DIRDEPS_CACHE=${DIRDEPS_CACHE} \
571 DIRDEPS="${DIRDEPS}" \
572 TARGET_SPEC=${TARGET_SPEC} \
573 MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \
574 ${BUILD_DIRDEPS_MAKEFILE} \
575 ${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \
576 .MAKE.DEPENDFILE=.none \
577 ${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \
578 ${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \
579 ${.MAKEFLAGS:tW:S,-d ,-d,g:tw:M-d*} \
580 3>&1 1>&2 | sed 's,${SRCTOP},_{SRCTOP},g;s,_{,$${,g' >> ${.TARGET}.new && \
581 mv ${.TARGET}.new ${.TARGET}
585 .elif !target(_count_dirdeps)
586 # we want to capture the dirdeps count in the cache
588 _count_dirdeps: .NOMETA
589 @{ 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
592 .elif !make(dirdeps) && !target(_count_dirdeps)
593 beforedirdeps: _count_dirdeps
594 _count_dirdeps: .NOMETA
595 @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}`"
600 .if ${BUILD_DIRDEPS} == "yes"
602 # the rest is done repeatedly for every Makefile.depend we read.
603 # if we are anything but the original dir we care only about the
604 # machine type we were included for..
606 .if ${DEP_RELDIR} == "."
607 _this_dir := ${SRCTOP}
609 _this_dir := ${SRCTOP}/${DEP_RELDIR}
612 # on rare occasions, there can be a need for extra help
613 _dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc
614 .-include <${_dep_hack}>
615 .-include <${_dep_hack:R}.options>
617 .if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC}
619 _machines := ${DEP_MACHINE}
621 # this is the machine list we actually use below
622 _machines := ${_only_machines}
624 .if defined(HOSTPROG) || ${DEP_MACHINE:Nhost*} == ""
625 # we need to build this guy's dependencies for host as well.
626 .if ${DEP_MACHINE:Nhost*} == ""
627 _machines += ${DEP_MACHINE}
633 _machines := ${_machines:O:u}
636 .if ${TARGET_SPEC_VARS:[#]} > 1
637 # we need to tweak _machines
638 _dm := ${DEP_MACHINE}
639 # apply the same filtering that we do when qualifying DIRDEPS.
640 # M_dep_qual_fixes expects .${MACHINE}* so add (and remove) '.'
641 # Again we expect that any already qualified machines are fully qualified.
642 _machines := ${_machines:M*,*} ${_machines:N*,*:@DEP_MACHINE@${DEP_TARGET_SPEC}@:S,^,.,:${M_dep_qual_fixes:ts:}:O:u:S,^.,,}
643 DEP_MACHINE := ${_dm}
644 _machines := ${_machines:O:u}
647 # reset each time through
650 .if ${DEP_RELDIR} == ${_DEP_RELDIR}
651 # pickup other machines for this dir if necessary
652 _build_dirs += ${_machines:@m@${_CURDIR}.$m@}
656 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]}
657 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}'
658 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}'
662 # these we reset each time through as they can depend on DEP_MACHINE
663 DEP_DIRDEPS_FILTER = \
664 ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \
665 ${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \
667 .if empty(DEP_DIRDEPS_FILTER)
669 DEP_DIRDEPS_FILTER = U
672 # this is what we start with
673 __depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:C,//+,/,g:O:u:@d@${SRCTOP}/$d@}
675 # some entries may be qualified with .<machine> or .<target_spec>
676 # we can tell the unqualified ones easily - because they exist
677 __unqual_depdirs := ${__depdirs:@d@${exists($d):?$d:}@}
678 __qual_depdirs := ${__depdirs:${__unqual_depdirs:Uno:${M_ListToSkip}}}
680 .if ${DEP_RELDIR} == ${_DEP_RELDIR}
681 # if it was called out - we likely need it.
682 __hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} \
683 ${DPADD:U.:M${HOST_OBJTOP32:Uno}/*:S,${HOST_OBJTOP32:Uno}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host32,:N.*:@d@${SRCTOP}/$d@}
684 __qual_depdirs += ${__hostdpadd}
688 .info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:}
689 .info depdirs=${__depdirs:S,^${SRCTOP}/,,}
690 .info qualified=${__qual_depdirs:S,^${SRCTOP}/,,}
691 .info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,}
694 # _build_dirs is what we will feed to _DIRDEP_USE
696 ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \
697 ${__qual_depdirs:N*.host} \
698 ${_machines:Mhost*:@m@${__unqual_depdirs:@d@$d.$m@}@:${NSkipHostDir}:N.host} \
699 ${_machines:Nhost*:@m@${__unqual_depdirs:@d@$d.$m@}@}
701 # qualify everything now
702 _build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u}
704 .endif # empty DIRDEPS
706 _build_all_dirs += ${_build_dirs} ${_build_xtra_dirs}
707 _build_all_dirs := ${_build_all_dirs:O:u}
709 # Normally if doing make -V something,
710 # we do not want to waste time chasing DIRDEPS
711 # but if we want to count the number of Makefile.depend* read, we do.
712 .if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS:U}} == ""
713 .if !empty(_build_all_dirs)
714 .if ${BUILD_DIRDEPS_CACHE} == "yes"
715 # we use _cache_script to minimize the number of times we fork the shell
716 _cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}';
717 # guard against _new_dirdeps being too big for a single command line
718 _new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,}
719 _cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,}
720 .export _cache_xtra_deps _new_dirdeps
721 .if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
722 # Discouraged, but there are always exceptions.
723 # Handle it here rather than explain how.
724 DIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS}
725 _cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo;
726 _cache_script += ${_cache_xvars}
729 # this makes it all happen
730 dirdeps: ${_build_all_dirs}
732 ${_build_all_dirs}: _DIRDEP_USE
735 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,}
738 .if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
739 .export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS}
740 DIRDEPS_EXPORT_VARS =
744 # this builds the dependency graph
745 .for m in ${_machines}
746 .if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs)
748 _cache_script += echo; echo 'DIRDEPS.${_this_dir}.$m = \';
750 # it would be nice to do :N${.TARGET}
751 .if !empty(__qual_depdirs)
752 .for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m}
753 .if ${_debug_reldir} || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != ""
754 .info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q:S,^${SRCTOP}/,,}
756 .if ${BUILD_DIRDEPS_CACHE} == "yes"
757 _cache_deps += ${_build_dirs:M*.$q:S,^${SRCTOP}/,,}
759 ${_this_dir}.$m: ${_build_dirs:M*.$q}
764 .info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
766 .if ${BUILD_DIRDEPS_CACHE} == "yes"
767 .if !empty(_build_dirs)
768 _cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
769 .if !empty(_cache_deps)
771 _cache_script += for x in $$_cache_deps; do echo " _{SRCTOP}/$$x \\"; done;
773 # anything in _{build,env}_xtra_dirs is hooked to dirdeps: only
774 x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
775 echo; echo 'dirdeps: ${_this_dir}.$m \'; \
776 for x in $$_cache_xtra_deps; do echo " _{SRCTOP}/$$x \\"; done; \
777 echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3
780 ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
786 # Now find more dependencies - and recurse.
787 .for d in ${_build_all_dirs}
788 .if !target(_dirdeps_checked.$d)
792 .info checking ${d:S,^${SRCTOP}/,,}
794 # Note: _build_all_dirs is fully qualifed so d:R is always the directory
796 # we pass _DEP_TARGET_SPEC to tell the next step what we want
797 _DEP_TARGET_SPEC := ${d:E}
798 # some makefiles may still look at this
799 _DEP_MACHINE := ${d:E:C/,.*//}
800 # set these too in case Makefile.depend* uses them
801 .if ${TARGET_SPEC_VARS:[#]} > 1
802 _dtspec := ${_DEP_TARGET_SPEC:S/,/ /g}
803 .for i in ${_tspec_x}
804 DEP_${TARGET_SPEC_VARS:[$i]} := ${_dtspec:[$i]}
807 DEP_MACHINE := ${_DEP_MACHINE}
809 # Warning: there is an assumption here that MACHINE is always
810 # the first entry in TARGET_SPEC_VARS.
811 # If TARGET_SPEC and MACHINE are insufficient, you have a problem.
812 _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]}
814 # M_dep_qual_fixes isn't geared to Makefile.depend
815 _qm := ${_m:C;(\.depend)$;\1.${d:E};:${M_dep_qual_fixes:ts:}}
817 .info Looking for ${_qm}
819 # set this "just in case"
820 # we can skip :tA since we computed the path above
821 DEP_RELDIR := ${_m:H:S,^${SRCTOP}/,,}
824 .if ${_debug_reldir} && ${_qm} != ${_m}
825 .info loading ${_m} for ${d:E}
829 .-include <local.dirdeps-missing.mk>
836 .endif # BUILD_DIRDEPS
838 .elif ${.MAKE.LEVEL} > 42
839 .error You should have stopped recursing by now.
841 # we are building something
842 DEP_RELDIR := ${RELDIR}
843 _DEP_RELDIR := ${RELDIR}
844 # Since we are/should be included by .MAKE.DEPENDFILE
845 # This is a final opportunity to add/hook global rules.
846 .-include <local.dirdeps-build.mk>
848 # skip _reldir_{finish,failed} if not included from Makefile.depend*
849 # or not in meta mode
850 .if !defined(WITHOUT_META_STATS) && ${.INCLUDEDFROMFILE:U:M${.MAKE.DEPENDFILE_PREFIX}*} != "" && ${.MAKE.MODE:Mmeta} != ""
852 meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \
853 created=${empty(.MAKE.META.CREATED):?0:${.MAKE.META.CREATED:[#]}}
855 .if !target(_reldir_finish)
857 _reldir_finish: .NOMETA
858 @echo "${TRACER}Finished ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}"
861 .if !target(_reldir_failed)
862 .ERROR: _reldir_failed
863 _reldir_failed: .NOMETA
864 @echo "${TRACER}Failed ${RELDIR}.${TARGET_SPEC} seconds=$$(( ${now_utc} - ${start_utc} )) ${meta_stats}"
869 # pickup local dependencies
870 .if ${MAKE_VERSION} < 20160220
877 # bootstrapping new dependencies made easy?
878 .if !target(bootstrap-empty)
879 .if !target(bootstrap) && (make(bootstrap) || \
880 make(bootstrap-this) || \
881 make(bootstrap-recurse) || \
882 make(bootstrap-empty))
884 # if we are bootstrapping create the default
885 _want = ${.CURDIR}/${.MAKE.DEPENDFILE_DEFAULT:T}
890 .elif !make(bootstrap-empty)
891 # find a Makefile.depend to use as _src
892 _src != cd ${.CURDIR} && for m in ${.MAKE.DEPENDFILE_PREFERENCE:T:S,${MACHINE},*,}; do test -s $$m || continue; echo $$m; break; done; echo
894 .error cannot find any of ${.MAKE.DEPENDFILE_PREFERENCE:T}${.newline}Use: bootstrap-empty
897 _src?= ${.MAKE.DEPENDFILE}
899 .MAKE.DEPENDFILE_BOOTSTRAP_SED+= -e 's/${_src:E:C/,.*//}/${MACHINE}/g'
901 # just create Makefile.depend* for this dir
902 bootstrap-this: .NOTMAIN
903 @echo Bootstrapping ${RELDIR}/${_want:T} from ${_src:T}; \
904 echo You need to build ${RELDIR} to correctly populate it.
905 .if ${_src:T} != ${.MAKE.DEPENDFILE_PREFIX:T}
906 (cd ${.CURDIR} && sed ${.MAKE.DEPENDFILE_BOOTSTRAP_SED} ${_src} > ${_want:T})
908 cp ${.CURDIR}/${_src:T} ${_want}
911 # create Makefile.depend* for this dir and its dependencies
912 bootstrap: bootstrap-recurse
913 bootstrap-recurse: bootstrap-this
916 bootstrap-recurse: .NOTMAIN .MAKE
918 for d in `cd ${RELDIR} && ${.MAKE} -B -f ${"${.MAKEFLAGS:M-n}":?${_src}:${.MAKE.DEPENDFILE:T}} -V DIRDEPS`; do \
919 test -d $$d || d=$${d%.*}; \
920 test -d $$d || continue; \
921 echo "Checking $$d for bootstrap ..."; \
922 (cd $$d && ${.MAKE} -f ${_mf} bootstrap-recurse); \
927 # create an empty Makefile.depend* to get the ball rolling.
928 bootstrap-empty: .NOTMAIN .NOMETA
929 @echo Creating empty ${RELDIR}/${_want:T}; \
930 echo You need to build ${RELDIR} to correctly populate it.
931 @{ echo DIRDEPS=; echo ".include <dirdeps.mk>"; } > ${_want}