git: a2b67d4a6e36 - main - Update dirdeps.mk to latest

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Mon, 29 Jul 2024 19:49:12 UTC
The branch main has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2b67d4a6e364586ae7180cc4696609e8960f955

commit a2b67d4a6e364586ae7180cc4696609e8960f955
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2024-07-29 19:48:38 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2024-07-29 19:48:56 +0000

    Update dirdeps.mk to latest
    
    Also add meta2deps.{py,sh} to FILES so they get installed/staged
    
    Reviewed by: stevek
---
 share/mk/Makefile                 |  2 ++
 share/mk/dirdeps.mk               | 51 +++++++++++++++++++++++++++++----------
 share/mk/local.dirdeps-targets.mk |  2 ++
 share/mk/meta.subdir.mk           |  3 +--
 4 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/share/mk/Makefile b/share/mk/Makefile
index 85b39a9c72ea..737b11d5a0f2 100644
--- a/share/mk/Makefile
+++ b/share/mk/Makefile
@@ -67,6 +67,8 @@ FILES=	\
 	meta.stage.mk \
 	meta.subdir.mk \
 	meta.sys.mk \
+	meta2deps.py \
+	meta2deps.sh \
 	${SRCTOP}/contrib/bmake/mk/posix.mk \
 	stage-install.sh \
 	sys.mk \
diff --git a/share/mk/dirdeps.mk b/share/mk/dirdeps.mk
index b3b34145e8e9..2a9d2ac92102 100644
--- a/share/mk/dirdeps.mk
+++ b/share/mk/dirdeps.mk
@@ -1,4 +1,4 @@
-# $Id: dirdeps.mk,v 1.166 2024/01/05 23:16:34 sjg Exp $
+# $Id: dirdeps.mk,v 1.170 2024/06/24 02:21:00 sjg Exp $
 
 # SPDX-License-Identifier: BSD-2-Clause
 #
@@ -139,7 +139,7 @@
 # DIRDEPS_EXPORT_VARS (DEP_EXPORT_VARS)
 #	It is discouraged, but sometimes necessary for a
 #	Makefile.depend file to influence the environment.
-#	Doing this is correctly (especially if using DIRDEPS_CACHE) is
+#	Doing this correctly (especially if using DIRDEPS_CACHE) is
 #	tricky so a Makefile.depend file can set DIRDEPS_EXPORT_VARS
 #	and dirdeps.mk will do the deed:
 #
@@ -581,6 +581,7 @@ BUILD_DIRDEPS_MAKEFILE ?= -f dirdeps.mk
 
 # these should generally do
 BUILD_DIRDEPS_MAKEFILE ?=
+BUILD_DIRDEPS_OVERRIDES ?=
 BUILD_DIRDEPS_TARGETS ?= ${.TARGETS}
 
 .if ${DIRDEPS_CACHE} != ${STATIC_DIRDEPS_CACHE:Uno} && ${DIRDEPS_CACHE:M${SRCTOP}/*} == ""
@@ -600,7 +601,9 @@ ${DIRDEPS_CACHE}:	.META .NOMETA_CMP
 	TARGET_SPEC=${TARGET_SPEC} \
 	MAKEFLAGS= ${DIRDEP_CACHE_MAKE:U${.MAKE}} -C ${_CURDIR} \
 	${BUILD_DIRDEPS_MAKEFILE} \
-	${BUILD_DIRDEPS_TARGETS} BUILD_DIRDEPS_CACHE=yes \
+	${BUILD_DIRDEPS_TARGETS} \
+	${BUILD_DIRDEPS_OVERRIDES} \
+	BUILD_DIRDEPS_CACHE=yes \
 	.MAKE.DEPENDFILE=.none \
 	${"${DEBUG_DIRDEPS:Nno}":?DEBUG_DIRDEPS='${DEBUG_DIRDEPS}':} \
 	${.MAKEFLAGS:tW:S,-D ,-D,g:tw:M*WITH*} \
@@ -692,9 +695,22 @@ DEP_DIRDEPS_FILTER = \
 	${DIRDEPS_FILTER.${DEP_TARGET_SPEC}:U} \
 	${TARGET_SPEC_VARS:@v@${DIRDEPS_FILTER.${DEP_$v}:U}@} \
 	${DIRDEPS_FILTER:U}
+
 .if empty(DEP_DIRDEPS_FILTER)
 # something harmless
-DEP_DIRDEPS_FILTER = U
+DEP_DIRDEPS_FILTER = u
+.endif
+
+# this is applied after we have computed build dirs
+# so everything is fully qualified and starts with ${SRCTOP}/
+DEP_DIRDEPS_BUILD_DIR_FILTER = \
+	${DIRDEPS_BUILD_DIR_FILTER.${DEP_TARGET_SPEC}:U} \
+	${TARGET_SPEC_VARS:@v@${DIRDEPS_BUILD_DIR_FILTER.${DEP_$v}:U}@} \
+	${DIRDEPS_BUILD_DIR_FILTER:U}
+
+.if empty(DEP_DIRDEPS_BUILD_DIR_FILTER)
+# something harmless
+DEP_DIRDEPS_BUILD_DIR_FILTER = u
 .endif
 
 # this is what we start with
@@ -714,6 +730,7 @@ __qual_depdirs += ${__hostdpadd}
 
 .if ${_debug_reldir}
 .info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:}
+.info DEP_DIRDEPS_BUILD_DIR_FILTER=${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:}
 .info depdirs=${__depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .info qualified=${__qual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
@@ -733,7 +750,8 @@ _build_dirs += \
 # make sure we do not mess with qualifying "host" entries
 _build_dirs := ${_build_dirs:M*.host*:${M_dep_qual_fixes.host:ts:}} \
 	${_build_dirs:N*.host*:${M_dep_qual_fixes:ts:}}
-_build_dirs := ${_build_dirs:O:u}
+# some filters can only be applied now
+_build_dirs := ${_build_dirs:${DEP_DIRDEPS_BUILD_DIR_FILTER:ts:}:O:u}
 .if ${_debug_reldir}
 .info _build_dirs=${_build_dirs:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .endif
@@ -743,6 +761,11 @@ _build_dirs := ${_build_dirs:O:u}
 _build_all_dirs += ${_build_dirs} ${_build_xtra_dirs}
 _build_all_dirs := ${_build_all_dirs:O:u}
 
+# we prefer DIRDEPS_EXPORT_VARS
+.if empty(DIRDEPS_EXPORT_VARS) && !empty(DEP_EXPORT_VARS)
+DIRDEPS_EXPORT_VARS = ${DEP_EXPORT_VARS}
+.endif
+
 # Normally if doing make -V something,
 # we do not want to waste time chasing DIRDEPS
 # but if we want to count the number of Makefile.depend* read, we do.
@@ -754,10 +777,9 @@ _cache_script = echo '\# ${DEP_RELDIR}.${DEP_TARGET_SPEC}';
 # guard against _new_dirdeps being too big for a single command line
 _new_dirdeps := ${_build_all_dirs:@x@${target($x):?:$x}@:S,^${SRCTOP}/,,}
 _cache_xtra_deps := ${_build_xtra_dirs:S,^${SRCTOP}/,,}
-.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
+.if !empty(DIRDEPS_EXPORT_VARS)
 # Discouraged, but there are always exceptions.
 # Handle it here rather than explain how.
-DIRDEPS_EXPORT_VARS ?= ${DEP_EXPORT_VARS}
 _cache_xvars := echo; ${DIRDEPS_EXPORT_VARS:@v@echo '$v = ${$v}';@} echo '.export ${DIRDEPS_EXPORT_VARS}'; echo;
 _cache_script += ${_cache_xvars}
 .endif
@@ -771,12 +793,6 @@ ${_build_all_dirs}:	_DIRDEP_USE
 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .endif
 
-.if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
-.export ${DIRDEPS_EXPORT_VARS} ${DEP_EXPORT_VARS}
-DIRDEPS_EXPORT_VARS =
-DEP_EXPORT_VARS =
-.endif
-
 # this builds the dependency graph
 .for m in ${_machines}
 .if ${BUILD_DIRDEPS_CACHE} == "yes" && !empty(_build_dirs)
@@ -832,6 +848,15 @@ ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
 
 .endif
 
+.if !empty(DIRDEPS_EXPORT_VARS)
+.if ${BUILD_DIRDEPS_CACHE} == "no"
+.export ${DIRDEPS_EXPORT_VARS}
+.endif
+# Reset these, we are done with them for this iteration.
+DIRDEPS_EXPORT_VARS =
+DEP_EXPORT_VARS =
+.endif
+
 # Now find more dependencies - and recurse.
 .for d in ${_build_all_dirs}
 .if !target(_dirdeps_checked.$d)
diff --git a/share/mk/local.dirdeps-targets.mk b/share/mk/local.dirdeps-targets.mk
index f07708c2c551..00346cddeeee 100644
--- a/share/mk/local.dirdeps-targets.mk
+++ b/share/mk/local.dirdeps-targets.mk
@@ -1 +1,3 @@
 .-include <${.PARSEFILE:S/local/site/}>
+
+DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo targets/packages
diff --git a/share/mk/meta.subdir.mk b/share/mk/meta.subdir.mk
index e2ece24515a4..aee8a1a9a39b 100644
--- a/share/mk/meta.subdir.mk
+++ b/share/mk/meta.subdir.mk
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: BSD-2-Clause
 #
-# $Id: meta.subdir.mk,v 1.14 2024/02/17 17:26:57 sjg Exp $
+# $Id: meta.subdir.mk,v 1.15 2024/04/19 15:10:22 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
@@ -70,7 +70,6 @@ DIRDEPS := ${DIRDEPS:S,^./,,:S,/./,/,g:${SUBDIRDEPS_FILTER:Uu}}
 # dirdeps.mk will compute some interesting combinations.
 .undef ALL_MACHINES
 
-DEP_RELDIR = ${RELDIR}
 .include <dirdeps.mk>
 .endif
 .endif