git: 14134e64f362 - stable/12 - Follow-up r349065: Fix .TARGET flag ambiguity with PROGS which broke MK_TESTS.

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sat, 25 Dec 2021 11:55:44 UTC
The branch stable/12 has been updated by dim:

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

commit 14134e64f3620c72c105928f31d05f5e81f272e7
Author:     Bryan Drewery <bdrewery@FreeBSD.org>
AuthorDate: 2019-06-19 19:19:37 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-25 11:51:18 +0000

    Follow-up r349065: Fix .TARGET flag ambiguity with PROGS which broke MK_TESTS.
    
    X-MFC-With:     r349065
    Sponsored by:   DellEMC
    
    (cherry picked from commit 8e0c373903c0ea70ea22e650a24a92d2a0744bd8)
---
 share/mk/bsd.sys.mk | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
index 5e9b8ed51b5a..375df956b4fd 100644
--- a/share/mk/bsd.sys.mk
+++ b/share/mk/bsd.sys.mk
@@ -253,7 +253,6 @@ DEBUG_FILES_CFLAGS?= -g
 .if ${MK_WARNS} != "no"
 CFLAGS+=	${CWARNFLAGS:M*} ${CWARNFLAGS.${COMPILER_TYPE}}
 CFLAGS+=	${CWARNFLAGS.${.IMPSRC:T}}
-CFLAGS+=	${CWARNFLAGS.${.TARGET:T}}
 CXXFLAGS+=	${CXXWARNFLAGS:M*} ${CXXWARNFLAGS.${COMPILER_TYPE}}
 CXXFLAGS+=	${CXXWARNFLAGS.${.IMPSRC:T}}
 .endif
@@ -266,14 +265,23 @@ AFLAGS+=	${AFLAGS.${.TARGET:T}}
 ACFLAGS+=	${ACFLAGS.${.IMPSRC:T}}
 ACFLAGS+=	${ACFLAGS.${.TARGET:T}}
 CFLAGS+=	${CFLAGS.${.IMPSRC:T}}
-CFLAGS+=	${CFLAGS.${.TARGET:T}}
 CXXFLAGS+=	${CXXFLAGS.${.IMPSRC:T}}
-CXXFLAGS+=	${CXXFLAGS.${.TARGET:T}}
 
 LDFLAGS+=	${LDFLAGS.${LINKER_TYPE}}
+
+# Only allow .TARGET when not using PROGS as it has the same syntax
+# per PROG which is ambiguous with this syntax. This is only needed
+# for PROG_VARS vars.
+.if !defined(_RECURSING_PROGS)
+.if ${MK_WARNS} != "no"
+CFLAGS+=	${CWARNFLAGS.${.TARGET:T}}
+.endif
+CFLAGS+=	${CFLAGS.${.TARGET:T}}
+CXXFLAGS+=	${CXXFLAGS.${.TARGET:T}}
 LDFLAGS+=	${LDFLAGS.${.TARGET:T}}
 LDADD+=		${LDADD.${.TARGET:T}}
 LIBADD+=	${LIBADD.${.TARGET:T}}
+.endif
 
 .if defined(SRCTOP)
 # Prevent rebuilding during install to support read-only objdirs.