git: f974ced38a4a - main - Update dirdeps.mk et al

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Thu, 14 Mar 2024 05:51:26 UTC
The branch main has been updated by sjg:

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

commit f974ced38a4a264bb78b4f067b44bf587f7887db
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2024-03-14 05:51:08 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2024-03-14 05:51:08 +0000

    Update dirdeps.mk et al
    
    bmake-20240309 includes updates to dirdeps and meta mode makefiles
---
 share/mk/dirdeps-options.mk |  4 +++-
 share/mk/dirdeps-targets.mk |  7 ++++++-
 share/mk/dirdeps.mk         | 37 +++++++++++++++++++++++++------------
 share/mk/local.autodep.mk   |  4 ----
 share/mk/meta.autodep.mk    | 16 ++++++++++------
 share/mk/meta.stage.mk      |  6 ++++--
 share/mk/meta.subdir.mk     |  4 +++-
 share/mk/meta.sys.mk        | 12 +++++++++---
 share/mk/meta2deps.py       | 15 +++++++++++----
 share/mk/meta2deps.sh       |  8 ++++----
 share/mk/sys.dirdeps.mk     |  9 ++++++---
 11 files changed, 81 insertions(+), 41 deletions(-)

diff --git a/share/mk/dirdeps-options.mk b/share/mk/dirdeps-options.mk
index 9a97615bbeb8..e12dcec40ac7 100644
--- a/share/mk/dirdeps-options.mk
+++ b/share/mk/dirdeps-options.mk
@@ -1,4 +1,6 @@
-# $Id: dirdeps-options.mk,v 1.21 2022/09/06 22:18:45 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: dirdeps-options.mk,v 1.22 2024/02/17 17:26:57 sjg Exp $
 #
 #	@(#) Copyright (c) 2018-2022, Simon J. Gerraty
 #
diff --git a/share/mk/dirdeps-targets.mk b/share/mk/dirdeps-targets.mk
index 821ae50e3ffa..9e3fb814fada 100644
--- a/share/mk/dirdeps-targets.mk
+++ b/share/mk/dirdeps-targets.mk
@@ -1,5 +1,7 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
 # RCSid:
-#       $Id: dirdeps-targets.mk,v 1.25 2023/05/11 05:07:28 sjg Exp $
+#       $Id: dirdeps-targets.mk,v 1.27 2024/02/25 19:12:13 sjg Exp $
 #
 #       @(#) Copyright (c) 2019-2020 Simon J. Gerraty
 #
@@ -40,6 +42,9 @@
 # pickup customizations
 .-include <local.dirdeps-targets.mk>
 
+# this is what we are here for
+.MAIN: dirdeps
+
 # for DIRDEPS_BUILD this is how we prime the pump
 # include . to allow any directory to work as a target
 DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo
diff --git a/share/mk/dirdeps.mk b/share/mk/dirdeps.mk
index 2cf62bed3d9e..b3b34145e8e9 100644
--- a/share/mk/dirdeps.mk
+++ b/share/mk/dirdeps.mk
@@ -1,4 +1,4 @@
-# $Id: dirdeps.mk,v 1.162 2023/05/15 17:37:46 sjg Exp $
+# $Id: dirdeps.mk,v 1.166 2024/01/05 23:16:34 sjg Exp $
 
 # SPDX-License-Identifier: BSD-2-Clause
 #
@@ -155,7 +155,7 @@
 #	if any test fails, but without the risk of introducing
 #	circular dependencies.
 
-now_utc ?= ${%s:L:gmtime}
+now_utc ?= ${%s:L:localtime}
 .if !defined(start_utc)
 start_utc := ${now_utc}
 .endif
@@ -415,6 +415,8 @@ DIRDEPS_FILTER += M${_DEP_RELDIR}
 # this is what we run below
 DIRDEP_MAKE ?= ${.MAKE}
 DIRDEP_DIR ?= ${.TARGET:R}
+# we normally want the default target
+DIRDEP_TARGETS ?=
 
 # if you want us to report load averages during build
 # DIRDEP_USE_PRELUDE += ${DIRDEP_LOADAVG_REPORT};
@@ -442,7 +444,7 @@ _DIRDEP_USE:	.USE .MAKE
 		MACHINE_ARCH= NO_SUBDIR=1 ${DIRDEP_USE_ENV} \
 		TARGET_SPEC=${.TARGET:E} \
 		MACHINE=${.TARGET:E} \
-		${DIRDEP_MAKE} -C ${DIRDEP_DIR} || exit 1; \
+		${DIRDEP_MAKE} -C ${DIRDEP_DIR} ${DIRDEP_TARGETS} || exit 1; \
 		break; \
 	done
 
@@ -680,7 +682,7 @@ _build_dirs += ${_machines:@m@${_CURDIR}.$m@}
 
 .if ${_debug_reldir}
 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: nDIRDEPS=${DIRDEPS:[#]}
-.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS='${DIRDEPS}'
+.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: DIRDEPS=${DIRDEPS:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: _machines='${_machines}'
 .endif
 
@@ -712,9 +714,9 @@ __qual_depdirs += ${__hostdpadd}
 
 .if ${_debug_reldir}
 .info DEP_DIRDEPS_FILTER=${DEP_DIRDEPS_FILTER:ts:}
-.info depdirs=${__depdirs:S,^${SRCTOP}/,,}
-.info qualified=${__qual_depdirs:S,^${SRCTOP}/,,}
-.info unqualified=${__unqual_depdirs:S,^${SRCTOP}/,,}
+.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:}}
 .endif
 
 # _build_dirs is what we will feed to _DIRDEP_USE
@@ -726,14 +728,14 @@ _build_dirs += \
 
 # qualify everything now
 .if ${_debug_reldir}
-.info _build_dirs=${_build_dirs}
+.info _build_dirs=${_build_dirs:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .endif
 # 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}
 .if ${_debug_reldir}
-.info _build_dirs=${_build_dirs}
+.info _build_dirs=${_build_dirs:${DEBUG_DIRDEPS_LIST_FILTER:U:N/:ts:}}
 .endif
 
 .endif				# empty DIRDEPS
@@ -752,7 +754,6 @@ _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}/,,}
-.export _cache_xtra_deps _new_dirdeps
 .if !empty(DIRDEPS_EXPORT_VARS) || !empty(DEP_EXPORT_VARS)
 # Discouraged, but there are always exceptions.
 # Handle it here rather than explain how.
@@ -767,7 +768,7 @@ dirdeps: ${_build_all_dirs}
 ${_build_all_dirs}:	_DIRDEP_USE
 
 .if ${_debug_reldir}
-.info ${DEP_RELDIR}.${DEP_TARGET_SPEC}: needs: ${_build_dirs:S,^${SRCTOP}/,,}
+.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)
@@ -802,15 +803,27 @@ ${_this_dir}.$m: ${_build_dirs:M*.$q}
 .if ${BUILD_DIRDEPS_CACHE} == "yes"
 .if !empty(_build_dirs)
 _cache_deps += ${_build_dirs:M*.$m:N${_this_dir}.$m:S,^${SRCTOP}/,,}
+# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only
+.if ${MAKE_VERSION} < 20240105
 .if !empty(_cache_deps)
 .export _cache_deps
 _cache_script += for x in $$_cache_deps; do echo "	_{SRCTOP}/$$x \\"; done;
 .endif
-# anything in _{build,env}_xtra_dirs is hooked to dirdeps: only
+.export _cache_xtra_deps _new_dirdeps
 x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
 	echo; echo 'dirdeps: ${_this_dir}.$m \'; \
 	for x in $$_cache_xtra_deps; do echo "	_{SRCTOP}/$$x \\"; done; \
 	echo; for x in $$_new_dirdeps; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3
+.else
+# we do not have the same limits on command lines
+.if !empty(_cache_deps)
+_cache_script += for x in ${_cache_deps}; do echo "	_{SRCTOP}/$$x \\"; done;
+.endif
+x!= echo; { echo; ${_cache_script} echo; echo '${_this_dir}.$m: $${DIRDEPS.${_this_dir}.$m}'; \
+	echo; echo 'dirdeps: ${_this_dir}.$m \'; \
+	for x in ${_cache_xtra_deps}; do echo "	_{SRCTOP}/$$x \\"; done; \
+	echo; for x in ${_new_dirdeps}; do echo "_{SRCTOP}/$$x: _DIRDEP_USE"; done; } >&3
+.endif
 .endif
 .else
 ${_this_dir}.$m: ${_build_dirs:M*.$m:N${_this_dir}.$m}
diff --git a/share/mk/local.autodep.mk b/share/mk/local.autodep.mk
index bc5bfd3e75db..f36fe6b11655 100644
--- a/share/mk/local.autodep.mk
+++ b/share/mk/local.autodep.mk
@@ -7,10 +7,6 @@ UPDATE_DEPENDFILE= no
 .endif
 .endif
 
-NOSSPPICO?= .nossppico
-PIEO?= .pieo
-OBJ_EXTENSIONS+= ${NOSSPPICO} ${PIEO}
-
 CLEANFILES+= .depend
 
 # handy for debugging
diff --git a/share/mk/meta.autodep.mk b/share/mk/meta.autodep.mk
index 6785d2ebf874..9824570ecc43 100644
--- a/share/mk/meta.autodep.mk
+++ b/share/mk/meta.autodep.mk
@@ -1,4 +1,6 @@
-# $Id: meta.autodep.mk,v 1.59 2023/08/19 17:35:32 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: meta.autodep.mk,v 1.62 2024/02/17 17:26:57 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
@@ -24,16 +26,16 @@ PICO?= .pico
 
 .if defined(SRCS)
 .if ${MAKE_VERSION:U0} >= 20211212
-OBJ_EXTENSIONS += ${.SUFFIXES:M*o}
+OBJ_SUFFIXES += ${.SUFFIXES:M*o}
 .else
 # it would be nice to be able to query .SUFFIXES
-OBJ_EXTENSIONS += .o .po .lo ${PICO}
+OBJ_SUFFIXES += .o .po .lo ${PICO}
 .endif
 
 # explicit dependencies help short-circuit .SUFFIX searches
 SRCS_DEP_FILTER+= N*.[hly]
 .for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}}
-.for e in ${OBJ_EXTENSIONS:O:u}
+.for e in ${OBJ_SUFFIXES:O:u}
 .if !target(${s:T:R}$e)
 ${s:T:R}$e: $s
 .endif
@@ -190,7 +192,7 @@ DEPEND_SUFFIXES += .c .h .cpp .hpp .cxx .hxx .cc .hh
 	@case "${.MAKE.META.FILES:T:M*.po.*}" in \
 	*.po.*) mv $@.${.MAKE.PID} $@;; \
 	*) { cat $@.${.MAKE.PID}; \
-	sed ${OBJ_EXTENSIONS:N.o:N.po:@o@-e 's,\$o:,.o:,'@} \
+	sed ${OBJ_SUFFIXES:N.o:N.po:@o@-e 's,\$o:,.o:,'@} \
 		-e 's,\.o:,.po:,' $@.${.MAKE.PID}; } | sort -u > $@; \
 	rm -f $@.${.MAKE.PID};; \
 	esac
@@ -305,7 +307,7 @@ ${_DEPENDFILE}: .PRECIOUS
 CLEANFILES += *.meta filemon.* *.db
 
 # these make it easy to gather some stats
-now_utc = ${%s:L:localtime}
+now_utc ?= ${%s:L:localtime}
 start_utc := ${now_utc}
 
 meta_stats= meta=${empty(.MAKE.META.FILES):?0:${.MAKE.META.FILES:[#]}} \
@@ -331,4 +333,6 @@ _reldir_failed: .NOMETA
 .ERROR: _reldir_failed
 .endif
 
+.-include <ccm.dep.mk>
+
 .endif
diff --git a/share/mk/meta.stage.mk b/share/mk/meta.stage.mk
index 168e46d22a82..345df6aae16b 100644
--- a/share/mk/meta.stage.mk
+++ b/share/mk/meta.stage.mk
@@ -1,4 +1,6 @@
-# $Id: meta.stage.mk,v 1.67 2023/04/17 01:22:10 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: meta.stage.mk,v 1.69 2024/02/17 17:26:57 sjg Exp $
 #
 #	@(#) Copyright (c) 2011-2017, Simon J. Gerraty
 #
@@ -212,7 +214,7 @@ stage_files.$s:	.dirdep
 STAGE_FILES ?= ${.ALLSRC:N.dirdep:Nstage_*}
 stage_files:	.dirdep
 .endif
-	@${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O}
+	@${STAGE_FILE_SCRIPT}; StageFiles ${FLAGS.$@:U} ${STAGE_FILES_DIR.$s:U${STAGE_DIR.$s}:${STAGE_DIR_FILTER}} ${STAGE_FILES.$s:O}
 	@touch $@
 .endif
 .endif
diff --git a/share/mk/meta.subdir.mk b/share/mk/meta.subdir.mk
index d9caae4edbcc..e2ece24515a4 100644
--- a/share/mk/meta.subdir.mk
+++ b/share/mk/meta.subdir.mk
@@ -1,4 +1,6 @@
-# $Id: meta.subdir.mk,v 1.13 2021/01/05 22:24:37 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: meta.subdir.mk,v 1.14 2024/02/17 17:26:57 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010, Simon J. Gerraty
diff --git a/share/mk/meta.sys.mk b/share/mk/meta.sys.mk
index ba213dd49da4..6e4216ab5383 100644
--- a/share/mk/meta.sys.mk
+++ b/share/mk/meta.sys.mk
@@ -1,4 +1,6 @@
-# $Id: meta.sys.mk,v 1.51 2023/05/11 20:05:32 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: meta.sys.mk,v 1.54 2024/03/10 15:53:51 sjg Exp $
 
 #
 #	@(#) Copyright (c) 2010-2023, Simon J. Gerraty
@@ -82,6 +84,7 @@ META2DEPS := ${META2DEPS}
 
 MAKE_PRINT_VAR_ON_ERROR += \
 	.ERROR_TARGET \
+	.ERROR_EXIT \
 	.ERROR_META_FILE \
 	.MAKE.LEVEL \
 	MAKEFILE \
@@ -98,10 +101,13 @@ SB = ${SRCTOP:H}
 ERROR_LOGDIR ?= ${SB}/error
 meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log
 
-# we are not interested in make telling us a failure happened elsewhere
 .ERROR: _metaError
+# We are interested here in the target(s) that caused the build to fail.
+# We want to ignore targets that were "aborted" due to failure
+# elsewhere per the message below or a sub-make may just exit 6.
 _metaError: .NOMETA .NOTMAIN
-	-@[ "${.ERROR_META_FILE}" ] && { \
+	-@[ ${.ERROR_EXIT:U0} = 6 ] && exit 0; \
+	[ "${.ERROR_META_FILE}" ] && { \
 	grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \
 	mkdir -p ${meta_error_log:H}; \
 	cp ${.ERROR_META_FILE} ${meta_error_log}; \
diff --git a/share/mk/meta2deps.py b/share/mk/meta2deps.py
index 334a008a2ab5..f188d0f01de8 100755
--- a/share/mk/meta2deps.py
+++ b/share/mk/meta2deps.py
@@ -36,8 +36,10 @@ We only pay attention to a subset of the information in the
 """
 
 """
+SPDX-License-Identifier: BSD-2-Clause
+
 RCSid:
-	$Id: meta2deps.py,v 1.45 2023/01/18 01:35:24 sjg Exp $
+	$Id: meta2deps.py,v 1.47 2024/02/17 17:26:57 sjg Exp $
 
 	Copyright (c) 2011-2020, Simon J. Gerraty
 	Copyright (c) 2011-2017, Juniper Networks, Inc.
@@ -74,8 +76,10 @@ import stat
 def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
     """
     Return an absolute path, resolving via cwd or last_dir if needed.
+
+    Cleanup any leading ``./`` and trailing ``/.``
     """
-    if path.endswith('/.'):
+    while path.endswith('/.'):
         path = path[0:-2]
     if len(path) > 0 and path[0] == '/':
         if os.path.exists(path):
@@ -86,7 +90,9 @@ def resolve(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
     if path == '.':
         return cwd
     if path.startswith('./'):
-        return cwd + path[1:]
+        while path.startswith('./'):
+            path = path[1:]
+        return cwd + path
     if last_dir == cwd:
         last_dir = None
     for d in [last_dir, cwd]:
@@ -144,6 +150,7 @@ def abspath(path, cwd, last_dir=None, debug=0, debug_out=sys.stderr):
         return None
     if (path.find('/') < 0 or
         path.find('./') > 0 or
+        path.find('/../') > 0 or
         path.endswith('/..')):
         path = cleanpath(path)
     return path
@@ -197,7 +204,7 @@ class MetaFile:
 
     def __init__(self, name, conf={}):
         """if name is set we will parse it now.
-        conf can have the following keys:
+        conf can have the follwing keys:
 
         SRCTOPS list of tops of the src tree(s).
 
diff --git a/share/mk/meta2deps.sh b/share/mk/meta2deps.sh
index 56367e0105f4..4c1b674f7b63 100755
--- a/share/mk/meta2deps.sh
+++ b/share/mk/meta2deps.sh
@@ -49,10 +49,8 @@
 #	The output, is a set of absolute paths with "SB" like:
 #.nf
 #
-#	$SB/obj-i386/bsd/gnu/lib/csu
-#	$SB/obj-i386/bsd/gnu/lib/libgcc
 #	$SB/obj-i386/bsd/include
-#	$SB/obj-i386/bsd/lib/csu/i386-elf
+#	$SB/obj-i386/bsd/lib/csu/i386
 #	$SB/obj-i386/bsd/lib/libc
 #	$SB/src/bsd/include
 #	$SB/src/bsd/sys/i386/include
@@ -77,8 +75,10 @@
 
 
 # RCSid:
-#	$Id: meta2deps.sh,v 1.20 2023/01/18 01:35:24 sjg Exp $
+#	$Id: meta2deps.sh,v 1.21 2024/02/17 17:26:57 sjg Exp $
 
+# SPDX-License-Identifier: BSD-2-Clause
+#
 # Copyright (c) 2010-2013, Juniper Networks, Inc.
 # All rights reserved.
 #
diff --git a/share/mk/sys.dirdeps.mk b/share/mk/sys.dirdeps.mk
index a3d22d7c2e82..1e3363c22339 100644
--- a/share/mk/sys.dirdeps.mk
+++ b/share/mk/sys.dirdeps.mk
@@ -1,4 +1,6 @@
-# $Id: sys.dirdeps.mk,v 1.12 2023/05/14 16:16:03 sjg Exp $
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# $Id: sys.dirdeps.mk,v 1.14 2024/02/25 19:12:13 sjg Exp $
 #
 #	@(#) Copyright (c) 2012-2023, Simon J. Gerraty
 #
@@ -31,9 +33,10 @@ _PARSEDIR ?= ${.PARSEDIR:tA}
 
 .if ${.MAKE.LEVEL} == 0
 # make sure dirdeps target exists and do it first
+# init.mk will set .MAIN to 'dirdeps' if appropriate
+# as will dirdeps-targets.mk for top-level builds.
+# This allows a Makefile to have more control.
 dirdeps:
-# first .MAIN is what counts
-.MAIN: dirdeps
 .NOPATH: dirdeps
 all: dirdeps .WAIT
 .endif