git: e2ed7ee02f6b - main - bsd.progs.mk: Fix incremental META_MODE for prog sources

From: Bryan Drewery <bdrewery_at_FreeBSD.org>
Date: Mon, 09 Mar 2026 14:42:17 UTC
The branch main has been updated by bdrewery:

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

commit e2ed7ee02f6bda705a7c8df3c512c6a43db56830
Author:     Bryan Drewery <bdrewery@FreeBSD.org>
AuthorDate: 2026-03-07 16:38:47 +0000
Commit:     Bryan Drewery <bdrewery@FreeBSD.org>
CommitDate: 2026-03-09 14:38:40 +0000

    bsd.progs.mk: Fix incremental META_MODE for prog sources
    
    This fixes recursed builds not having meta mode enabled for them which
    disabled dependency and and command change tracking.  We only want common
    objects marked .NOMETA when recursing, not non-common objects.  The
    common code expects _PROGS_COMMON_SRCS does not contain the prog source
    or else it will be marked .NOMETA.
    
    Add comments explaining the intent and cases being covered.
    
    Fixes:  4ea5e107b1 ("<bsd.progs.mk>: Allow using SRCS for common sources")
    Differential Revision:  https://reviews.freebsd.org/D55711
    Reviewed by:    vexeduxr, sjg
---
 share/mk/bsd.progs.mk | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/share/mk/bsd.progs.mk b/share/mk/bsd.progs.mk
index 007e8a843944..2c6f6df33279 100644
--- a/share/mk/bsd.progs.mk
+++ b/share/mk/bsd.progs.mk
@@ -14,6 +14,7 @@
 # we really only use PROGS below...
 PROGS += ${PROGS_CXX}
 
+_save_srcs:=	${SRCS:U}
 .if defined(PROG)
 # just one of many
 PROG_OVERRIDE_VARS +=	BINDIR BINGRP BINOWN BINMODE CSTD CXXSTD DPSRCS MAN \
@@ -91,8 +92,29 @@ $v =
 # Find common sources among the PROGS to depend on them before building
 # anything.  This allows parallelization without them each fighting over
 # the same objects.
-_PROGS_COMMON_SRCS= ${DPSRCS} ${SRCS}
-_PROGS_ALL_SRCS= ${SRCS}
+#
+# There are 3 cases to consider.
+# 1. No common sources.
+#         SRCS=
+#         SRCS.prog1= prog1.c
+#         SRCS.prog2= prog2.c
+# 2. Common sources in all SRCS.$prog.
+#         SRCS=
+#         SRCS.prog1= prog1.c common.c
+#         SRCS.prog2= prog2.c common.c
+# 3. Common sources in SRCS.
+#         SRCS= common.c
+#         SRCS.prog1= prog1.c
+#         SRCS.prog2= prog2.c
+# The intent is:
+# a. Only build common objects in the parent make before recursing.
+# b. When recursing only build non-common objects.
+# c. When recursing disable meta mode for common objects so they are not
+#    inspected.
+# _PROGS_COMMON_SRCS is expected to only contain common sources both
+# in the parent and when recursing.
+_PROGS_COMMON_SRCS:= ${DPSRCS} ${_save_srcs}
+_PROGS_ALL_SRCS:= ${_save_srcs}
 .for p in ${PROGS}
 .for s in ${SRCS.${p}}
 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
@@ -115,6 +137,7 @@ _PROGS_COMMON_OBJS+=	${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/
 ${_PROGS_COMMON_OBJS}: .NOMETA
 .endif
 .endif
+.undef _save_srcs
 
 .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
 # tell progs.mk we might want to install things