xref: /freebsd/share/mk/gendirdeps.mk (revision 51c71d3e03236d6a10766bc6562051234495266d)
1ccfb9654SSimon J. Gerraty# $FreeBSD$
2be19d90bSSimon J. Gerraty# $Id: gendirdeps.mk,v 1.30 2016/02/27 00:20:39 sjg Exp $
37750ad47SMarcel Moolenaar
44ed4429cSSimon J. Gerraty# Copyright (c) 2010-2013, Juniper Networks, Inc.
54ed4429cSSimon J. Gerraty# All rights reserved.
67750ad47SMarcel Moolenaar#
77750ad47SMarcel Moolenaar# Redistribution and use in source and binary forms, with or without
87750ad47SMarcel Moolenaar# modification, are permitted provided that the following conditions
97750ad47SMarcel Moolenaar# are met:
107750ad47SMarcel Moolenaar# 1. Redistributions of source code must retain the above copyright
117750ad47SMarcel Moolenaar#    notice, this list of conditions and the following disclaimer.
127750ad47SMarcel Moolenaar# 2. Redistributions in binary form must reproduce the above copyright
137750ad47SMarcel Moolenaar#    notice, this list of conditions and the following disclaimer in the
147750ad47SMarcel Moolenaar#    documentation and/or other materials provided with the distribution.
157750ad47SMarcel Moolenaar#
167750ad47SMarcel Moolenaar# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177750ad47SMarcel Moolenaar# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187750ad47SMarcel Moolenaar# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197750ad47SMarcel Moolenaar# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207750ad47SMarcel Moolenaar# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217750ad47SMarcel Moolenaar# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227750ad47SMarcel Moolenaar# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237750ad47SMarcel Moolenaar# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247750ad47SMarcel Moolenaar# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257750ad47SMarcel Moolenaar# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267750ad47SMarcel Moolenaar# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277750ad47SMarcel Moolenaar
287750ad47SMarcel Moolenaar#
297750ad47SMarcel Moolenaar# This makefile [re]generates ${.MAKE.DEPENDFILE}
307750ad47SMarcel Moolenaar#
317750ad47SMarcel Moolenaar
327750ad47SMarcel Moolenaar.include <install-new.mk>
337750ad47SMarcel Moolenaar
347750ad47SMarcel Moolenaar# Assumptions:
357750ad47SMarcel Moolenaar#	RELDIR is the relative path from ${SRCTOP} to ${_CURDIR}
367750ad47SMarcel Moolenaar#		(SRCTOP is ${SB}/src)
377750ad47SMarcel Moolenaar#	_CURDIR is the absolute version of ${.CURDIR}
387750ad47SMarcel Moolenaar#	_OBJDIR is the absolute version of ${.OBJDIR}
397750ad47SMarcel Moolenaar#	_objroot is realpath of ${_OBJTOP} without ${MACHINE}
407750ad47SMarcel Moolenaar#		this may be different from _OBJROOT if $SB/obj is a
417750ad47SMarcel Moolenaar#		symlink to another filesystem.
427750ad47SMarcel Moolenaar#		_objroot must be a prefix match for _objtop
437750ad47SMarcel Moolenaar
447750ad47SMarcel Moolenaar.MAIN: all
457750ad47SMarcel Moolenaar
467750ad47SMarcel Moolenaar# keep this simple
477750ad47SMarcel Moolenaar.MAKE.MODE = compat
487750ad47SMarcel Moolenaar
497750ad47SMarcel Moolenaarall:
507750ad47SMarcel Moolenaar
517750ad47SMarcel Moolenaar_CURDIR ?= ${.CURDIR}
527750ad47SMarcel Moolenaar_OBJDIR ?= ${.OBJDIR}
537750ad47SMarcel Moolenaar_OBJTOP ?= ${OBJTOP}
547750ad47SMarcel Moolenaar_OBJROOT ?= ${OBJROOT:U${_OBJTOP}}
5510cd22b1SSimon J. Gerraty.if ${_OBJROOT:M*/}
5610cd22b1SSimon J. Gerraty_slash=/
5710cd22b1SSimon J. Gerraty.else
5810cd22b1SSimon J. Gerraty_slash=
5910cd22b1SSimon J. Gerraty.endif
6010cd22b1SSimon J. Gerraty_objroot ?= ${_OBJROOT:tA}${_slash}
617750ad47SMarcel Moolenaar
627750ad47SMarcel Moolenaar_this = ${.PARSEDIR}/${.PARSEFILE}
637750ad47SMarcel Moolenaar
647750ad47SMarcel Moolenaar# remember what to make
657750ad47SMarcel Moolenaar_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T}
667750ad47SMarcel Moolenaar
677750ad47SMarcel Moolenaar# We do _not_ want to read our own output!
687750ad47SMarcel Moolenaar.MAKE.DEPENDFILE = /dev/null
697750ad47SMarcel Moolenaar
707750ad47SMarcel Moolenaar# caller should have set this
717750ad47SMarcel MoolenaarMETA_FILES ?= ${.MAKE.META.FILES}
727750ad47SMarcel Moolenaar
737750ad47SMarcel Moolenaar.if !empty(META_FILES)
747750ad47SMarcel Moolenaar
757750ad47SMarcel Moolenaar.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER)
767750ad47SMarcel Moolenaar# so we can compare below
777750ad47SMarcel Moolenaar.-include <${_DEPENDFILE}>
787750ad47SMarcel Moolenaar# yes, I mean :U with no value
797750ad47SMarcel Moolenaar_DIRDEPS := ${DIRDEPS:U:O:u}
807750ad47SMarcel Moolenaar.endif
817750ad47SMarcel Moolenaar
827750ad47SMarcel MoolenaarMETA_FILES := ${META_FILES:T:O:u}
837750ad47SMarcel Moolenaar.export META_FILES
847750ad47SMarcel Moolenaar
857750ad47SMarcel Moolenaar# pickup customizations
86*51c71d3eSSimon J. Gerraty.-include <local.gendirdeps.mk>
877750ad47SMarcel Moolenaar
887750ad47SMarcel Moolenaar# these are actually prefixes that we'll skip
897750ad47SMarcel Moolenaar# they should all be absolute paths
907750ad47SMarcel MoolenaarSKIP_GENDIRDEPS ?=
917750ad47SMarcel Moolenaar.if !empty(SKIP_GENDIRDEPS)
927750ad47SMarcel Moolenaar_skip_gendirdeps = egrep -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' |
937750ad47SMarcel Moolenaar.else
947750ad47SMarcel Moolenaar_skip_gendirdeps =
957750ad47SMarcel Moolenaar.endif
967750ad47SMarcel Moolenaar
976251c65aSSimon J. Gerraty# Below we will turn _{VAR} into ${VAR} which keeps this simple
986251c65aSSimon J. Gerraty# GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for.
996251c65aSSimon J. Gerraty# GENDIRDEPS_FILTER_VARS is more general.
1006251c65aSSimon J. Gerraty# In each case order matters.
1016251c65aSSimon J. Gerraty.if !empty(GENDIRDEPS_FILTER_DIR_VARS)
1026251c65aSSimon J. GerratyGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@}
1036251c65aSSimon J. Gerraty.endif
1046251c65aSSimon J. Gerraty.if !empty(GENDIRDEPS_FILTER_VARS)
1056251c65aSSimon J. GerratyGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u}
1066251c65aSSimon J. Gerraty.endif
1076251c65aSSimon J. Gerraty
1087750ad47SMarcel Moolenaar# this (*should* be set in meta.sys.mk)
1097750ad47SMarcel Moolenaar# is the script that extracts what we want.
1107750ad47SMarcel MoolenaarMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh
1117750ad47SMarcel MoolenaarMETA2DEPS := ${META2DEPS}
1127750ad47SMarcel Moolenaar
1137750ad47SMarcel Moolenaar.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != ""
1147750ad47SMarcel Moolenaar_time = time
1157750ad47SMarcel Moolenaar_sh_x = sh -x
1167750ad47SMarcel Moolenaar_py_d = -ddd
1177750ad47SMarcel Moolenaar.else
1187750ad47SMarcel Moolenaar_time =
1197750ad47SMarcel Moolenaar_sh_x =
1207750ad47SMarcel Moolenaar_py_d =
1217750ad47SMarcel Moolenaar.endif
1227750ad47SMarcel Moolenaar
1237750ad47SMarcel Moolenaar.if ${META2DEPS:E} == "py"
1247750ad47SMarcel Moolenaar# we can afford to do this all the time.
1257750ad47SMarcel MoolenaarDPDEPS ?= no
12606137b0fSSimon J. GerratyMETA2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d}
12706137b0fSSimon J. Gerraty.if ${DPDEPS:tl} != "no"
12806137b0fSSimon J. GerratyMETA2DEPS_CMD += -D ${DPDEPS}
12906137b0fSSimon J. Gerraty.endif
13006137b0fSSimon J. GerratyMETA2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
13106137b0fSSimon J. Gerraty.elif ${META2DEPS:E} == "sh"
13206137b0fSSimon J. GerratyMETA2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP}
13306137b0fSSimon J. Gerraty.else
13406137b0fSSimon J. GerratyMETA2DEPS_CMD ?= ${META2DEPS}
13506137b0fSSimon J. Gerraty.endif
1364ed4429cSSimon J. Gerraty
13701f18a0cSSimon J. Gerraty.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE}
13801f18a0cSSimon J. GerratyMETA2DEPS_CMD += -T ${TARGET_OBJ_SPEC}
13901f18a0cSSimon J. Gerraty.endif
14006137b0fSSimon J. GerratyMETA2DEPS_CMD += \
14106137b0fSSimon J. Gerraty	-R ${RELDIR} -H ${HOST_TARGET} \
142*51c71d3eSSimon J. Gerraty	${M2D_OBJROOTS:O:u:@o@-O $o@} \
143*51c71d3eSSimon J. Gerraty	${M2D_EXCLUDES:O:u:@o@-X $o@} \
14406137b0fSSimon J. Gerraty
1454ed4429cSSimon J. Gerraty
146876336c8SSimon J. GerratyM2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot}
1474ed4429cSSimon J. Gerraty.if defined(SB_OBJROOT)
1484ed4429cSSimon J. GerratyM2D_OBJROOTS += ${SB_OBJROOT}
1494ed4429cSSimon J. Gerraty.endif
1507750ad47SMarcel Moolenaar.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == ""
1517750ad47SMarcel Moolenaar# meta2deps.py only groks objroot
1527750ad47SMarcel Moolenaar# so we need to give it what it expects
1537750ad47SMarcel Moolenaar# and tell it not to add machine qualifiers
1547750ad47SMarcel MoolenaarMETA2DEPS_ARGS += MACHINE=none
1557750ad47SMarcel Moolenaar.endif
1567750ad47SMarcel Moolenaar.if defined(SB_BACKING_SB)
1574ed4429cSSimon J. GerratyMETA2DEPS_CMD += -S ${SB_BACKING_SB}/src
1584ed4429cSSimon J. GerratyM2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX}
1597750ad47SMarcel Moolenaar.endif
1607750ad47SMarcel Moolenaar
1617750ad47SMarcel Moolenaar# we are only interested in the dirs
162af928aa0SBryan Drewery# specifically those we read something from.
1637750ad47SMarcel Moolenaar# we canonicalize them to keep things simple
1647750ad47SMarcel Moolenaar# if we are using a split-fs sandbox, it gets a little messier.
1657750ad47SMarcel Moolenaar_objtop := ${_OBJTOP:tA}
1667750ad47SMarcel Moolenaardir_list != cd ${_OBJDIR} && \
1677750ad47SMarcel Moolenaar	${META2DEPS_CMD} MACHINE=${MACHINE} \
1687750ad47SMarcel Moolenaar	SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \
1697750ad47SMarcel Moolenaar	${META2DEPS_ARGS} \
1707750ad47SMarcel Moolenaar	${META_FILES:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
1717750ad47SMarcel Moolenaar	sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,'
1727750ad47SMarcel Moolenaar
1737750ad47SMarcel Moolenaar.if ${dir_list:M*ERROR\:*} != ""
1747750ad47SMarcel Moolenaar.warning ${dir_list:tW:C,.*(ERROR),\1,}
1757750ad47SMarcel Moolenaar.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,}
1767750ad47SMarcel Moolenaar# we are not going to update anything
1777750ad47SMarcel Moolenaar.else
17810ea6facSSimon J. Gerratydpadd_dir_list=
1797750ad47SMarcel Moolenaar.if !empty(DPADD)
1807750ad47SMarcel Moolenaar_nonlibs := ${DPADD:T:Nlib*:N*include}
1817750ad47SMarcel Moolenaar.if !empty(_nonlibs)
182c2ec0b51SSimon J. Gerratyddep_list =
1832cb6de20SSimon J. Gerraty.for f in ${_nonlibs:@x@${DPADD:M*/$x}@}
184c2ec0b51SSimon J. Gerraty.if exists($f.dirdep)
185c2ec0b51SSimon J. Gerratyddep_list += $f.dirdep
186c2ec0b51SSimon J. Gerraty.elif exists(${f:H}.dirdep)
187c2ec0b51SSimon J. Gerratyddep_list += ${f:H}.dirdep
188c2ec0b51SSimon J. Gerraty.else
1892cb6de20SSimon J. Gerratydir_list += ${f:H:tA}
19010ea6facSSimon J. Gerratydpadd_dir_list += ${f:H:tA}
191c2ec0b51SSimon J. Gerraty.endif
192c2ec0b51SSimon J. Gerraty.endfor
193c2ec0b51SSimon J. Gerraty.if !empty(ddep_list)
194c2ec0b51SSimon J. Gerratyddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \
195876336c8SSimon J. Gerraty        sed 's,//*$$,,;s,\.${HOST_TARGET}$$,.host,;s,\.${MACHINE}$$,,'
196876336c8SSimon J. Gerraty
197876336c8SSimon J. Gerraty.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
198876336c8SSimon J. Gerraty.info ${RELDIR}: raw_dir_list='${dir_list}'
199876336c8SSimon J. Gerraty.info ${RELDIR}: ddeps='${ddeps}'
200876336c8SSimon J. Gerraty.endif
201c2ec0b51SSimon J. Gerratydir_list += ${ddeps}
202c2ec0b51SSimon J. Gerraty.endif
2037750ad47SMarcel Moolenaar.endif
2047750ad47SMarcel Moolenaar.endif
2057750ad47SMarcel Moolenaar
2067750ad47SMarcel Moolenaar# DIRDEPS represent things that had to have been built first
2077750ad47SMarcel Moolenaar# so they should all be undir OBJTOP.
2087750ad47SMarcel Moolenaar# Note that ${_OBJTOP}/bsd/include/machine will get reported
2097750ad47SMarcel Moolenaar# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we
2107750ad47SMarcel Moolenaar# will want to visit bsd/include
2117750ad47SMarcel Moolenaar# so we add
2127750ad47SMarcel Moolenaar# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:}
2137750ad47SMarcel Moolenaar# to GENDIRDEPS_DIR_LIST_XTRAS
21410ea6facSSimon J. Gerraty_objtops = ${OBJTOP} ${_OBJTOP} ${_objtop}
215876336c8SSimon J. Gerraty_objtops := ${_objtops:O:u}
2167750ad47SMarcel Moolenaardirdep_list = \
217876336c8SSimon J. Gerraty	${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \
2187750ad47SMarcel Moolenaar	${GENDIRDEPS_DIR_LIST_XTRAS}
2197750ad47SMarcel Moolenaar
220c2ec0b51SSimon J. Gerraty# sort longest first
221c2ec0b51SSimon J. GerratyM2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]}
222c2ec0b51SSimon J. Gerraty
2237750ad47SMarcel Moolenaar# anything we use from an object dir other than ours
2247750ad47SMarcel Moolenaar# needs to be qualified with its .<machine> suffix
2257750ad47SMarcel Moolenaar# (we used the pseudo machine "host" for the HOST_TARGET).
226876336c8SSimon J. Gerratyskip_ql= ${SRCTOP}* ${_objtops:@o@$o*@}
227c2ec0b51SSimon J. Gerraty.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}}
228876336c8SSimon J. Gerraty# we need := so only skip_ql to this point applies
22910ea6facSSimon J. Gerratyql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,}
23010ea6facSSimon J. Gerratyqualdir_list += ${ql.$o}
23110ea6facSSimon J. Gerraty.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
23210ea6facSSimon J. Gerraty.info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@}
23310ea6facSSimon J. Gerraty.endif
234c2ec0b51SSimon J. Gerratyskip_ql+= $o*
235c2ec0b51SSimon J. Gerraty.endfor
2367750ad47SMarcel Moolenaar
2377750ad47SMarcel Moolenaardirdep_list := ${dirdep_list:O:u}
238c2ec0b51SSimon J. Gerratyqualdir_list := ${qualdir_list:N*.${MACHINE}:O:u}
2397750ad47SMarcel Moolenaar
2407750ad47SMarcel MoolenaarDIRDEPS = \
2417750ad47SMarcel Moolenaar	${dirdep_list:N${RELDIR}:N${RELDIR}/*} \
2427750ad47SMarcel Moolenaar	${qualdir_list:N${RELDIR}.*:N${RELDIR}/*}
2437750ad47SMarcel Moolenaar
2447750ad47SMarcel Moolenaar# We only consider things below $RELDIR/ if they have a makefile.
24510ea6facSSimon J. Gerraty# This is the same test that _DIRDEP_USE applies.
2467750ad47SMarcel Moolenaar# We have do a double test with dirdep_list as it _may_ contain
2477750ad47SMarcel Moolenaar# qualified dirs - if we got anything from a stage dir.
2487750ad47SMarcel Moolenaar# qualdir_list we know are all qualified.
2497750ad47SMarcel Moolenaar# It would be nice do peform this check for all of DIRDEPS,
2507750ad47SMarcel Moolenaar# but we cannot assume that all of the tree is present,
2517750ad47SMarcel Moolenaar# in fact we can only assume that RELDIR is.
2527750ad47SMarcel MoolenaarDIRDEPS += \
2537750ad47SMarcel Moolenaar	${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \
2547750ad47SMarcel Moolenaar	${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@}
2557750ad47SMarcel Moolenaar
25610ea6facSSimon J. GerratyDIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:ts:}:C,//+,/,g:O:u}
2577750ad47SMarcel Moolenaar
2587750ad47SMarcel Moolenaar.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != ""
259c2ec0b51SSimon J. Gerraty.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS}
260*51c71d3eSSimon J. Gerraty.info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES}
2617750ad47SMarcel Moolenaar.info ${RELDIR}: dir_list='${dir_list}'
26210ea6facSSimon J. Gerraty.info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}'
2637750ad47SMarcel Moolenaar.info ${RELDIR}: dirdep_list='${dirdep_list}'
2647750ad47SMarcel Moolenaar.info ${RELDIR}: qualdir_list='${qualdir_list}'
2657750ad47SMarcel Moolenaar.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}'
2667750ad47SMarcel Moolenaar.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}'
2677750ad47SMarcel Moolenaar.info ${RELDIR}: FORCE_DPADD='${DPADD}'
2687750ad47SMarcel Moolenaar.info ${RELDIR}: DIRDEPS='${DIRDEPS}'
2697750ad47SMarcel Moolenaar.endif
2707750ad47SMarcel Moolenaar
2717750ad47SMarcel Moolenaar# SRC_DIRDEPS is for checkout logic
2727750ad47SMarcel Moolenaarsrc_dirdep_list = \
2737750ad47SMarcel Moolenaar	${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,}
2747750ad47SMarcel Moolenaar
2757750ad47SMarcel MoolenaarSRC_DIRDEPS = \
2767750ad47SMarcel Moolenaar	${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,}
2777750ad47SMarcel Moolenaar
27810ea6facSSimon J. GerratySRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u}
2797750ad47SMarcel Moolenaar
2807750ad47SMarcel Moolenaar# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put
2817750ad47SMarcel Moolenaar# SRC_DIRDEPS_FILE = ${_DEPENDFILE}
2827750ad47SMarcel Moolenaar# in local.gendirdeps.mk
2837750ad47SMarcel Moolenaar.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no"
2847750ad47SMarcel MoolenaarECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@	$d \\${.newline}@}'; echo;
2857750ad47SMarcel Moolenaar
2867750ad47SMarcel Moolenaar.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T}
2877750ad47SMarcel Moolenaar_include_src_dirdeps = ${ECHO_SRC_DIRDEPS}
2887750ad47SMarcel Moolenaar.else
2897750ad47SMarcel Moolenaarall: ${SRC_DIRDEPS_FILE}
2907750ad47SMarcel Moolenaar.if !target(${SRC_DIRDEPS_FILE})
2917750ad47SMarcel Moolenaar${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS}
2927750ad47SMarcel Moolenaar	@(${ECHO_SRC_DIRDEPS}) > $@
2937750ad47SMarcel Moolenaar.endif
2947750ad47SMarcel Moolenaar.endif
2957750ad47SMarcel Moolenaar.endif
2967750ad47SMarcel Moolenaar_include_src_dirdeps ?=
2977750ad47SMarcel Moolenaar
2987750ad47SMarcel Moolenaarall:	${_DEPENDFILE}
2997750ad47SMarcel Moolenaar
3007750ad47SMarcel Moolenaar# if this is going to exist it would be there by now
3017750ad47SMarcel Moolenaar.if !exists(.depend)
3027750ad47SMarcel MoolenaarCAT_DEPEND = /dev/null
3037750ad47SMarcel Moolenaar.endif
3047750ad47SMarcel MoolenaarCAT_DEPEND ?= .depend
3057750ad47SMarcel Moolenaar
3067750ad47SMarcel Moolenaar.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS}
3077750ad47SMarcel Moolenaar# we may have changed a filter
3087750ad47SMarcel Moolenaar.PHONY: ${_DEPENDFILE}
3097750ad47SMarcel Moolenaar.endif
3107750ad47SMarcel Moolenaar
3117750ad47SMarcel Moolenaar# 'cat .depend' should suffice, but if we are mixing build modes
3127750ad47SMarcel Moolenaar# .depend may contain things we don't want.
3137750ad47SMarcel Moolenaar# The sed command at the end of the stream, allows for the filters
3147750ad47SMarcel Moolenaar# to output _{VAR} tokens which we will turn into proper ${VAR} references.
315be19d90bSSimon J. Gerraty${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS}
316ccfb9654SSimon J. Gerraty	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
3177750ad47SMarcel Moolenaar	echo 'DIRDEPS = \'; \
3187750ad47SMarcel Moolenaar	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \
3197750ad47SMarcel Moolenaar	${_include_src_dirdeps} \
3207750ad47SMarcel Moolenaar	echo '.include <dirdeps.mk>'; \
3217750ad47SMarcel Moolenaar	echo; \
3227750ad47SMarcel Moolenaar	echo '.if $${DEP_RELDIR} == $${_DEP_RELDIR}'; \
3237750ad47SMarcel Moolenaar	echo '# local dependencies - needed for -jN in clean tree'; \
3247750ad47SMarcel Moolenaar	[ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \
3257750ad47SMarcel Moolenaar	echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID}
3267750ad47SMarcel Moolenaar	@${InstallNew}; InstallNew -s $@.new${.MAKE.PID}
3277750ad47SMarcel Moolenaar
3287750ad47SMarcel Moolenaar.endif				# meta2deps failed
3297750ad47SMarcel Moolenaar.elif !empty(SUBDIR)
3307750ad47SMarcel Moolenaar
3317750ad47SMarcel MoolenaarDIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u}
3327750ad47SMarcel Moolenaar
3337750ad47SMarcel Moolenaarall:	${_DEPENDFILE}
3347750ad47SMarcel Moolenaar
335be19d90bSSimon J. Gerraty${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this}
336ccfb9654SSimon J. Gerraty	@(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \
3377750ad47SMarcel Moolenaar	echo 'DIRDEPS = \'; \
3387750ad47SMarcel Moolenaar	echo '${DIRDEPS:@d@	$d \\${.newline}@}'; echo; \
3397750ad47SMarcel Moolenaar	echo '.include <dirdeps.mk>'; \
3407750ad47SMarcel Moolenaar	echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new
3417750ad47SMarcel Moolenaar	@${InstallNew}; InstallNew $@.new
3427750ad47SMarcel Moolenaar
3437750ad47SMarcel Moolenaar.else
3447750ad47SMarcel Moolenaar
3457750ad47SMarcel Moolenaar# nothing to do
3467750ad47SMarcel Moolenaarall ${_DEPENDFILE}:
3477750ad47SMarcel Moolenaar
3487750ad47SMarcel Moolenaar.endif
3497750ad47SMarcel Moolenaar${_DEPENDFILE}: .PRECIOUS
350