1*6647af9bSSimon J. Gerraty# $Id: gendirdeps.mk,v 1.50 2023/11/04 16:47:34 sjg Exp $ 27750ad47SMarcel Moolenaar 3f957a32dSSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 4f957a32dSSimon J. Gerraty# 5960b77beSSimon J. Gerraty# Copyright (c) 2011-2020, Simon J. Gerraty 6960b77beSSimon J. Gerraty# Copyright (c) 2010-2018, Juniper Networks, Inc. 74ed4429cSSimon J. Gerraty# All rights reserved. 87750ad47SMarcel Moolenaar# 97750ad47SMarcel Moolenaar# Redistribution and use in source and binary forms, with or without 107750ad47SMarcel Moolenaar# modification, are permitted provided that the following conditions 117750ad47SMarcel Moolenaar# are met: 127750ad47SMarcel Moolenaar# 1. Redistributions of source code must retain the above copyright 137750ad47SMarcel Moolenaar# notice, this list of conditions and the following disclaimer. 147750ad47SMarcel Moolenaar# 2. Redistributions in binary form must reproduce the above copyright 157750ad47SMarcel Moolenaar# notice, this list of conditions and the following disclaimer in the 167750ad47SMarcel Moolenaar# documentation and/or other materials provided with the distribution. 177750ad47SMarcel Moolenaar# 187750ad47SMarcel Moolenaar# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 197750ad47SMarcel Moolenaar# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 207750ad47SMarcel Moolenaar# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 217750ad47SMarcel Moolenaar# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 227750ad47SMarcel Moolenaar# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 237750ad47SMarcel Moolenaar# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 247750ad47SMarcel Moolenaar# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 257750ad47SMarcel Moolenaar# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 267750ad47SMarcel Moolenaar# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 277750ad47SMarcel Moolenaar# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 287750ad47SMarcel Moolenaar# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 297750ad47SMarcel Moolenaar 307750ad47SMarcel Moolenaar# 317750ad47SMarcel Moolenaar# This makefile [re]generates ${.MAKE.DEPENDFILE} 327750ad47SMarcel Moolenaar# 337750ad47SMarcel Moolenaar 347750ad47SMarcel Moolenaar.include <install-new.mk> 357750ad47SMarcel Moolenaar 367750ad47SMarcel Moolenaar# Assumptions: 377750ad47SMarcel Moolenaar# RELDIR is the relative path from ${SRCTOP} to ${_CURDIR} 387750ad47SMarcel Moolenaar# (SRCTOP is ${SB}/src) 397750ad47SMarcel Moolenaar# _CURDIR is the absolute version of ${.CURDIR} 407750ad47SMarcel Moolenaar# _OBJDIR is the absolute version of ${.OBJDIR} 417750ad47SMarcel Moolenaar# _objroot is realpath of ${_OBJTOP} without ${MACHINE} 427750ad47SMarcel Moolenaar# this may be different from _OBJROOT if $SB/obj is a 437750ad47SMarcel Moolenaar# symlink to another filesystem. 447750ad47SMarcel Moolenaar# _objroot must be a prefix match for _objtop 457750ad47SMarcel Moolenaar 46f957a32dSSimon J. Gerraty# If any of GENDIRDEPS_FILTER, GENDIRDEPS_FILTER_DIR_VARS 47f957a32dSSimon J. Gerraty# or GENDIRDEPS_FILTER_VARS are set, we use them to filter the 48f957a32dSSimon J. Gerraty# output from filemon(4). 49f957a32dSSimon J. Gerraty# Any references to variables that dirdeps.mk will set 50f957a32dSSimon J. Gerraty# such as DEP_MACHINE, DEP_RELDIR etc, should use that form. 51f957a32dSSimon J. Gerraty# Thus we want ${DEP_MACHINE} not ${MACHINE} used in DIRDEPS. 52f957a32dSSimon J. Gerraty# 53f957a32dSSimon J. Gerraty# If any manually maintained Makefile.depend files will use any 54f957a32dSSimon J. Gerraty# DEP_* variables in conditionals, precautions are needed to avoid 55f957a32dSSimon J. Gerraty# errors when Makefile.depend is read at level 1+ (ie not via 56f957a32dSSimon J. Gerraty# dirdeps.mk) 57f957a32dSSimon J. Gerraty# Using MACHINE as an example; such makefiles can do: 58f957a32dSSimon J. Gerraty# 59f957a32dSSimon J. Gerraty# DEP_MACHINE ?= ${MACHINE} 60f957a32dSSimon J. Gerraty# .if ${DEP_MACHINE} == "xyz" 61f957a32dSSimon J. Gerraty# 62f957a32dSSimon J. Gerraty# or: 63f957a32dSSimon J. Gerraty# 64f957a32dSSimon J. Gerraty# .if ${DEP_MACHINE:U${MACHINE}} == "xyz" 65f957a32dSSimon J. Gerraty# 66f957a32dSSimon J. Gerraty# but it might be safer to set GENDIRDEPS_FILTER_DIR_VARS and 67f957a32dSSimon J. Gerraty# GENDIRDEPS_FILTER_VARS via local.meta.sys.mk rather than 68f957a32dSSimon J. Gerraty# local.gendirdeps.mk and then: 69f957a32dSSimon J. Gerraty# 70f957a32dSSimon J. Gerraty# .if ${.MAKE.LEVEL} > 0 71f957a32dSSimon J. Gerraty# .for V in ${GENDIRDEPS_FILTER_DIR_VARS:MDEP_*} \ 72f957a32dSSimon J. Gerraty# ${GENDIRDEPS_FILTER_VARS:MDEP_*} 73f957a32dSSimon J. Gerraty# $V ?= ${${V:S,DEP_,,}} 74f957a32dSSimon J. Gerraty# .endfor 75f957a32dSSimon J. Gerraty# .endif 76f957a32dSSimon J. Gerraty# 777750ad47SMarcel Moolenaar.MAIN: all 787750ad47SMarcel Moolenaar 797750ad47SMarcel Moolenaar# keep this simple 807750ad47SMarcel Moolenaar.MAKE.MODE = compat 817750ad47SMarcel Moolenaar 827750ad47SMarcel Moolenaarall: 837750ad47SMarcel Moolenaar 847750ad47SMarcel Moolenaar_CURDIR ?= ${.CURDIR} 857750ad47SMarcel Moolenaar_OBJDIR ?= ${.OBJDIR} 867750ad47SMarcel Moolenaar_OBJTOP ?= ${OBJTOP} 87960b77beSSimon J. Gerraty_OBJROOT ?= ${OBJROOT:U${_OBJTOP:H}} 8810cd22b1SSimon J. Gerraty.if ${_OBJROOT:M*/} 8910cd22b1SSimon J. Gerraty_slash=/ 9010cd22b1SSimon J. Gerraty.else 9110cd22b1SSimon J. Gerraty_slash= 9210cd22b1SSimon J. Gerraty.endif 9310cd22b1SSimon J. Gerraty_objroot ?= ${_OBJROOT:tA}${_slash} 947750ad47SMarcel Moolenaar 957750ad47SMarcel Moolenaar_this = ${.PARSEDIR}/${.PARSEFILE} 967750ad47SMarcel Moolenaar 977750ad47SMarcel Moolenaar# remember what to make 987750ad47SMarcel Moolenaar_DEPENDFILE := ${_CURDIR}/${.MAKE.DEPENDFILE:T} 997750ad47SMarcel Moolenaar 1007750ad47SMarcel Moolenaar# We do _not_ want to read our own output! 1017750ad47SMarcel Moolenaar.MAKE.DEPENDFILE = /dev/null 1027750ad47SMarcel Moolenaar 1037750ad47SMarcel Moolenaar# caller should have set this 1047750ad47SMarcel MoolenaarMETA_FILES ?= ${.MAKE.META.FILES} 105*6647af9bSSimon J. Gerraty# this sometimes needs to be passed separately 106*6647af9bSSimon J. Gerraty.if !empty(META_XTRAS) 107*6647af9bSSimon J. GerratyMETA_FILES += ${META_XTRAS:N\*.meta} 108*6647af9bSSimon J. Gerraty.endif 1097750ad47SMarcel Moolenaar 1107750ad47SMarcel Moolenaar.if !empty(META_FILES) 1117750ad47SMarcel Moolenaar 1127750ad47SMarcel Moolenaar.if ${.MAKE.LEVEL} > 0 && !empty(GENDIRDEPS_FILTER) 1137750ad47SMarcel Moolenaar# so we can compare below 1147750ad47SMarcel Moolenaar.-include <${_DEPENDFILE}> 1157750ad47SMarcel Moolenaar# yes, I mean :U with no value 1167750ad47SMarcel Moolenaar_DIRDEPS := ${DIRDEPS:U:O:u} 1177750ad47SMarcel Moolenaar.endif 1187750ad47SMarcel Moolenaar 1197750ad47SMarcel MoolenaarMETA_FILES := ${META_FILES:T:O:u} 1207750ad47SMarcel Moolenaar 1217750ad47SMarcel Moolenaar# pickup customizations 12251c71d3eSSimon J. Gerraty.-include <local.gendirdeps.mk> 1237750ad47SMarcel Moolenaar 1247750ad47SMarcel Moolenaar# these are actually prefixes that we'll skip 1257750ad47SMarcel Moolenaar# they should all be absolute paths 1267750ad47SMarcel MoolenaarSKIP_GENDIRDEPS ?= 1277750ad47SMarcel Moolenaar.if !empty(SKIP_GENDIRDEPS) 128bf7aa99aSSimon J. Gerraty_skip_gendirdeps = ${EGREP:Uegrep} -v '^(${SKIP_GENDIRDEPS:O:u:ts|})' | 1297750ad47SMarcel Moolenaar.else 1307750ad47SMarcel Moolenaar_skip_gendirdeps = 1317750ad47SMarcel Moolenaar.endif 1327750ad47SMarcel Moolenaar 1336251c65aSSimon J. Gerraty# Below we will turn _{VAR} into ${VAR} which keeps this simple 1346251c65aSSimon J. Gerraty# GENDIRDEPS_FILTER_DIR_VARS is a list of dirs to be substiuted for. 1356251c65aSSimon J. Gerraty# GENDIRDEPS_FILTER_VARS is more general. 1366251c65aSSimon J. Gerraty# In each case order matters. 1376251c65aSSimon J. Gerraty.if !empty(GENDIRDEPS_FILTER_DIR_VARS) 1386251c65aSSimon J. GerratyGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_DIR_VARS:@v@S,${$v},_{${v}},@} 1396251c65aSSimon J. Gerraty.endif 1406251c65aSSimon J. Gerraty.if !empty(GENDIRDEPS_FILTER_VARS) 1416251c65aSSimon J. GerratyGENDIRDEPS_FILTER += ${GENDIRDEPS_FILTER_VARS:@v@S,/${$v}/,/_{${v}}/,@:NS,//,*:u} 1426251c65aSSimon J. Gerraty.endif 1436251c65aSSimon J. Gerraty 1447750ad47SMarcel Moolenaar# this (*should* be set in meta.sys.mk) 1457750ad47SMarcel Moolenaar# is the script that extracts what we want. 1467750ad47SMarcel MoolenaarMETA2DEPS ?= ${.PARSEDIR}/meta2deps.sh 1477750ad47SMarcel MoolenaarMETA2DEPS := ${META2DEPS} 1487750ad47SMarcel Moolenaar 1497750ad47SMarcel Moolenaar.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" && ${DEBUG_GENDIRDEPS:Uno:Mmeta2d*} != "" 1507750ad47SMarcel Moolenaar_time = time 1517750ad47SMarcel Moolenaar_sh_x = sh -x 1527750ad47SMarcel Moolenaar_py_d = -ddd 1537750ad47SMarcel Moolenaar.else 1547750ad47SMarcel Moolenaar_time = 1557750ad47SMarcel Moolenaar_sh_x = 1567750ad47SMarcel Moolenaar_py_d = 1577750ad47SMarcel Moolenaar.endif 1587750ad47SMarcel Moolenaar 1597750ad47SMarcel Moolenaar.if ${META2DEPS:E} == "py" 1607750ad47SMarcel Moolenaar# we can afford to do this all the time. 1617750ad47SMarcel MoolenaarDPDEPS ?= no 16206137b0fSSimon J. GerratyMETA2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} 16306137b0fSSimon J. Gerraty.if ${DPDEPS:tl} != "no" 16406137b0fSSimon J. GerratyMETA2DEPS_CMD += -D ${DPDEPS} 16506137b0fSSimon J. Gerraty.endif 16606137b0fSSimon J. GerratyMETA2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' | 16706137b0fSSimon J. Gerraty.elif ${META2DEPS:E} == "sh" 16806137b0fSSimon J. GerratyMETA2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP} 16906137b0fSSimon J. Gerraty.else 17006137b0fSSimon J. GerratyMETA2DEPS_CMD ?= ${META2DEPS} 17106137b0fSSimon J. Gerraty.endif 1724ed4429cSSimon J. Gerraty 17301f18a0cSSimon J. Gerraty.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE} 17401f18a0cSSimon J. GerratyMETA2DEPS_CMD += -T ${TARGET_OBJ_SPEC} 17501f18a0cSSimon J. Gerraty.endif 17606137b0fSSimon J. GerratyMETA2DEPS_CMD += \ 17706137b0fSSimon J. Gerraty -R ${RELDIR} -H ${HOST_TARGET} \ 17851c71d3eSSimon J. Gerraty ${M2D_OBJROOTS:O:u:@o@-O $o@} \ 17951c71d3eSSimon J. Gerraty ${M2D_EXCLUDES:O:u:@o@-X $o@} \ 18006137b0fSSimon J. Gerraty 1814ed4429cSSimon J. Gerraty 182876336c8SSimon J. GerratyM2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot} 1834ed4429cSSimon J. Gerraty.if defined(SB_OBJROOT) 1844ed4429cSSimon J. GerratyM2D_OBJROOTS += ${SB_OBJROOT} 1854ed4429cSSimon J. Gerraty.endif 186b47b9f6bSSimon J. Gerraty.if defined(STAGE_ROOT) 187b47b9f6bSSimon J. GerratyM2D_OBJROOTS += ${STAGE_ROOT} 188b47b9f6bSSimon J. Gerraty.endif 1897750ad47SMarcel Moolenaar.if ${.MAKE.DEPENDFILE_PREFERENCE:U${.MAKE.DEPENDFILE}:M*.${MACHINE}} == "" 1907750ad47SMarcel Moolenaar# meta2deps.py only groks objroot 1917750ad47SMarcel Moolenaar# so we need to give it what it expects 1927750ad47SMarcel Moolenaar# and tell it not to add machine qualifiers 1937750ad47SMarcel MoolenaarMETA2DEPS_ARGS += MACHINE=none 1947750ad47SMarcel Moolenaar.endif 1957750ad47SMarcel Moolenaar.if defined(SB_BACKING_SB) 1964ed4429cSSimon J. GerratyMETA2DEPS_CMD += -S ${SB_BACKING_SB}/src 1974ed4429cSSimon J. GerratyM2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX} 1987750ad47SMarcel Moolenaar.endif 1997750ad47SMarcel Moolenaar 200a6589ab7SSimon J. GerratyGENDIRDEPS_SEDCMDS += \ 201a6589ab7SSimon J. Gerraty -e 's,//*$$,,;s,\.${HOST_TARGET:Uhost}$$,.host,' \ 202a6589ab7SSimon J. Gerraty -e 's,\.${HOST_TARGET32:Uhost32}$$,.host32,' \ 203a6589ab7SSimon J. Gerraty -e 's,\.${MACHINE}$$,,' \ 204a6589ab7SSimon J. Gerraty -e 's:\.${TARGET_SPEC:U${MACHINE}}$$::' 205a6589ab7SSimon J. Gerraty 2067750ad47SMarcel Moolenaar# we are only interested in the dirs 207af928aa0SBryan Drewery# specifically those we read something from. 2087750ad47SMarcel Moolenaar# we canonicalize them to keep things simple 2097750ad47SMarcel Moolenaar# if we are using a split-fs sandbox, it gets a little messier. 2107750ad47SMarcel Moolenaar_objtop := ${_OBJTOP:tA} 211a6589ab7SSimon J. Gerraty 212a6589ab7SSimon J. Gerraty# some people put *.meta in META_XTRAS to make sure we get here 213a6589ab7SSimon J. Gerraty_meta_files := ${META_FILES:N\*.meta:O:u} 214a6589ab7SSimon J. Gerraty# assume a big list 215a6589ab7SSimon J. Gerraty_meta_files_arg= @meta.list 216a6589ab7SSimon J. Gerraty.if empty(_meta_files) && ${META_FILES:M\*.meta} != "" 217a6589ab7SSimon J. Gerraty# XXX this should be considered a bad idea, 218a6589ab7SSimon J. Gerraty# since we cannot ignore stale .meta 219a6589ab7SSimon J. Gerratyx != cd ${_OBJDIR} && find . -name '*.meta' -print -o \( -type d ! -name . -prune \) | sed 's,^./,,' > meta.list; echo 220a6589ab7SSimon J. Gerraty.elif ${_meta_files:[#]} > 500 221a6589ab7SSimon J. Gerraty.export _meta_files 222a6589ab7SSimon J. Gerratyx != echo; for m in $$_meta_files; do echo $$m; done > meta.list 223312809feSSimon J. Gerraty# _meta_files is consuming a lot of env space 224312809feSSimon J. Gerraty# that can impact command line length, 225312809feSSimon J. Gerraty# and we do not need it any more 226312809feSSimon J. Gerraty.undef _meta_files 227312809feSSimon J. Gerraty.unexport _meta_files 228a6589ab7SSimon J. Gerraty.else 229a6589ab7SSimon J. Gerraty_meta_files_arg:= ${_meta_files} 230a6589ab7SSimon J. Gerraty.endif 231a6589ab7SSimon J. Gerraty 2327750ad47SMarcel Moolenaardir_list != cd ${_OBJDIR} && \ 2337750ad47SMarcel Moolenaar ${META2DEPS_CMD} MACHINE=${MACHINE} \ 2347750ad47SMarcel Moolenaar SRCTOP=${SRCTOP} RELDIR=${RELDIR} CURDIR=${_CURDIR} \ 2357750ad47SMarcel Moolenaar ${META2DEPS_ARGS} \ 236a6589ab7SSimon J. Gerraty ${_meta_files_arg} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 237a6589ab7SSimon J. Gerraty sed ${GENDIRDEPS_SEDCMDS} 2387750ad47SMarcel Moolenaar 2397750ad47SMarcel Moolenaar.if ${dir_list:M*ERROR\:*} != "" 2407750ad47SMarcel Moolenaar.warning ${dir_list:tW:C,.*(ERROR),\1,} 2417750ad47SMarcel Moolenaar.warning Skipping ${_DEPENDFILE:S,${SRCTOP}/,,} 2427750ad47SMarcel Moolenaar# we are not going to update anything 2437750ad47SMarcel Moolenaar.else 24410ea6facSSimon J. Gerratydpadd_dir_list= 2457750ad47SMarcel Moolenaar.if !empty(DPADD) 2467750ad47SMarcel Moolenaar_nonlibs := ${DPADD:T:Nlib*:N*include} 2477750ad47SMarcel Moolenaar.if !empty(_nonlibs) 248c2ec0b51SSimon J. Gerratyddep_list = 2492cb6de20SSimon J. Gerraty.for f in ${_nonlibs:@x@${DPADD:M*/$x}@} 250c2ec0b51SSimon J. Gerraty.if exists($f.dirdep) 251c2ec0b51SSimon J. Gerratyddep_list += $f.dirdep 252c2ec0b51SSimon J. Gerraty.elif exists(${f:H}.dirdep) 253c2ec0b51SSimon J. Gerratyddep_list += ${f:H}.dirdep 254c2ec0b51SSimon J. Gerraty.else 2552cb6de20SSimon J. Gerratydir_list += ${f:H:tA} 25610ea6facSSimon J. Gerratydpadd_dir_list += ${f:H:tA} 257c2ec0b51SSimon J. Gerraty.endif 258c2ec0b51SSimon J. Gerraty.endfor 259c2ec0b51SSimon J. Gerraty.if !empty(ddep_list) 260c2ec0b51SSimon J. Gerratyddeps != cat ${ddep_list:O:u} | ${META2DEPS_FILTER} ${_skip_gendirdeps} \ 261a6589ab7SSimon J. Gerraty sed ${GENDIRDEPS_SEDCMDS} 262876336c8SSimon J. Gerraty 263876336c8SSimon J. Gerraty.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 264876336c8SSimon J. Gerraty.info ${RELDIR}: raw_dir_list='${dir_list}' 265876336c8SSimon J. Gerraty.info ${RELDIR}: ddeps='${ddeps}' 266876336c8SSimon J. Gerraty.endif 267c2ec0b51SSimon J. Gerratydir_list += ${ddeps} 268c2ec0b51SSimon J. Gerraty.endif 2697750ad47SMarcel Moolenaar.endif 2707750ad47SMarcel Moolenaar.endif 2717750ad47SMarcel Moolenaar 2727750ad47SMarcel Moolenaar# DIRDEPS represent things that had to have been built first 2737750ad47SMarcel Moolenaar# so they should all be undir OBJTOP. 2747750ad47SMarcel Moolenaar# Note that ${_OBJTOP}/bsd/include/machine will get reported 2757750ad47SMarcel Moolenaar# to us as $SRCTOP/bsd/sys/$MACHINE_ARCH/include meaning we 2767750ad47SMarcel Moolenaar# will want to visit bsd/include 2777750ad47SMarcel Moolenaar# so we add 2787750ad47SMarcel Moolenaar# ${"${dir_list:M*bsd/sys/${MACHINE_ARCH}/include}":?bsd/include:} 2797750ad47SMarcel Moolenaar# to GENDIRDEPS_DIR_LIST_XTRAS 28010ea6facSSimon J. Gerraty_objtops = ${OBJTOP} ${_OBJTOP} ${_objtop} 281876336c8SSimon J. Gerraty_objtops := ${_objtops:O:u} 2827750ad47SMarcel Moolenaardirdep_list = \ 283876336c8SSimon J. Gerraty ${_objtops:@o@${dir_list:M$o*/*:C,$o[^/]*/,,}@} \ 2847750ad47SMarcel Moolenaar ${GENDIRDEPS_DIR_LIST_XTRAS} 2857750ad47SMarcel Moolenaar 286c2ec0b51SSimon J. Gerraty# sort longest first 287c2ec0b51SSimon J. GerratyM2D_OBJROOTS := ${M2D_OBJROOTS:O:u:[-1..1]} 288c2ec0b51SSimon J. Gerraty 2897750ad47SMarcel Moolenaar# anything we use from an object dir other than ours 2907750ad47SMarcel Moolenaar# needs to be qualified with its .<machine> suffix 2917750ad47SMarcel Moolenaar# (we used the pseudo machine "host" for the HOST_TARGET). 292876336c8SSimon J. Gerratyskip_ql= ${SRCTOP}* ${_objtops:@o@$o*@} 293c2ec0b51SSimon J. Gerraty.for o in ${M2D_OBJROOTS:${skip_ql:${M_ListToSkip}}} 294876336c8SSimon J. Gerraty# we need := so only skip_ql to this point applies 29510ea6facSSimon J. Gerratyql.$o := ${dir_list:${skip_ql:${M_ListToSkip}}:M$o*/*/*:C,$o([^/]+)/(.*),\2.\1,:S,.${HOST_TARGET},.host,} 29610ea6facSSimon J. Gerratyqualdir_list += ${ql.$o} 29710ea6facSSimon J. Gerraty.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 29810ea6facSSimon J. Gerraty.info ${RELDIR}: o=$o ${ql.$o qualdir_list:L:@v@$v=${$v}@} 29910ea6facSSimon J. Gerraty.endif 300c2ec0b51SSimon J. Gerratyskip_ql+= $o* 301c2ec0b51SSimon J. Gerraty.endfor 3027750ad47SMarcel Moolenaar 3037750ad47SMarcel Moolenaardirdep_list := ${dirdep_list:O:u} 304c2ec0b51SSimon J. Gerratyqualdir_list := ${qualdir_list:N*.${MACHINE}:O:u} 3057750ad47SMarcel Moolenaar 3067750ad47SMarcel MoolenaarDIRDEPS = \ 3077750ad47SMarcel Moolenaar ${dirdep_list:N${RELDIR}:N${RELDIR}/*} \ 3087750ad47SMarcel Moolenaar ${qualdir_list:N${RELDIR}.*:N${RELDIR}/*} 3097750ad47SMarcel Moolenaar 3107750ad47SMarcel Moolenaar# We only consider things below $RELDIR/ if they have a makefile. 31110ea6facSSimon J. Gerraty# This is the same test that _DIRDEP_USE applies. 3127750ad47SMarcel Moolenaar# We have do a double test with dirdep_list as it _may_ contain 3137750ad47SMarcel Moolenaar# qualified dirs - if we got anything from a stage dir. 3147750ad47SMarcel Moolenaar# qualdir_list we know are all qualified. 3157750ad47SMarcel Moolenaar# It would be nice do peform this check for all of DIRDEPS, 3167750ad47SMarcel Moolenaar# but we cannot assume that all of the tree is present, 3177750ad47SMarcel Moolenaar# in fact we can only assume that RELDIR is. 3187750ad47SMarcel MoolenaarDIRDEPS += \ 3197750ad47SMarcel Moolenaar ${dirdep_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/$d/$m):?$d:${exists(${SRCTOP}/${d:R}/$m):?$d:}}@}@} \ 3207750ad47SMarcel Moolenaar ${qualdir_list:M${RELDIR}/*:@d@${.MAKE.MAKEFILE_PREFERENCE:@m@${exists(${SRCTOP}/${d:R}/$m):?$d:}@}@} 3217750ad47SMarcel Moolenaar 322a6589ab7SSimon J. Gerraty# what modifiers do we allow in GENDIRDEPS_FILTER 323a6589ab7SSimon J. GerratyGENDIRDEPS_FILTER_MASK += @CMNS 324a6589ab7SSimon J. GerratyDIRDEPS := ${DIRDEPS:${GENDIRDEPS_FILTER:UNno:M[${GENDIRDEPS_FILTER_MASK:O:u:ts}]*:ts:}:C,//+,/,g:O:u} 3257750ad47SMarcel Moolenaar 3267750ad47SMarcel Moolenaar.if ${DEBUG_GENDIRDEPS:Uno:@x@${RELDIR:M$x}@} != "" 327c2ec0b51SSimon J. Gerraty.info ${RELDIR}: M2D_OBJROOTS=${M2D_OBJROOTS} 32851c71d3eSSimon J. Gerraty.info ${RELDIR}: M2D_EXCLUDES=${M2D_EXCLUDES} 3297750ad47SMarcel Moolenaar.info ${RELDIR}: dir_list='${dir_list}' 33010ea6facSSimon J. Gerraty.info ${RELDIR}: dpadd_dir_list='${dpadd_dir_list}' 3317750ad47SMarcel Moolenaar.info ${RELDIR}: dirdep_list='${dirdep_list}' 3327750ad47SMarcel Moolenaar.info ${RELDIR}: qualdir_list='${qualdir_list}' 3337750ad47SMarcel Moolenaar.info ${RELDIR}: SKIP_GENDIRDEPS='${SKIP_GENDIRDEPS}' 3347750ad47SMarcel Moolenaar.info ${RELDIR}: GENDIRDEPS_FILTER='${GENDIRDEPS_FILTER}' 3357750ad47SMarcel Moolenaar.info ${RELDIR}: FORCE_DPADD='${DPADD}' 3367750ad47SMarcel Moolenaar.info ${RELDIR}: DIRDEPS='${DIRDEPS}' 3377750ad47SMarcel Moolenaar.endif 3387750ad47SMarcel Moolenaar 3397750ad47SMarcel Moolenaar# SRC_DIRDEPS is for checkout logic 3407750ad47SMarcel Moolenaarsrc_dirdep_list = \ 3417750ad47SMarcel Moolenaar ${dir_list:M${SRCTOP}/*:S,${SRCTOP}/,,} 3427750ad47SMarcel Moolenaar 3437750ad47SMarcel MoolenaarSRC_DIRDEPS = \ 3447750ad47SMarcel Moolenaar ${src_dirdep_list:N${RELDIR}:N${RELDIR}/*:C,(/h)/.*,,} 3457750ad47SMarcel Moolenaar 34610ea6facSSimon J. GerratySRC_DIRDEPS := ${SRC_DIRDEPS:${GENDIRDEPS_SRC_FILTER:UN/*:ts:}:C,//+,/,g:O:u} 3477750ad47SMarcel Moolenaar 3487750ad47SMarcel Moolenaar# if you want to capture SRC_DIRDEPS in .MAKE.DEPENDFILE put 3497750ad47SMarcel Moolenaar# SRC_DIRDEPS_FILE = ${_DEPENDFILE} 3507750ad47SMarcel Moolenaar# in local.gendirdeps.mk 3517750ad47SMarcel Moolenaar.if ${SRC_DIRDEPS_FILE:Uno:tl} != "no" 3527750ad47SMarcel MoolenaarECHO_SRC_DIRDEPS = echo 'SRC_DIRDEPS = \'; echo '${SRC_DIRDEPS:@d@ $d \\${.newline}@}'; echo; 3537750ad47SMarcel Moolenaar 3547750ad47SMarcel Moolenaar.if ${SRC_DIRDEPS_FILE:T} == ${_DEPENDFILE:T} 3557750ad47SMarcel Moolenaar_include_src_dirdeps = ${ECHO_SRC_DIRDEPS} 3567750ad47SMarcel Moolenaar.else 3577750ad47SMarcel Moolenaarall: ${SRC_DIRDEPS_FILE} 3587750ad47SMarcel Moolenaar.if !target(${SRC_DIRDEPS_FILE}) 3597750ad47SMarcel Moolenaar${SRC_DIRDEPS_FILE}: ${META_FILES} ${_this} ${META2DEPS} 3607750ad47SMarcel Moolenaar @(${ECHO_SRC_DIRDEPS}) > $@ 3617750ad47SMarcel Moolenaar.endif 3627750ad47SMarcel Moolenaar.endif 3637750ad47SMarcel Moolenaar.endif 3647750ad47SMarcel Moolenaar_include_src_dirdeps ?= 3657750ad47SMarcel Moolenaar 3667750ad47SMarcel Moolenaarall: ${_DEPENDFILE} 3677750ad47SMarcel Moolenaar 3687750ad47SMarcel Moolenaar# if this is going to exist it would be there by now 3697750ad47SMarcel Moolenaar.if !exists(.depend) 3707750ad47SMarcel MoolenaarCAT_DEPEND = /dev/null 3717750ad47SMarcel Moolenaar.endif 3727750ad47SMarcel MoolenaarCAT_DEPEND ?= .depend 3737750ad47SMarcel Moolenaar 3747750ad47SMarcel Moolenaar.if !empty(_DIRDEPS) && ${DIRDEPS} != ${_DIRDEPS} 3757750ad47SMarcel Moolenaar# we may have changed a filter 3767750ad47SMarcel Moolenaar.PHONY: ${_DEPENDFILE} 3777750ad47SMarcel Moolenaar.endif 3787750ad47SMarcel Moolenaar 379bf7aa99aSSimon J. Gerraty# set this to 'no' and we will not capture any 380bf7aa99aSSimon J. Gerraty# local depends 381960b77beSSimon J. GerratyLOCAL_DEPENDS_GUARD ?= _{.MAKE.LEVEL} > 0 382960b77beSSimon J. Gerraty 3837750ad47SMarcel Moolenaar# 'cat .depend' should suffice, but if we are mixing build modes 3847750ad47SMarcel Moolenaar# .depend may contain things we don't want. 3857750ad47SMarcel Moolenaar# The sed command at the end of the stream, allows for the filters 3867750ad47SMarcel Moolenaar# to output _{VAR} tokens which we will turn into proper ${VAR} references. 387be19d90bSSimon J. Gerraty${_DEPENDFILE}: .NOMETA ${CAT_DEPEND:M.depend} ${META_FILES:O:u:@m@${exists($m):?$m:}@} ${_this} ${META2DEPS} 388ccfb9654SSimon J. Gerraty @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ 3897750ad47SMarcel Moolenaar echo 'DIRDEPS = \'; \ 3907750ad47SMarcel Moolenaar echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 3917750ad47SMarcel Moolenaar ${_include_src_dirdeps} \ 3927750ad47SMarcel Moolenaar echo '.include <dirdeps.mk>'; \ 393bf7aa99aSSimon J. Gerraty [ "${LOCAL_DEPENDS_GUARD:[1]:tl}" != no ] || exit 0; \ 3947750ad47SMarcel Moolenaar echo; \ 395960b77beSSimon J. Gerraty echo '.if ${LOCAL_DEPENDS_GUARD}'; \ 3967750ad47SMarcel Moolenaar echo '# local dependencies - needed for -jN in clean tree'; \ 3977750ad47SMarcel Moolenaar [ -s ${CAT_DEPEND} ] && { grep : ${CAT_DEPEND} | grep -v '[/\\]'; }; \ 3987750ad47SMarcel Moolenaar echo '.endif' ) | sed 's,_\([{(]\),$$\1,g' > $@.new${.MAKE.PID} 3997750ad47SMarcel Moolenaar @${InstallNew}; InstallNew -s $@.new${.MAKE.PID} 4007750ad47SMarcel Moolenaar 4017750ad47SMarcel Moolenaar.endif # meta2deps failed 4027750ad47SMarcel Moolenaar.elif !empty(SUBDIR) 4037750ad47SMarcel Moolenaar 4047750ad47SMarcel MoolenaarDIRDEPS := ${SUBDIR:S,^,${RELDIR}/,:O:u} 4057750ad47SMarcel Moolenaar 4067750ad47SMarcel Moolenaarall: ${_DEPENDFILE} 4077750ad47SMarcel Moolenaar 408be19d90bSSimon J. Gerraty${_DEPENDFILE}: .NOMETA ${MAKEFILE} ${_this} 409ccfb9654SSimon J. Gerraty @(${GENDIRDEPS_HEADER} echo '# Autogenerated - do NOT edit!'; echo; \ 4107750ad47SMarcel Moolenaar echo 'DIRDEPS = \'; \ 4117750ad47SMarcel Moolenaar echo '${DIRDEPS:@d@ $d \\${.newline}@}'; echo; \ 4127750ad47SMarcel Moolenaar echo '.include <dirdeps.mk>'; \ 4137750ad47SMarcel Moolenaar echo ) | sed 's,_\([{(]\),$$\1,g' > $@.new 4147750ad47SMarcel Moolenaar @${InstallNew}; InstallNew $@.new 4157750ad47SMarcel Moolenaar 4167750ad47SMarcel Moolenaar.else 4177750ad47SMarcel Moolenaar 4187750ad47SMarcel Moolenaar# nothing to do 4197750ad47SMarcel Moolenaarall ${_DEPENDFILE}: 4207750ad47SMarcel Moolenaar 4217750ad47SMarcel Moolenaar.endif 4227750ad47SMarcel Moolenaar${_DEPENDFILE}: .PRECIOUS 423312809feSSimon J. Gerraty 424312809feSSimon J. Gerraty# don't waste time looking for ways to make .meta files 425312809feSSimon J. Gerraty.SUFFIXES: 426