git: 65d1b80dc114 - stable/12 - Add various CFLAGS/LDADD overrides for the output target file.

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

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

commit 65d1b80dc1140b5baf0eba803d76dbaf4c273838
Author:     Bryan Drewery <bdrewery@FreeBSD.org>
AuthorDate: 2019-06-15 17:08:24 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-25 11:51:17 +0000

    Add various CFLAGS/LDADD overrides for the output target file.
    
    Sponsored by:   DellEMC
    
    (cherry picked from commit 48da57b47ff1425360f396ea799e05e939d1e1ce)
---
 share/mk/bsd.README | 17 +++++++++++++++++
 share/mk/bsd.sys.mk |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/share/mk/bsd.README b/share/mk/bsd.README
index c4db43ea5699..ef93c55f73fc 100644
--- a/share/mk/bsd.README
+++ b/share/mk/bsd.README
@@ -125,10 +125,16 @@ The following variables are common:
 
 AFLAGS.${SRC}
 		Flags dependent on source file name.
+AFLAGS.${TARGET}
+		Flags dependent on output file name.
 ACFLAGS.${SRC}
 		Flags dependent on source file name.
+ACFLAGS.${TARGET}
+		Flags dependent on output file name.
 CFLAGS.${SRC}
 		Flags dependent on source file name.
+CFLAGS.${TARGET}
+		Flags dependent on output file name.
 CFLAGS.${COMPILER_TYPE}
 		Flags dependent on compiler added to CFLAGS.
 CFLAGS.${MACHINE_ARCH}
@@ -142,6 +148,8 @@ CXXFLAGS.${MACHINE_ARCH}
 		Architectural flags added to CXXFLAGS.
 CXXFLAGS.${SRC}
 		Flags dependent on source file name.
+CXXFLAGS.${TARGET}
+		Flags dependent on output file name.
 COMPILER_FEATURES
 		A list of features that the compiler supports. Zero or
 		more of:
@@ -336,14 +344,23 @@ LDADD		Additional loader objects.  Usually used for libraries.
 
 			LDADD=-lutil -lcompat
 
+LDADD.${TAREGT}
+		Loader objects dependent on output file name.
+
 LDFLAGS		Additional loader flags. Passed to the loader via CC,
 		since that's used to link programs as well, so loader
 		specific flags need to be prefixed with -Wl, to work.
 
+LDFLAGS.${TARGET}
+		Flags dependent on output file name.
+
 LIBADD		Additional libraries.  This is for base system libraries
 		and is only valid inside of the /usr/src tree.
 		Use LIBADD=name instead of LDADD=-lname.
 
+LIBADD.${TARGET}
+		Libraries dependent on output file name.
+
 LINKS		The list of binary links; should be full pathnames, the
 		linked-to file coming first, followed by the linked
 		file.  The files are hard-linked.  For example, to link
diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk
index e787d4f439df..5e9b8ed51b5a 100644
--- a/share/mk/bsd.sys.mk
+++ b/share/mk/bsd.sys.mk
@@ -253,6 +253,7 @@ 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
@@ -261,11 +262,18 @@ CFLAGS+=	 ${CFLAGS.${COMPILER_TYPE}}
 CXXFLAGS+=	 ${CXXFLAGS.${COMPILER_TYPE}}
 
 AFLAGS+=	${AFLAGS.${.IMPSRC:T}}
+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}}
+LDFLAGS+=	${LDFLAGS.${.TARGET:T}}
+LDADD+=		${LDADD.${.TARGET:T}}
+LIBADD+=	${LIBADD.${.TARGET:T}}
 
 .if defined(SRCTOP)
 # Prevent rebuilding during install to support read-only objdirs.