xref: /dflybsd-src/contrib/bmake/mk/gendirdeps.mk (revision 9e7ae5a0527a977cab412aede3a532cfe2903bbb)
1*6eef5f0cSAntonio Huete Jimenez# $Id: gendirdeps.mk,v 1.48 2022/09/09 17:44:29 sjg Exp $
25f1e34d9SAlexandre Perrin
3ca58f742SDaniel Fojt# Copyright (c) 2011-2020, Simon J. Gerraty
4ca58f742SDaniel Fojt# Copyright (c) 2010-2018, Juniper Networks, Inc.
55f1e34d9SAlexandre Perrin# All rights reserved.
65f1e34d9SAlexandre Perrin#
75f1e34d9SAlexandre Perrin# Redistribution and use in source and binary forms, with or without
85f1e34d9SAlexandre Perrin# modification, are permitted provided that the following conditions
95f1e34d9SAlexandre Perrin# are met:
105f1e34d9SAlexandre Perrin# 1. Redistributions of source code must retain the above copyright
115f1e34d9SAlexandre Perrin#    notice, this list of conditions and the following disclaimer.
125f1e34d9SAlexandre Perrin# 2. Redistributions in binary form must reproduce the above copyright
135f1e34d9SAlexandre Perrin#    notice, this list of conditions and the following disclaimer in the
145f1e34d9SAlexandre Perrin#    documentation and/or other materials provided with the distribution.
155f1e34d9SAlexandre Perrin#
165f1e34d9SAlexandre Perrin# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175f1e34d9SAlexandre Perrin# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185f1e34d9SAlexandre Perrin# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195f1e34d9SAlexandre Perrin# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205f1e34d9SAlexandre Perrin# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215f1e34d9SAlexandre Perrin# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225f1e34d9SAlexandre Perrin# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235f1e34d9SAlexandre Perrin# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245f1e34d9SAlexandre Perrin# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255f1e34d9SAlexandre Perrin# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265f1e34d9SAlexandre Perrin# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275f1e34d9SAlexandre Perrin
285f1e34d9SAlexandre Perrin#
295f1e34d9SAlexandre Perrin# This makefile [re]generates ${.MAKE.DEPENDFILE}
305f1e34d9SAlexandre Perrin#
315f1e34d9SAlexandre Perrin
325f1e34d9SAlexandre Perrin.include <install-new.mk>
335f1e34d9SAlexandre Perrin
345f1e34d9SAlexandre Perrin# Assumptions:
355f1e34d9SAlexandre Perrin#	RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
365f1e34d9SAlexandre Perrin#		(SRCTOP is ${SB}/src)
375f1e34d9SAlexandre Perrin#	_CURDIR is the absolute version of ${.CURDIR}
385f1e34d9SAlexandre Perrin#	_OBJDIR is the absolute version of ${.OBJDIR}
395f1e34d9SAlexandre Perrin#	_objroot is realpath of ${_OBJTOP} without ${MACHINE}
405f1e34d9SAlexandre Perrin#		this may be different from _OBJROOT if $SB/obj is a
415f1e34d9SAlexandre Perrin#		symlink to another filesystem.
425f1e34d9SAlexandre Perrin#		_objroot must be a prefix match for _objtop
435f1e34d9SAlexandre Perrin
445f1e34d9SAlexandre Perrin.MAIN: all
455f1e34d9SAlexandre Perrin
465f1e34d9SAlexandre Perrin# keep this simple
475f1e34d9SAlexandre Perrin.MAKE.MODE = compat
485f1e34d9SAlexandre Perrin
495f1e34d9SAlexandre Perrinall:
505f1e34d9SAlexandre Perrin
515f1e34d9SAlexandre Perrin_CURDIR ?= ${.CURDIR}
525f1e34d9SAlexandre Perrin_OBJDIR ?= ${.OBJDIR}
535f1e34d9SAlexandre Perrin_OBJTOP ?= ${OBJTOP}
54ca58f742SDaniel Fojt_OBJROOT ?= ${OBJROOT:U${_OBJTOP:H}}
555f1e34d9SAlexandre Perrin.if ${_OBJROOT:M*/}
565f1e34d9SAlexandre Perrin_slash=/
575f1e34d9SAlexandre Perrin.else
585f1e34d9SAlexandre Perrin_slash=
595f1e34d9SAlexandre Perrin.endif
605f1e34d9SAlexandre Perrin_objroot ?= ${_OBJROOT:tA}${_slash}
615f1e34d9SAlexandre Perrin
625f1e34d9SAlexandre Perrin_this = ${.PARSEDIR}/${.PARSEFILE}
635f1e34d9SAlexandre Perrin
645f1e34d9SAlexandre Perrin# remember what to make
655f1e34d9SAlexandre Perrin_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
665f1e34d9SAlexandre Perrin
675f1e34d9SAlexandre Perrin# We do _not_ want to read our own output!
685f1e34d9SAlexandre Perrin.MAKE.DEPENDFILE = /dev/null
695f1e34d9SAlexandre Perrin
705f1e34d9SAlexandre Perrin# caller should have set this
715f1e34d9SAlexandre PerrinMETA_FILES ?= ${.MAKE.META.FILES}
725f1e34d9SAlexandre Perrin
735f1e34d9SAlexandre Perrin.if !empty(META_FILES)
745f1e34d9SAlexandre Perrin
755f1e34d9SAlexandre Perrin.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
765f1e34d9SAlexandre Perrin# so we can compare below
775f1e34d9SAlexandre Perrin.-include <${_DEPENDFILE}>
785f1e34d9SAlexandre Perrin# yes, I mean :U with no value
795f1e34d9SAlexandre Perrin_DIRDEPS := ${DIRDEPS:U:O:u}
805f1e34d9SAlexandre Perrin.endif
815f1e34d9SAlexandre Perrin
825f1e34d9SAlexandre PerrinMETA_FILES := ${META_FILES:T:O:u}
835f1e34d9SAlexandre Perrin
845f1e34d9SAlexandre Perrin# pickup customizations
85f445c897SJohn Marino.-include <local.gendirdeps.mk>
865f1e34d9SAlexandre Perrin
875f1e34d9SAlexandre Perrin# these are actually prefixes that we'll skip
885f1e34d9SAlexandre Perrin# they should all be absolute paths
895f1e34d9SAlexandre PerrinSKIP_GENDIRDEPS ?=
905f1e34d9SAlexandre Perrin.if !empty(SKIP_GENDIRDEPS)
91*6eef5f0cSAntonio Huete Jimenez_skip_gendirdeps = ${EGREP:Uegrep} -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
925f1e34d9SAlexandre Perrin.else
935f1e34d9SAlexandre Perrin_skip_gendirdeps =
945f1e34d9SAlexandre Perrin.endif
955f1e34d9SAlexandre Perrin
966a91b982SJohn Marino# Below we will turn _{VAR} into ${VAR} which keeps this simple
976a91b982SJohn Marino# GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for.
986a91b982SJohn Marino# GENDIRDEPS_FILTER_VARS is more general.
996a91b982SJohn Marino# In each case order matters.
1006a91b982SJohn Marino.if !empty(GENDIRDEPS_FILTER_DIR_VARS)
1016a91b982SJohn MarinoGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@}
1026a91b982SJohn Marino.endif
1036a91b982SJohn Marino.if !empty(GENDIRDEPS_FILTER_VARS)
1046a91b982SJohn MarinoGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u}
1056a91b982SJohn Marino.endif
1066a91b982SJohn Marino
1075f1e34d9SAlexandre Perrin# this (*should* be set in meta.sys.mk)
1085f1e34d9SAlexandre Perrin# is the script that extracts what we want.
1095f1e34d9SAlexandre PerrinMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh
1105f1e34d9SAlexandre PerrinMETA2DEPS := ${META2DEPS}
1115f1e34d9SAlexandre Perrin
1125f1e34d9SAlexandre Perrin.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != ""
1135f1e34d9SAlexandre Perrin_time = time
1145f1e34d9SAlexandre Perrin_sh_x = sh -x
1155f1e34d9SAlexandre Perrin_py_d = -ddd
1165f1e34d9SAlexandre Perrin.else
1175f1e34d9SAlexandre Perrin_time =
1185f1e34d9SAlexandre Perrin_sh_x =
1195f1e34d9SAlexandre Perrin_py_d =
1205f1e34d9SAlexandre Perrin.endif
1215f1e34d9SAlexandre Perrin
1225f1e34d9SAlexandre Perrin.if ${META2DEPS:E} == "py"
1235f1e34d9SAlexandre Perrin# we can afford to do this all the time.
1245f1e34d9SAlexandre PerrinDPDEPS ?= no
1255f1e34d9SAlexandre PerrinMETA2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d}
1265f1e34d9SAlexandre Perrin.if ${DPDEPS:tl} != "no"
1275f1e34d9SAlexandre PerrinMETA2DEPS_CMD += -D ${DPDEPS}
1285f1e34d9SAlexandre Perrin.endif
1295f1e34d9SAlexandre PerrinMETA2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
1305f1e34d9SAlexandre Perrin.elif ${META2DEPS:E} == "sh"
1315f1e34d9SAlexandre PerrinMETA2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP}
1325f1e34d9SAlexandre Perrin.else
1335f1e34d9SAlexandre PerrinMETA2DEPS_CMD ?= ${META2DEPS}
1345f1e34d9SAlexandre Perrin.endif
1355f1e34d9SAlexandre Perrin
1365f1e34d9SAlexandre Perrin.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE}
1375f1e34d9SAlexandre PerrinMETA2DEPS_CMD += -T ${TARGET_OBJ_SPEC}
1385f1e34d9SAlexandre Perrin.endif
1395f1e34d9SAlexandre PerrinMETA2DEPS_CMD += \
1405f1e34d9SAlexandre Perrin	-R ${RELDIR} -H ${HOST_TARGET} \
141f445c897SJohn Marino	${M2D_OBJROOTS:O:u:@o@-O $o@} \
142f445c897SJohn Marino	${M2D_EXCLUDES:O:u:@o@-X $o@} \
1435f1e34d9SAlexandre Perrin
1445f1e34d9SAlexandre Perrin
1455f1e34d9SAlexandre PerrinM2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot}
1465f1e34d9SAlexandre Perrin.if defined(SB_OBJROOT)
1475f1e34d9SAlexandre PerrinM2D_OBJROOTS += ${SB_OBJROOT}
1485f1e34d9SAlexandre Perrin.endif
149ca58f742SDaniel Fojt.if defined(STAGE_ROOT)
150ca58f742SDaniel FojtM2D_OBJROOTS += ${STAGE_ROOT}
151ca58f742SDaniel Fojt.endif
1525f1e34d9SAlexandre Perrin.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
1535f1e34d9SAlexandre Perrin# meta2deps.py only groks objroot
1545f1e34d9SAlexandre Perrin# so we need to give it what it expects
1555f1e34d9SAlexandre Perrin# and tell it not to add machine qualifiers
1565f1e34d9SAlexandre PerrinMETA2DEPS_ARGS += MACHINE=none
1575f1e34d9SAlexandre Perrin.endif
1585f1e34d9SAlexandre Perrin.if defined(SB_BACKING_SB)
1595f1e34d9SAlexandre PerrinMETA2DEPS_CMD += -S ${SB_BACKING_SB}/src
1605f1e34d9SAlexandre PerrinM2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX}
1615f1e34d9SAlexandre Perrin.endif
1625f1e34d9SAlexandre Perrin
163ca58f742SDaniel FojtGENDIRDEPS_SEDCMDS += \
164ca58f742SDaniel Fojt	-e 's,//*$$,,;s,\.${HOST_TARGET:Uhost}$$,.host,' \
165ca58f742SDaniel Fojt	-e 's,\.${HOST_TARGET32:Uhost32}$$,.host32,' \
166ca58f742SDaniel Fojt	-e 's,\.${MACHINE}$$,,' \
167ca58f742SDaniel Fojt	-e 's:\.${TARGET_SPEC:U${MACHINE}}$$::'
168ca58f742SDaniel Fojt
1695f1e34d9SAlexandre Perrin# we are only interested in the dirs
170f445c897SJohn Marino# specifically those we read something from.
1715f1e34d9SAlexandre Perrin# we canonicalize them to keep things simple
1725f1e34d9SAlexandre Perrin# if we are using a split-fs sandbox, it gets a little messier.
1735f1e34d9SAlexandre Perrin_objtop := ${_OBJTOP:tA}
174ca58f742SDaniel Fojt
175ca58f742SDaniel Fojt# some people put *.meta in META_XTRAS to make sure we get here
176ca58f742SDaniel Fojt_meta_files := ${META_FILES:N\*.meta:O:u}
177ca58f742SDaniel Fojt# assume a big list
178ca58f742SDaniel Fojt_meta_files_arg= @meta.list
179ca58f742SDaniel Fojt.if empty(_meta_files) && ${META_FILES:M\*.meta} != ""
180ca58f742SDaniel Fojt# XXX this should be considered a bad idea,
181ca58f742SDaniel Fojt# since we cannot ignore stale .meta
182ca58f742SDaniel Fojtx != cd ${_OBJDIR} && find . -name '*.meta' -print -o \( -type d ! -name . -prune \) | sed 's,^./,,' > meta.list; echo
183ca58f742SDaniel Fojt.elif ${_meta_files:[#]} > 500
184ca58f742SDaniel Fojt.export _meta_files
185ca58f742SDaniel Fojtx != echo; for m in $$_meta_files; do echo $$m; done > meta.list
186ca58f742SDaniel Fojt# _meta_files is consuming a lot of env space
187ca58f742SDaniel Fojt# that can impact command line length,
188ca58f742SDaniel Fojt# and we do not need it any more
189ca58f742SDaniel Fojt.undef _meta_files
190ca58f742SDaniel Fojt.unexport _meta_files
191ca58f742SDaniel Fojt.else
192ca58f742SDaniel Fojt_meta_files_arg:= ${_meta_files}
193ca58f742SDaniel Fojt.endif
194ca58f742SDaniel Fojt
1955f1e34d9SAlexandre Perrindir_list != cd ${_OBJDIR} && \
1965f1e34d9SAlexandre Perrin	${META2DEPS_CMD} MACHINE=${MACHINE} \
1975f1e34d9SAlexandre Perrin	SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \
1985f1e34d9SAlexandre Perrin	${META2DEPS_ARGS} \
199ca58f742SDaniel Fojt	${_meta_files_arg} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
200ca58f742SDaniel Fojt	sed ${GENDIRDEPS_SEDCMDS}
2015f1e34d9SAlexandre Perrin
2025f1e34d9SAlexandre Perrin.if ${dir_list:M*ERROR\:*} != ""
2035f1e34d9SAlexandre Perrin.warning ${dir_list:tW:C,.*(ERROR),\1,}
2045f1e34d9SAlexandre Perrin.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,}
2055f1e34d9SAlexandre Perrin# we are not going to update anything
2065f1e34d9SAlexandre Perrin.else
2075f1e34d9SAlexandre Perrindpadd_dir_list=
2085f1e34d9SAlexandre Perrin.if !empty(DPADD)
2095f1e34d9SAlexandre Perrin_nonlibs := ${DPADD:T:Nlib*:N*include}
2105f1e34d9SAlexandre Perrin.if !empty(_nonlibs)
2115f1e34d9SAlexandre Perrinddep_list =
2125f1e34d9SAlexandre Perrin.for f in ${_nonlibs:@x@${DPADD:M*/$x}@}
2135f1e34d9SAlexandre Perrin.if exists($f.dirdep)
2145f1e34d9SAlexandre Perrinddep_list += $f.dirdep
2155f1e34d9SAlexandre Perrin.elif exists(${f:H}.dirdep)
2165f1e34d9SAlexandre Perrinddep_list += ${f:H}.dirdep
2175f1e34d9SAlexandre Perrin.else
2185f1e34d9SAlexandre Perrindir_list += ${f:H:tA}
2195f1e34d9SAlexandre Perrindpadd_dir_list += ${f:H:tA}
2205f1e34d9SAlexandre Perrin.endif
2215f1e34d9SAlexandre Perrin.endfor
2225f1e34d9SAlexandre Perrin.if !empty(ddep_list)
2235f1e34d9SAlexandre Perrinddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
224ca58f742SDaniel Fojt	sed ${GENDIRDEPS_SEDCMDS}
2255f1e34d9SAlexandre Perrin
2265f1e34d9SAlexandre Perrin.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
2275f1e34d9SAlexandre Perrin.info ${RELDIR}: raw_dir_list='${dir_list}'
2285f1e34d9SAlexandre Perrin.info ${RELDIR}: ddeps='${ddeps}'
2295f1e34d9SAlexandre Perrin.endif
2305f1e34d9SAlexandre Perrindir_list += ${ddeps}
2315f1e34d9SAlexandre Perrin.endif
2325f1e34d9SAlexandre Perrin.endif
2335f1e34d9SAlexandre Perrin.endif
2345f1e34d9SAlexandre Perrin
2355f1e34d9SAlexandre Perrin# DIRDEPS represent things that had to have been built first
2365f1e34d9SAlexandre Perrin# so they should all be undir OBJTOP.
2375f1e34d9SAlexandre Perrin# Note that ${_OBJTOP}/bsd/include/machine will get reported
2385f1e34d9SAlexandre Perrin# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
2395f1e34d9SAlexandre Perrin# will want to visit bsd/include
2405f1e34d9SAlexandre Perrin# so we add
2415f1e34d9SAlexandre Perrin# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
2425f1e34d9SAlexandre Perrin# to GENDIRDEPS_DIR_LIST_XTRAS
2435f1e34d9SAlexandre Perrin_objtops = ${OBJTOP} ${_OBJTOP} ${_objtop}
2445f1e34d9SAlexandre Perrin_objtops := ${_objtops:O:u}
2455f1e34d9SAlexandre Perrindirdep_list = \
2465f1e34d9SAlexandre Perrin	${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \
2475f1e34d9SAlexandre Perrin	${GENDIRDEPS_DIR_LIST_XTRAS}
2485f1e34d9SAlexandre Perrin
2495f1e34d9SAlexandre Perrin# sort longest first
2505f1e34d9SAlexandre PerrinM2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]}
2515f1e34d9SAlexandre Perrin
2525f1e34d9SAlexandre Perrin# anything we use from an object dir other than ours
2535f1e34d9SAlexandre Perrin# needs to be qualified with its .<machine> suffix
2545f1e34d9SAlexandre Perrin# (we used the pseudo machine "host" for the HOST_TARGET).
2555f1e34d9SAlexandre Perrinskip_ql= ${SRCTOP}* ${_objtops:@o@$o*@}
2565f1e34d9SAlexandre Perrin.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}}
2575f1e34d9SAlexandre Perrin# we need := so only skip_ql to this point applies
2585f1e34d9SAlexandre Perrinql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
2595f1e34d9SAlexandre Perrinqualdir_list += ${ql.$o}
2605f1e34d9SAlexandre Perrin.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
2615f1e34d9SAlexandre Perrin.info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@}
2625f1e34d9SAlexandre Perrin.endif
2635f1e34d9SAlexandre Perrinskip_ql+= $o*
2645f1e34d9SAlexandre Perrin.endfor
2655f1e34d9SAlexandre Perrin
2665f1e34d9SAlexandre Perrindirdep_list := ${dirdep_list:O:u}
2675f1e34d9SAlexandre Perrinqualdir_list := ${qualdir_list:N*.${MACHINE}:O:u}
2685f1e34d9SAlexandre Perrin
2695f1e34d9SAlexandre PerrinDIRDEPS = \
2705f1e34d9SAlexandre Perrin	${dirdep_list:N${RELDIR}:N${RELDIR}/*} \
2715f1e34d9SAlexandre Perrin	${qualdir_list:N${RELDIR}.*:N${RELDIR}/*}
2725f1e34d9SAlexandre Perrin
2735f1e34d9SAlexandre Perrin# We only consider things below $RELDIR/ if they have a makefile.
2746a91b982SJohn Marino# This is the same test that _DIRDEP_USE applies.
2755f1e34d9SAlexandre Perrin# We have do a double test with dirdep_list as it _may_ contain
2765f1e34d9SAlexandre Perrin# qualified dirs - if we got anything from a stage dir.
2775f1e34d9SAlexandre Perrin# qualdir_list we know are all qualified.
2785f1e34d9SAlexandre Perrin# It would be nice do peform this check for all of DIRDEPS,
2795f1e34d9SAlexandre Perrin# but we cannot assume that all of the tree is present,
2805f1e34d9SAlexandre Perrin# in fact we can only assume that RELDIR is.
2815f1e34d9SAlexandre PerrinDIRDEPS += \
2825f1e34d9SAlexandre Perrin	${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \
2835f1e34d9SAlexandre Perrin	${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@}
2845f1e34d9SAlexandre Perrin
285ca58f742SDaniel Fojt# what modifiers do we allow in GENDIRDEPS_FILTER
286ca58f742SDaniel FojtGENDIRDEPS_FILTER_MASK += @CMNS
287ca58f742SDaniel FojtDIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:M[${GENDIRDEPS_FILTER_MASK:O:u:ts}]*:ts:}:C,//+,/,g:O:u}
2885f1e34d9SAlexandre Perrin
2895f1e34d9SAlexandre Perrin.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
2905f1e34d9SAlexandre Perrin.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS}
291f445c897SJohn Marino.info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES}
2925f1e34d9SAlexandre Perrin.info ${RELDIR}: dir_list='${dir_list}'
2935f1e34d9SAlexandre Perrin.info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}'
2945f1e34d9SAlexandre Perrin.info ${RELDIR}: dirdep_list='${dirdep_list}'
2955f1e34d9SAlexandre Perrin.info ${RELDIR}: qualdir_list='${qualdir_list}'
2965f1e34d9SAlexandre Perrin.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}'
2975f1e34d9SAlexandre Perrin.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}'
2985f1e34d9SAlexandre Perrin.info ${RELDIR}: FORCE_DPADD='${DPADD}'
2995f1e34d9SAlexandre Perrin.info ${RELDIR}: DIRDEPS='${DIRDEPS}'
3005f1e34d9SAlexandre Perrin.endif
3015f1e34d9SAlexandre Perrin
3025f1e34d9SAlexandre Perrin# SRC_DIRDEPS is for checkout logic
3035f1e34d9SAlexandre Perrinsrc_dirdep_list = \
3045f1e34d9SAlexandre Perrin	${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,}
3055f1e34d9SAlexandre Perrin
3065f1e34d9SAlexandre PerrinSRC_DIRDEPS = \
3075f1e34d9SAlexandre Perrin	${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,}
3085f1e34d9SAlexandre Perrin
3096a91b982SJohn MarinoSRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u}
3105f1e34d9SAlexandre Perrin
3115f1e34d9SAlexandre Perrin# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
3125f1e34d9SAlexandre Perrin# SRC_DIRDEPS_FILE = ${_DEPENDFILE}
3135f1e34d9SAlexandre Perrin# in local.gendirdeps.mk
3145f1e34d9SAlexandre Perrin.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no"
3155f1e34d9SAlexandre PerrinECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@	$d \\${.newline}@}'; echo;
3165f1e34d9SAlexandre Perrin
3175f1e34d9SAlexandre Perrin.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
3185f1e34d9SAlexandre Perrin_include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
3195f1e34d9SAlexandre Perrin.else
3205f1e34d9SAlexandre Perrinall: ${SRC_DIRDEPS_FILE}
3215f1e34d9SAlexandre Perrin.if !target(${SRC_DIRDEPS_FILE})
3225f1e34d9SAlexandre Perrin${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
3235f1e34d9SAlexandre Perrin	@(${ECHO_SRC_DIRDEPS}) > $@
3245f1e34d9SAlexandre Perrin.endif
3255f1e34d9SAlexandre Perrin.endif
3265f1e34d9SAlexandre Perrin.endif
3275f1e34d9SAlexandre Perrin_include_src_dirdeps ?=
3285f1e34d9SAlexandre Perrin
3295f1e34d9SAlexandre Perrinall:	${_DEPENDFILE}
3305f1e34d9SAlexandre Perrin
3315f1e34d9SAlexandre Perrin# if this is going to exist it would be there by now
3325f1e34d9SAlexandre Perrin.if !exists(.depend)
3335f1e34d9SAlexandre PerrinCAT_DEPEND = /dev/null
3345f1e34d9SAlexandre Perrin.endif
3355f1e34d9SAlexandre PerrinCAT_DEPEND ?= .depend
3365f1e34d9SAlexandre Perrin
3375f1e34d9SAlexandre Perrin.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
3385f1e34d9SAlexandre Perrin# we may have changed a filter
3395f1e34d9SAlexandre Perrin.PHONY: ${_DEPENDFILE}
3405f1e34d9SAlexandre Perrin.endif
3415f1e34d9SAlexandre Perrin
342*6eef5f0cSAntonio Huete Jimenez# set this to 'no' and we will not capture any
343*6eef5f0cSAntonio Huete Jimenez# local depends
344ca58f742SDaniel FojtLOCAL_DEPENDS_GUARD ?= _{.MAKE.LEVEL} > 0
345ca58f742SDaniel Fojt
3465f1e34d9SAlexandre Perrin# 'cat .depend' should suffice, but if we are mixing build modes
3475f1e34d9SAlexandre Perrin# .depend may contain things we don't want.
3485f1e34d9SAlexandre Perrin# The sed command at the end of the stream, allows for the filters
3495f1e34d9SAlexandre Perrin# to output _{VAR} tokens which we will turn into proper ${VAR} references.
350f445c897SJohn Marino${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
351f445c897SJohn Marino	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
3525f1e34d9SAlexandre Perrin	echo 'DIRDEPS = \'; \
3535f1e34d9SAlexandre Perrin	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \
3545f1e34d9SAlexandre Perrin	${_include_src_dirdeps} \
3555f1e34d9SAlexandre Perrin	echo '.include <dirdeps.mk>'; \
356*6eef5f0cSAntonio Huete Jimenez	[ "${LOCAL_DEPENDS_GUARD:[1]:tl}" != no ] || exit 0; \
3575f1e34d9SAlexandre Perrin	echo; \
358ca58f742SDaniel Fojt	echo '.if ${LOCAL_DEPENDS_GUARD}'; \
3595f1e34d9SAlexandre Perrin	echo '# local dependencies - needed for -jN in clean tree'; \
3605f1e34d9SAlexandre Perrin	[ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \
3615f1e34d9SAlexandre Perrin	echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID}
3625f1e34d9SAlexandre Perrin	@${InstallNew}; InstallNew -s $@.new${.MAKE.PID}
3635f1e34d9SAlexandre Perrin
3645f1e34d9SAlexandre Perrin.endif				# meta2deps failed
3655f1e34d9SAlexandre Perrin.elif !empty(SUBDIR)
3665f1e34d9SAlexandre Perrin
3675f1e34d9SAlexandre PerrinDIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u}
3685f1e34d9SAlexandre Perrin
3695f1e34d9SAlexandre Perrinall:	${_DEPENDFILE}
3705f1e34d9SAlexandre Perrin
371f445c897SJohn Marino${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this}
372f445c897SJohn Marino	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
3735f1e34d9SAlexandre Perrin	echo 'DIRDEPS = \'; \
3745f1e34d9SAlexandre Perrin	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \
3755f1e34d9SAlexandre Perrin	echo '.include <dirdeps.mk>'; \
3765f1e34d9SAlexandre Perrin	echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new
3775f1e34d9SAlexandre Perrin	@${InstallNew}; InstallNew $@.new
3785f1e34d9SAlexandre Perrin
3795f1e34d9SAlexandre Perrin.else
3805f1e34d9SAlexandre Perrin
3815f1e34d9SAlexandre Perrin# nothing to do
3825f1e34d9SAlexandre Perrinall ${_DEPENDFILE}:
3835f1e34d9SAlexandre Perrin
3845f1e34d9SAlexandre Perrin.endif
3855f1e34d9SAlexandre Perrin${_DEPENDFILE}: .PRECIOUS
386ca58f742SDaniel Fojt
387ca58f742SDaniel Fojt# don't waste time looking for ways to make .meta files
388ca58f742SDaniel Fojt.SUFFIXES:
389