1249033Ssjg# $Id: dirdeps.mk,v 1.28 2013/03/25 21:11:43 sjg Exp $ 2246149Ssjg 3249033Ssjg# Copyright (c) 2010-2013, Juniper Networks, Inc. 4249033Ssjg# All rights reserved. 5246149Ssjg# 6246149Ssjg# Redistribution and use in source and binary forms, with or without 7246149Ssjg# modification, are permitted provided that the following conditions 8246149Ssjg# are met: 9246149Ssjg# 1. Redistributions of source code must retain the above copyright 10246149Ssjg# notice, this list of conditions and the following disclaimer. 11246149Ssjg# 2. Redistributions in binary form must reproduce the above copyright 12246149Ssjg# notice, this list of conditions and the following disclaimer in the 13246149Ssjg# documentation and/or other materials provided with the distribution. 14246149Ssjg# 15246149Ssjg# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16246149Ssjg# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17246149Ssjg# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18246149Ssjg# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19246149Ssjg# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20246149Ssjg# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21246149Ssjg# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22246149Ssjg# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23246149Ssjg# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24246149Ssjg# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25246149Ssjg# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26246149Ssjg 27246149Ssjg# Much of the complexity here is for supporting cross-building. 28246149Ssjg# If a tree does not support that, simply using plain Makefile.depend 29246149Ssjg# should provide sufficient clue. 30246149Ssjg# Otherwise the recommendation is to use Makefile.depend.${MACHINE} 31246149Ssjg# as expected below. 32246149Ssjg 33246149Ssjg# Note: this file gets multiply included. 34246149Ssjg# This is what we do with DIRDEPS 35246149Ssjg 36246149Ssjg# DIRDEPS: 37249033Ssjg# This is a list of directories - relative to SRCTOP, it is 38249033Ssjg# normally only of interest to .MAKE.LEVEL 0. 39246149Ssjg# In some cases the entry may be qualified with a .<machine> 40249033Ssjg# or .<target_spec> suffix (see TARGET_SPEC_VARS below), 41249033Ssjg# for example to force building something for the pseudo 42246149Ssjg# machines "host" or "common" regardless of current ${MACHINE}. 43249033Ssjg# 44249033Ssjg# All unqualified entries end up being qualified with .${TARGET_SPEC} 45249033Ssjg# and partially qualified (if TARGET_SPEC_VARS has multiple 46249033Ssjg# entries) are also expanded to a full .<target_spec>. 47249033Ssjg# The _DIRDEPS_USE target uses the suffix to set TARGET_SPEC 48246149Ssjg# correctly when visiting each entry. 49246149Ssjg# 50249033Ssjg# The fully qualified directory entries are used to construct a 51249033Ssjg# dependency graph that will drive the build later. 52249033Ssjg# 53249033Ssjg# Also, for each fully qualified directory target, we will search 54249033Ssjg# using ${.MAKE.DEPENDFILE_PREFERENCE} to find additional 55249033Ssjg# dependencies. We use Makefile.depend (default value for 56249033Ssjg# .MAKE.DEPENDFILE_PREFIX) to refer to these makefiles to 57249033Ssjg# distinguish them from others. 58249033Ssjg# 59249033Ssjg# Each Makefile.depend file sets DEP_RELDIR to be the 60246149Ssjg# the RELDIR (path relative to SRCTOP) for its directory, and 61249033Ssjg# since each Makefile.depend file includes dirdeps.mk, this 62246149Ssjg# processing is recursive and results in .MAKE.LEVEL 0 learning the 63246149Ssjg# dependencies of the tree wrt the initial directory (_DEP_RELDIR). 64246149Ssjg# 65246149Ssjg# BUILD_AT_LEVEL0 66246149Ssjg# Indicates whether .MAKE.LEVEL 0 builds anything: 67246149Ssjg# if "no" sub-makes are used to build everything, 68246149Ssjg# if "yes" sub-makes are only used to build for other machines. 69249033Ssjg# It is best to use "no", but this can require fixing some 70249033Ssjg# makefiles to not do anything at .MAKE.LEVEL 0. 71246149Ssjg# 72246149Ssjg# TARGET_SPEC_VARS 73249033Ssjg# The default value is just MACHINE, and for most environments 74249033Ssjg# this is sufficient. The _DIRDEPS_USE target actually sets 75249033Ssjg# both MACHINE and TARGET_SPEC to the suffix of the current 76249033Ssjg# target so that in the general case TARGET_SPEC can be ignored. 77246149Ssjg# 78249033Ssjg# If more than MACHINE is needed then sys.mk needs to decompose 79246149Ssjg# TARGET_SPEC and set the relevant variables accordingly. 80249033Ssjg# It is important that MACHINE be included in and actually be 81249033Ssjg# the first member of TARGET_SPEC_VARS. This allows other 82249033Ssjg# variables to be considered optional, and some of the treatment 83249033Ssjg# below relies on MACHINE being the first entry. 84246149Ssjg# Note: TARGET_SPEC cannot contain any '.'s so the target 85249033Ssjg# triple used by compiler folk won't work (directly anyway). 86246149Ssjg# 87246149Ssjg# For example: 88246149Ssjg# 89249033Ssjg# # Always list MACHINE first, 90249033Ssjg# # other variables might be optional. 91246149Ssjg# TARGET_SPEC_VARS = MACHINE TARGET_OS 92246149Ssjg# .if ${TARGET_SPEC:Uno:M*,*} != "" 93246149Ssjg# _tspec := ${TARGET_SPEC:S/,/ /g} 94246149Ssjg# MACHINE := ${_tspec:[1]} 95246149Ssjg# TARGET_OS := ${_tspec:[2]} 96246149Ssjg# # etc. 97249033Ssjg# # We need to stop that TARGET_SPEC affecting any submakes 98249033Ssjg# # and deal with MACHINE=${TARGET_SPEC} in the environment. 99249033Ssjg# TARGET_SPEC = 100249033Ssjg# # export but do not track 101249033Ssjg# .export-env TARGET_SPEC 102249033Ssjg# .export ${TARGET_SPEC_VARS} 103246149Ssjg# .for v in ${TARGET_SPEC_VARS:O:u} 104246149Ssjg# .if empty($v) 105246149Ssjg# .undef $v 106246149Ssjg# .endif 107246149Ssjg# .endfor 108246149Ssjg# .endif 109249033Ssjg# # make sure we know what TARGET_SPEC is 110249033Ssjg# # as we may need it to find Makefile.depend* 111249033Ssjg# TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 112246149Ssjg# 113246149Ssjg 114246149Ssjg.if ${.MAKE.LEVEL} == 0 115246149Ssjg# only the first instance is interested in all this 116246149Ssjg 117246149Ssjg# First off, we want to know what ${MACHINE} to build for. 118246149Ssjg# This can be complicated if we are using a mixture of ${MACHINE} specific 119246149Ssjg# and non-specific Makefile.depend* 120246149Ssjg 121246149Ssjg.if !target(_DIRDEP_USE) 122246149Ssjg# do some setup we only need once 123246149Ssjg_CURDIR ?= ${.CURDIR} 124246149Ssjg 125249033Ssjg# make sure these are empty to start with 126249033Ssjg_DEP_TARGET_SPEC = 127249033Ssjg_DIRDEP_CHECKED = 128249033Ssjg 129246149Ssjg# If TARGET_SPEC_VARS is other than just MACHINE 130246149Ssjg# it should be set by sys.mk or similar by now. 131246149Ssjg# TARGET_SPEC must not contain any '.'s. 132246149SsjgTARGET_SPEC_VARS ?= MACHINE 133249033Ssjg# this is what we started with 134246149SsjgTARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 135249033Ssjg# this is what we mostly use below 136249033SsjgDEP_TARGET_SPEC = ${TARGET_SPEC_VARS:S,^,DEP_,:@v@${$v:U}@:ts,} 137249033Ssjg# make sure we have defaults 138249033Ssjg.for v in ${TARGET_SPEC_VARS} 139249033SsjgDEP_$v ?= ${$v} 140249033Ssjg.endfor 141246149Ssjg 142249033Ssjg.if ${TARGET_SPEC_VARS:[#]} > 1 143249033Ssjg# Ok, this gets more complex (putting it mildly). 144249033Ssjg# In order to stay sane, we need to ensure that all the build_dirs 145249033Ssjg# we compute below are fully qualified wrt DEP_TARGET_SPEC. 146249033Ssjg# The makefiles may only partially specify (eg. MACHINE only), 147249033Ssjg# so we need to construct a set of modifiers to fill in the gaps. 148249033Ssjg# jot 10 should output 1 2 3 .. 10 149249033SsjgJOT ?= jot 150249033Ssjg_tspec_x := ${${JOT} ${TARGET_SPEC_VARS:[#]}:L:sh} 151249033Ssjg# this handles unqualified entries 152249033SsjgM_dep_qual_fixes = C;(/[^/.,]+)$$;\1.${DEP_TARGET_SPEC}; 153249033Ssjg# there needs to be at least one item missing for these to make sense 154249033Ssjg.for i in ${_tspec_x:[2..-1]} 155249033Ssjg_tspec_m$i := ${TARGET_SPEC_VARS:[2..$i]:@w@[^,]+@:ts,} 156249033Ssjg_tspec_a$i := ,${TARGET_SPEC_VARS:[$i..-1]:@v@$${DEP_$v}@:ts,} 157249033SsjgM_dep_qual_fixes += C;(\.${_tspec_m$i})$$;\1${_tspec_a$i}; 158249033Ssjg.endfor 159249033Ssjg.else 160249033Ssjg# A harmless? default. 161249033SsjgM_dep_qual_fixes = U 162249033Ssjg.endif 163249033Ssjg 164246149Ssjg.if !defined(.MAKE.DEPENDFILE_PREFERENCE) 165249033Ssjg# .MAKE.DEPENDFILE_PREFERENCE makes the logic below neater? 166249033Ssjg# you really want this set by sys.mk or similar 167246149Ssjg.MAKE.DEPENDFILE_PREFERENCE = ${_CURDIR}/${.MAKE.DEPENDFILE:T} 168246149Ssjg.if ${.MAKE.DEPENDFILE:E} == "${TARGET_SPEC}" 169246149Ssjg.if ${TARGET_SPEC} != ${MACHINE} 170246149Ssjg.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R}.$${MACHINE} 171246149Ssjg.endif 172246149Ssjg.MAKE.DEPENDFILE_PREFERENCE += ${_CURDIR}/${.MAKE.DEPENDFILE:T:R} 173246149Ssjg.endif 174246149Ssjg.endif 175246149Ssjg 176246149Ssjg_default_dependfile := ${.MAKE.DEPENDFILE_PREFERENCE:[1]:T} 177249033Ssjg_machine_dependfiles := ${.MAKE.DEPENDFILE_PREFERENCE:T:M*${MACHINE}*} 178246149Ssjg 179246149Ssjg# for machine specific dependfiles we require ${MACHINE} to be at the end 180246149Ssjg# also for the sake of sanity we require a common prefix 181246149Ssjg.if !defined(.MAKE.DEPENDFILE_PREFIX) 182249033Ssjg# knowing .MAKE.DEPENDFILE_PREFIX helps 183246149Ssjg.if !empty(_machine_dependfiles) 184246149Ssjg.MAKE.DEPENDFILE_PREFIX := ${_machine_dependfiles:[1]:T:R} 185246149Ssjg.else 186246149Ssjg.MAKE.DEPENDFILE_PREFIX := ${_default_dependfile:T} 187246149Ssjg.endif 188246149Ssjg.endif 189246149Ssjg 190246149Ssjg 191246149Ssjg# this is how we identify non-machine specific dependfiles 192249033SsjgN_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} 193246149Ssjg 194246149Ssjg.endif # !target(_DIRDEP_USE) 195246149Ssjg 196249033Ssjg# if we were included recursively _DEP_TARGET_SPEC should be valid. 197249033Ssjg.if empty(_DEP_TARGET_SPEC) 198249033Ssjg# we may or may not have included a dependfile yet 199246149Ssjg_last_dependfile := ${.MAKE.MAKEFILES:M*/${.MAKE.DEPENDFILE_PREFIX}*:[-1]} 200249033Ssjg.if !empty(_debug_reldir) 201249033Ssjg.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _last_dependfile='${_last_dependfile}' 202249033Ssjg.endif 203246149Ssjg 204249033Ssjg.if empty(_last_dependfile) || ${_last_dependfile:E:${N_notmachine}} == "" 205249033Ssjg# this is all we have to work with 206249033SsjgDEP_MACHINE = ${TARGET_MACHINE:U${MACHINE}} 207249033Ssjg_DEP_TARGET_SPEC := ${DEP_TARGET_SPEC} 208246149Ssjg.else 209249033Ssjg_DEP_TARGET_SPEC = ${_last_dependfile:${M_dep_qual_fixes:ts:}:E} 210246149Ssjg.endif 211249033Ssjg.if !empty(_last_dependfile) 212249033Ssjg# record that we've read dependfile for this 213249033Ssjg_DIRDEP_CHECKED += ${_CURDIR}.${TARGET_SPEC} 214249033Ssjg.endif 215249033Ssjg.endif 216246149Ssjg 217249033Ssjg# by now _DEP_TARGET_SPEC should be set, parse it. 218249033Ssjg.if ${TARGET_SPEC_VARS:[#]} > 1 219249033Ssjg# we need to parse DEP_MACHINE may or may not contain more info 220249033Ssjg_tspec := ${_DEP_TARGET_SPEC:S/,/ /g} 221249033Ssjg.for i in ${_tspec_x} 222249033SsjgDEP_${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} 223249033Ssjg.endfor 224249033Ssjg.for v in ${TARGET_SPEC_VARS:O:u} 225249033Ssjg.if empty(DEP_$v) 226249033Ssjg.undef DEP_$v 227249033Ssjg.endif 228249033Ssjg.endfor 229249033Ssjg.else 230249033SsjgDEP_MACHINE := ${_DEP_TARGET_SPEC} 231249033Ssjg.endif 232249033Ssjg 233246149Ssjg# pickup customizations 234246149Ssjg# as below you can use !target(_DIRDEP_USE) to protect things 235246149Ssjg# which should only be done once. 236246149Ssjg.-include "local.dirdeps.mk" 237246149Ssjg 238246149Ssjg# the first time we are included the _DIRDEP_USE target will not be defined 239246149Ssjg# we can use this as a clue to do initialization and other one time things. 240246149Ssjg.if !target(_DIRDEP_USE) 241246149Ssjg# make sure this target exists 242246149Ssjgdirdeps: 243246149Ssjg 244246149Ssjg# We normally expect to be included by Makefile.depend.* 245246149Ssjg# which sets the DEP_* macros below. 246246149SsjgDEP_RELDIR ?= ${RELDIR} 247246149Ssjg 248246149Ssjg# this can cause lots of output! 249246149Ssjg# set to a set of glob expressions that might match RELDIR 250246149SsjgDEBUG_DIRDEPS ?= no 251246149Ssjg 252246149Ssjg# remember the initial value of DEP_RELDIR - we test for it below. 253246149Ssjg_DEP_RELDIR := ${DEP_RELDIR} 254246149Ssjg 255246149Ssjg# things we skip for host tools 256246149SsjgSKIP_HOSTDIR ?= 257246149Ssjg 258246149SsjgNSkipHostDir = ${SKIP_HOSTDIR:N*.host:S,$,.host,:N.host:${M_ListToSkip}} 259246149Ssjg 260246149Ssjg# things we always skip 261246149Ssjg# SKIP_DIRDEPS allows for adding entries on command line. 262246149SsjgSKIP_DIR += .host *.WAIT ${SKIP_DIRDEPS} 263249033SsjgSKIP_DIR.host += ${SKIP_HOSTDIR} 264246149Ssjg 265249033SsjgDEP_SKIP_DIR = ${SKIP_DIR} \ 266249033Ssjg ${SKIP_DIR.${DEP_TARGET_SPEC}:U} \ 267249033Ssjg ${SKIP_DIR.${DEP_MACHINE}:U} \ 268249033Ssjg ${SKIP_DIRDEPS.${DEP_MACHINE}:U} 269246149Ssjg 270249033SsjgNSkipDir = ${DEP_SKIP_DIR:${M_ListToSkip}} 271246149Ssjg 272246149Ssjg.if defined(NO_DIRDEPS) || defined(NODIRDEPS) 273246149Ssjg# confine ourselves to the original dir 274246149SsjgDIRDEPS_FILTER += M${_DEP_RELDIR}* 275246149Ssjg.endif 276246149Ssjg 277246149Ssjg# we supress SUBDIR when visiting the leaves 278246149Ssjg# we assume sys.mk will set MACHINE_ARCH 279249033Ssjg# you can add extras to DIRDEP_USE_ENV 280249033Ssjg# if there is no makefile in the target directory, we skip it. 281246149Ssjg_DIRDEP_USE: .USE .MAKE 282246149Ssjg @for m in ${.MAKE.MAKEFILE_PREFERENCE}; do \ 283246149Ssjg test -s ${.TARGET:R}/$$m || continue; \ 284246149Ssjg echo "${TRACER}Checking ${.TARGET:R} for ${.TARGET:E} ..."; \ 285249033Ssjg MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \ 286246149Ssjg TARGET_SPEC=${.TARGET:E} \ 287249033Ssjg MACHINE=${.TARGET:E} \ 288246149Ssjg ${.MAKE} -C ${.TARGET:R} || exit 1; \ 289246149Ssjg break; \ 290246149Ssjg done 291246149Ssjg 292246149Ssjg.ifdef ALL_MACHINES 293246149Ssjg# this is how you limit it to only the machines we have been built for 294246149Ssjg# previously. 295246149Ssjg.if empty(ONLY_MACHINE_LIST) 296246149Ssjg.if !empty(ALL_MACHINE_LIST) 297246149Ssjg# ALL_MACHINE_LIST is the list of all legal machines - ignore anything else 298246149Ssjg_machine_list != cd ${_CURDIR} && 'ls' -1 ${ALL_MACHINE_LIST:O:u:@m@${.MAKE.DEPENDFILE:T:R}.$m@} 2> /dev/null; echo 299246149Ssjg.else 300246149Ssjg_machine_list != 'ls' -1 ${_CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.* 2> /dev/null; echo 301246149Ssjg.endif 302246149Ssjg_only_machines := ${_machine_list:${NIgnoreFiles:UN*.bak}:E:O:u} 303246149Ssjg.else 304246149Ssjg_only_machines := ${ONLY_MACHINE_LIST} 305246149Ssjg.endif 306246149Ssjg 307246149Ssjg.if empty(_only_machines) 308246149Ssjg# we must be boot-strapping 309246149Ssjg_only_machines := ${TARGET_MACHINE:U${ALL_MACHINE_LIST:U${DEP_MACHINE}}} 310246149Ssjg.endif 311246149Ssjg 312246149Ssjg.else # ! ALL_MACHINES 313246149Ssjg# if ONLY_MACHINE_LIST is set, we are limited to that 314246149Ssjg# if TARGET_MACHINE is set - it is really the same as ONLY_MACHINE_LIST 315246149Ssjg# otherwise DEP_MACHINE is it - so DEP_MACHINE will match. 316246149Ssjg_only_machines := ${ONLY_MACHINE_LIST:U${TARGET_MACHINE:U${DEP_MACHINE}}:M${DEP_MACHINE}} 317246149Ssjg.endif 318246149Ssjg 319246149Ssjg.if !empty(NOT_MACHINE_LIST) 320246149Ssjg_only_machines := ${_only_machines:${NOT_MACHINE_LIST:${M_ListToSkip}}} 321246149Ssjg.endif 322246149Ssjg 323246149Ssjg# make sure we have a starting place? 324246149SsjgDIRDEPS ?= ${RELDIR} 325246149Ssjg.endif # target 326246149Ssjg 327246149Ssjg_debug_reldir := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} 328246149Ssjg_debug_search := ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.depend:L:M$x}@} 329246149Ssjg 330246149Ssjg# the rest is done repeatedly for every Makefile.depend we read. 331246149Ssjg# if we are anything but the original dir we care only about the 332246149Ssjg# machine type we were included for.. 333246149Ssjg 334246149Ssjg.if ${DEP_RELDIR} == "." 335246149Ssjg_this_dir := ${SRCTOP} 336246149Ssjg.else 337246149Ssjg_this_dir := ${SRCTOP}/${DEP_RELDIR} 338246149Ssjg.endif 339246149Ssjg 340246149Ssjg# on rare occasions, there can be a need for extra help 341246149Ssjg_dep_hack := ${_this_dir}/${.MAKE.DEPENDFILE_PREFIX}.inc 342246149Ssjg.-include "${_dep_hack}" 343246149Ssjg 344249033Ssjg.if ${DEP_RELDIR} != ${_DEP_RELDIR} || ${DEP_TARGET_SPEC} != ${TARGET_SPEC} 345246149Ssjg# this should be all 346246149Ssjg_machines := ${DEP_MACHINE} 347246149Ssjg.else 348246149Ssjg# this is the machine list we actually use below 349246149Ssjg_machines := ${_only_machines} 350246149Ssjg 351246149Ssjg.if defined(HOSTPROG) || ${DEP_MACHINE} == "host" 352246149Ssjg# we need to build this guy's dependencies for host as well. 353246149Ssjg_machines += host 354246149Ssjg.endif 355246149Ssjg 356246149Ssjg_machines := ${_machines:O:u} 357246149Ssjg.endif 358246149Ssjg 359249033Ssjg.if ${TARGET_SPEC_VARS:[#]} > 1 360249033Ssjg# we need to tweak _machines 361249033Ssjg_dm := ${DEP_MACHINE} 362249033Ssjg_machines := ${_machines:@DEP_MACHINE@${DEP_TARGET_SPEC}@} 363249033SsjgDEP_MACHINE := ${_dm} 364249033Ssjg.endif 365249033Ssjg 366249033Ssjg# reset each time through 367246149Ssjg_build_dirs = 368246149Ssjg 369246149Ssjg.if ${DEP_RELDIR} == ${_DEP_RELDIR} 370246149Ssjg# pickup other machines for this dir if necessary 371246149Ssjg.if ${BUILD_AT_LEVEL0:Uyes} == "no" 372246149Ssjg_build_dirs += ${_machines:@m@${_CURDIR}.$m@} 373246149Ssjg.else 374249033Ssjg_build_dirs += ${_machines:N${DEP_TARGET_SPEC}:@m@${_CURDIR}.$m@} 375249033Ssjg.if ${DEP_TARGET_SPEC} == ${TARGET_SPEC} 376246149Ssjg# pickup local dependencies now 377246149Ssjg.-include <.depend> 378246149Ssjg.endif 379246149Ssjg.endif 380246149Ssjg.endif 381246149Ssjg 382246149Ssjg.if !empty(_debug_reldir) 383249033Ssjg.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}' 384249033Ssjg.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}' 385246149Ssjg.endif 386246149Ssjg 387246149Ssjg.if !empty(DIRDEPS) 388249033Ssjg# these we reset each time through as they can depend on DEP_MACHINE 389249033SsjgDEP_DIRDEPS_FILTER = \ 390249033Ssjg ${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \ 391249033Ssjg ${DIRDEPS_FILTER.${DEP_MACHINE}:U} \ 392249033Ssjg ${DIRDEPS_FILTER:U} 393249033Ssjg.if empty(DEP_DIRDEPS_FILTER) 394249033Ssjg# something harmless 395249033SsjgDEP_DIRDEPS_FILTER = U 396249033Ssjg.endif 397246149Ssjg 398246149Ssjg# this is what we start with 399249033Ssjg__depdirs := ${DIRDEPS:${NSkipDir}:${DEP_DIRDEPS_FILTER:ts:}:O:u:@d@${SRCTOP}/$d@} 400246149Ssjg 401246149Ssjg# some entries may be qualified with .<machine> 402246149Ssjg# the :M*/*/*.* just tries to limit the dirs we check to likely ones. 403246149Ssjg# the ${d:E:M*/*} ensures we don't consider junos/usr.sbin/mgd 404246149Ssjg__qual_depdirs := ${__depdirs:M*/*/*.*:@d@${exists($d):?:${"${d:E:M*/*}":?:${exists(${d:R}):?$d:}}}@} 405246149Ssjg__unqual_depdirs := ${__depdirs:${__qual_depdirs:Uno:${M_ListToSkip}}} 406246149Ssjg 407246149Ssjg.if ${DEP_RELDIR} == ${_DEP_RELDIR} 408246149Ssjg# if it was called out - we likely need it. 409246149Ssjg__hostdpadd := ${DPADD:U.:M${HOST_OBJTOP}/*:S,${HOST_OBJTOP}/,,:H:${NSkipDir}:${DIRDEPS_FILTER:ts:}:S,$,.host,:N.*:@d@${SRCTOP}/$d@} 410246149Ssjg__qual_depdirs += ${__hostdpadd} 411246149Ssjg.endif 412246149Ssjg 413246149Ssjg.if !empty(_debug_reldir) 414246149Ssjg.info depdirs=${__depdirs} 415246149Ssjg.info qualified=${__qual_depdirs} 416246149Ssjg.info unqualified=${__unqual_depdirs} 417246149Ssjg.endif 418246149Ssjg 419246149Ssjg# _build_dirs is what we will feed to _DIRDEP_USE 420246149Ssjg_build_dirs += \ 421246149Ssjg ${__qual_depdirs:M*.host:${NSkipHostDir}:N.host} \ 422246149Ssjg ${__qual_depdirs:N*.host} \ 423246149Ssjg ${_machines:@m@${__unqual_depdirs:@d@$d.$m@}@} 424246149Ssjg 425249033Ssjg# qualify everything now 426249033Ssjg_build_dirs := ${_build_dirs:${M_dep_qual_fixes:ts:}:O:u} 427246149Ssjg 428246149Ssjg.endif # empty DIRDEPS 429246149Ssjg 430246149Ssjg# Normally if doing make -V something, 431246149Ssjg# we do not want to waste time chasing DIRDEPS 432246149Ssjg# but if we want to count the number of Makefile.depend* read, we do. 433246149Ssjg.if ${.MAKEFLAGS:M-V${_V_READ_DIRDEPS}} == "" 434246149Ssjg.if !empty(_build_dirs) 435246149Ssjg# this makes it all happen 436246149Ssjgdirdeps: ${_build_dirs} 437246149Ssjg${_build_dirs}: _DIRDEP_USE 438246149Ssjg 439246149Ssjg.if !empty(_debug_reldir) 440249033Ssjg.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs} 441246149Ssjg.endif 442246149Ssjg 443249033Ssjg# this builds the dependency graph 444246149Ssjg.for m in ${_machines} 445246149Ssjg# it would be nice to do :N${.TARGET} 446246149Ssjg.if !empty(__qual_depdirs) 447249033Ssjg.for q in ${__qual_depdirs:${M_dep_qual_fixes:ts:}:E:O:u:N$m} 448246149Ssjg.if !empty(_debug_reldir) || ${DEBUG_DIRDEPS:@x@${${DEP_RELDIR}.$m:L:M$x}${${DEP_RELDIR}.$q:L:M$x}@} != "" 449249033Ssjg.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$q} 450246149Ssjg.endif 451246149Ssjg${_this_dir}.$m: ${_build_dirs:M*.$q} 452246149Ssjg.endfor 453246149Ssjg.endif 454246149Ssjg.if !empty(_debug_reldir) 455249033Ssjg.info ${DEP_RELDIR}.$m: graph: ${_build_dirs:M*.$m:N${_this_dir}.$m} 456246149Ssjg.endif 457246149Ssjg${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m} 458246149Ssjg.endfor 459246149Ssjg 460246149Ssjg.endif 461246149Ssjg 462249033Ssjg# Now find more dependencies - and recurse. 463249033Ssjg.for d in ${_build_dirs} 464249033Ssjg.if ${_DIRDEP_CHECKED:M$d} == "" 465249033Ssjg# once only 466249033Ssjg_DIRDEP_CHECKED += $d 467249033Ssjg# Note: _build_dirs is fully qualifed so d:R is always the directory 468249033Ssjg.if exists(${d:R}) 469249033Ssjg# Warning: there is an assumption here that MACHINE is always 470249033Ssjg# the first entry in TARGET_SPEC_VARS. 471249033Ssjg# If TARGET_SPEC and MACHINE are insufficient, you have a problem. 472249033Ssjg_m := ${.MAKE.DEPENDFILE_PREFERENCE:T:S;${TARGET_SPEC}$;${d:E};:S;${MACHINE};${d:E:C/,.*//};:@m@${exists(${d:R}/$m):?${d:R}/$m:}@:[1]} 473249033Ssjg.if !empty(_m) 474249033Ssjg_qm := ${_m:${M_dep_qual_fixes:ts:}} 475246149Ssjg.if !empty(_debug_search) 476249033Ssjg.info Looking for ${_qm} 477246149Ssjg.endif 478249033Ssjg# we pass _DEP_TARGET_SPEC to tell the next step what we want 479249033Ssjg_DEP_TARGET_SPEC := ${d:E} 480249033Ssjg# some makefiles may still look at this 481249033Ssjg_DEP_MACHINE := ${d:E:C/,.*//} 482249033Ssjg.if !empty(_debug_reldir) && ${_qm} != ${_m} 483249033Ssjg.info loading ${_m} for ${d:E} 484246149Ssjg.endif 485249033Ssjg.include <${_m}> 486246149Ssjg.endif 487246149Ssjg.endif 488249033Ssjg.endif 489246149Ssjg.endfor 490249033Ssjg 491246149Ssjg.endif # -V 492246149Ssjg 493246149Ssjg.elif ${.MAKE.LEVEL} > 42 494246149Ssjg.error You should have stopped recursing by now. 495246149Ssjg.else 496246149Ssjg_DEP_RELDIR := ${DEP_RELDIR} 497246149Ssjg# pickup local dependencies 498246149Ssjg.-include <.depend> 499246149Ssjg.endif 500246149Ssjg 501