git: 8fad2cda93c7 - main - bsd.compat.mk: Provide new CPP and sub-make variables

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Sun, 09 Jul 2023 17:52:00 UTC
The branch main has been updated by jrtc27:

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

commit 8fad2cda93c7930b01f25a2160e5c433085f13e3
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-07-09 17:47:42 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-07-09 17:47:42 +0000

    bsd.compat.mk: Provide new CPP and sub-make variables
    
    Currently the only way to detect for a libcompat build is to consult
    whether COMPAT_32BIT is defined (or equivalent, for downstreams with
    other libcompats or past releases with libsoft as COMPAT_SOFTFP). There
    are two issues with this:
    
    1. COMPAT_32BIT is a new naming scheme that doesn't match the libcompat
       name, which is unnecessary deviation.
    2. When multiple libcompats exist, everywhere that needs to detect a
       libcompat must check each variable in turn, despite the fact that it
       normally just wants to know if this is a libcompat build and perhaps
       what ${LIBCOMPAT} and/or ${libcompat} are for it.
    
    As a result, far too many places in the tree need to know about the set
    of possible libcompats.
    
    Instead, introduce two new CPP and sub-make variables, COMPAT_LIBCOMPAT
    and COMPAT_libcompat, which give the values for ${LIBCOMPAT} and
    ${libcompat} respectively, so that uses can be made parameterised. For
    when code really does need to know the specific libcompat, Makefiles can
    perform a string comparison, but the C preprocessor cannot, so introduce
    an additional CPP-only COMPAT_LIB${LIBCOMPAT} which is intended to
    replace the inconsistently-named COMPAT_32BIT (which will be removed in
    future). Uses of this new variable should still be kept to a minimum,
    however, given the code duplication needed for new libcompats.
    
    Reviewed by:    emaste, brooks, jhb
    Differential Revision:  https://reviews.freebsd.org/D40922
---
 share/mk/bsd.compat.mk | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/share/mk/bsd.compat.mk b/share/mk/bsd.compat.mk
index 444a25101357..4b9bd7b621d2 100644
--- a/share/mk/bsd.compat.mk
+++ b/share/mk/bsd.compat.mk
@@ -115,11 +115,17 @@ WORLDTMP?=		${SYSROOT}
 LIB${_LIBCOMPAT}_OBJTOP?=	${OBJTOP}/obj-lib${_libcompat}
 
 LIB${_LIBCOMPAT}CFLAGS+=	${LIB${_LIBCOMPAT}CPUFLAGS} \
+				-DCOMPAT_LIBCOMPAT=\"${_LIBCOMPAT}\" \
+				-DCOMPAT_libcompat=\"${_libcompat}\" \
+				-DCOMPAT_LIB${_LIBCOMPAT} \
 				--sysroot=${WORLDTMP} \
 				${BFLAGS}
 
 LIB${_LIBCOMPAT}LDFLAGS+=	-L${WORLDTMP}/usr/lib${_libcompat}
 
+LIB${_LIBCOMPAT}WMAKEFLAGS+=	COMPAT_LIBCOMPAT=${_LIBCOMPAT} \
+				COMPAT_libcompat=${_libcompat}
+
 LIB${_LIBCOMPAT}WMAKEENV+=	MACHINE=${LIB${_LIBCOMPAT}_MACHINE}
 LIB${_LIBCOMPAT}WMAKEENV+=	MACHINE_ARCH=${LIB${_LIBCOMPAT}_MACHINE_ARCH}