git: 426fc376afaf - main - bsd.cpu.mk: Introduce MACHINE_ABI

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Wed, 05 Oct 2022 16:29:42 UTC
The branch main has been updated by brooks:

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

commit 426fc376afaf39c1e754e263588534fdedb1b5ec
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2022-10-05 16:26:30 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2022-10-05 16:27:44 +0000

    bsd.cpu.mk: Introduce MACHINE_ABI
    
    MACHINE_ABI is a list of properties of the ABI used for MACHINE_ARCH.
    It should be used in place of long conditionals on MACHINE_ARCH where
    practical.
    
    The following properties are indicated with one of the follow values:
    
    Byte order:                  big-endian, little-endian
    Floating point ABI:          soft-float, hard-float
    Size of long (size_t, etc):  long32, long64
    Pointer type:                ptr32, ptr64
    Size of time_t:              time32, time64
    
    For example, i386 targets will be:
    MACHINE_ABI=    big-endian hard-float long32 ptr32 time32
    
    Reviewed by:    imp
    Obtained from:  CheriBSD
    Sponsored by:   DARPA, AFRL
    Differential Revision:  https://reviews.freebsd.org/D36421
---
 share/mk/bsd.compat.mk |  8 +++++++-
 share/mk/bsd.cpu.mk    | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/share/mk/bsd.compat.mk b/share/mk/bsd.compat.mk
index f7b40ce47532..9a59020b4df2 100644
--- a/share/mk/bsd.compat.mk
+++ b/share/mk/bsd.compat.mk
@@ -66,6 +66,12 @@ LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
 LIB32CFLAGS=	-DCOMPAT_32BIT
 LIB32DTRACE=	${DTRACE} -32
 LIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
+LIB32_MACHINE_ABI=	${MACHINE_ABI:N*64} long32 ptr32
+.if ${COMPAT_ARCH} == "amd64"
+LIB32_MACHINE_ABI+=	time32
+.else
+LIB32_MACHINE_ABI+=	time64
+.endif
 
 # -------------------------------------------------------------------
 # In the program linking case, select LIBCOMPAT
@@ -95,7 +101,7 @@ _LIBCOMPAT:=	${WANT_COMPAT}
 # Set defaults based on type.
 libcompat=	${_LIBCOMPAT:tl}
 _LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
-			_MACHINE _MACHINE_ARCH \
+			_MACHINE _MACHINE_ARCH _MACHINE_ABI \
 			WMAKEENV WMAKEFLAGS WMAKE WORLDTMP
 .for _var in ${_LIBCOMPAT_MAKEVARS}
 .if !empty(LIB${_LIBCOMPAT}${_var})
diff --git a/share/mk/bsd.cpu.mk b/share/mk/bsd.cpu.mk
index 610f45969b4d..db5fa08df4bc 100644
--- a/share/mk/bsd.cpu.mk
+++ b/share/mk/bsd.cpu.mk
@@ -362,3 +362,41 @@ CFLAGS_NO_SIMD += ${CFLAGS_NO_SIMD.${COMPILER_TYPE}}
 CFLAGS += ${CFLAGS.${MACHINE_ARCH}}
 CXXFLAGS += ${CXXFLAGS.${MACHINE_ARCH}}
 
+#
+# MACHINE_ABI is a list of properties about the ABI used for MACHINE_ARCH.
+# The following properties are indicated with one of the follow values:
+#
+# Byte order:			big-endian, little-endian
+# Floating point ABI:		soft-float, hard-float
+# Size of long (size_t, etc):	long32, long64
+# Pointer type:			ptr32, ptr64
+# Size of time_t:		time32, time64
+#
+.if (${MACHINE} == "arm" && (defined(CPUTYPE) && ${CPUTYPE:M*soft*})) || \
+    (${MACHINE_ARCH} == "powerpc" && (defined(CPUTYPE) && ${CPUTYPE} == "e500")) || \
+    ${MACHINE_ARCH:Mriscv*sf*}
+MACHINE_ABI+=	soft-float
+.else
+MACHINE_ABI+=	hard-float
+.endif
+# Currently all 64-bit architectures include 64 in their name (see arch(7)).
+.if ${MACHINE_ARCH:M*64*}
+MACHINE_ABI+=  long64
+.else
+MACHINE_ABI+=  long32
+.endif
+.if ${MACHINE_ABI:Mlong64}
+MACHINE_ABI+=  ptr64
+.else
+MACHINE_ABI+=  ptr32
+.endif
+.if ${MACHINE_ARCH} == "i386"
+MACHINE_ABI+=  time32
+.else
+MACHINE_ABI+=  time64
+.endif
+.if ${MACHINE_ARCH:Mpowerpc*} && !${MACHINE_ARCH:M*le}
+MACHINE_ABI+=	big-endian
+.else
+MACHINE_ABI+=	little-endian
+.endif