git: a1b675731301 - main - arm64 lib32: enable building of lib32 on arm64

From: Mike Karels <karels_at_FreeBSD.org>
Date: Wed, 26 Jul 2023 00:00:23 UTC
The branch main has been updated by karels:

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

commit a1b67573130114257fdd443c4ec9b54fbe2e5843
Author:     Mike Karels <karels@FreeBSD.org>
AuthorDate: 2023-07-25 23:59:52 +0000
Commit:     Mike Karels <karels@FreeBSD.org>
CommitDate: 2023-07-25 23:59:52 +0000

    arm64 lib32: enable building of lib32 on arm64
    
    Enable LIB32 option on aarch64, defaulting to YES; it had defaulted
    to "broken".  Add required variables for how to compile lib32 on
    arm.  Use /usr/include/arm for armv7 (32-bit) headers, analogous to
    /usr/include/i386 on amd64.  Omit libomp from lib32; it is not
    supported on armv7.
    
    Reviewed by:    jrtc27
    Differential Revision:  https://reviews.freebsd.org/D40945
---
 Makefile.inc1          |  2 ++
 Makefile.libcompat     |  2 +-
 lib/Makefile           |  2 +-
 share/mk/bsd.compat.mk | 19 +++++++++++++++++++
 share/mk/src.opts.mk   |  4 ++--
 5 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index 415bc41a6726..53699a454ff6 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -163,6 +163,8 @@ _t=		${TARGET_ARCH}/${TARGET}
 
 .if ${TARGET_ARCH} == "amd64"
 LIBCOMPAT_INCLUDE_DIRS+= i386
+.elif ${TARGET_ARCH} == "aarch64"
+LIBCOMPAT_INCLUDE_DIRS+= arm
 .endif
 
 .if ${.MAKE.OS} != "FreeBSD"
diff --git a/Makefile.libcompat b/Makefile.libcompat
index b21e27105e99..f9fe28e1082b 100644
--- a/Makefile.libcompat
+++ b/Makefile.libcompat
@@ -4,7 +4,7 @@
 __<${_this:T}>__:
 
 # Makefile for the compatibility libraries.
-# - 32-bit compat libraries on PowerPC, and AMD64.
+# - 32-bit compat libraries on some 64-bit architectures
 
 .if defined(_LIBCOMPATS)
 
diff --git a/lib/Makefile b/lib/Makefile
index 47ff3cec7ebf..310935fdc26e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -203,7 +203,7 @@ SUBDIR.${MK_PMC}+=	libipt
 SUBDIR.${MK_BHYVE}+=	libvmmapi
 .endif
 
-.if ${MACHINE_ARCH} != "powerpc"
+.if ${MACHINE_ARCH} != "powerpc" && ${MACHINE_CPUARCH} != "arm"
 SUBDIR.${MK_OPENMP}+=	libomp
 .endif
 .if ${MK_USB} != "no"
diff --git a/share/mk/bsd.compat.mk b/share/mk/bsd.compat.mk
index cda3efd6cd63..49fbfe3bf8e2 100644
--- a/share/mk/bsd.compat.mk
+++ b/share/mk/bsd.compat.mk
@@ -63,6 +63,25 @@ LIB32_MACHINE=	powerpc
 LIB32_MACHINE_ARCH=	powerpc
 LIB32WMAKEFLAGS=	\
 		LD="${XLD} -m elf32ppc_fbsd"
+
+.elif ${COMPAT_ARCH} == "aarch64"
+HAS_COMPAT+=	32
+.if empty(LIB32CPUTYPE)
+LIB32CPUFLAGS=	-march=armv7
+.else
+LIB32CPUFLAGS=	-mcpu=${LIB32CPUTYPE}
+.endif
+
+LIB32CPUFLAGS+=	-m32
+.if ${COMPAT_COMPILER_TYPE} == "gcc"
+.else
+LIB32CPUFLAGS+=	-target armv7-unknown-freebsd${OS_REVISION}-gnueabihf
+.endif
+
+LIB32_MACHINE=	arm
+LIB32_MACHINE_ARCH=	armv7
+LIB32WMAKEFLAGS=	\
+		LD="${XLD} -m armelf_fbsd"
 .endif
 
 LIB32WMAKEFLAGS+= NM="${XNM}"
diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk
index 0e9b5a052ffc..899d620fb0c1 100644
--- a/share/mk/src.opts.mk
+++ b/share/mk/src.opts.mk
@@ -297,8 +297,8 @@ __DEFAULT_YES_OPTIONS+=LLDB
 .else
 __DEFAULT_NO_OPTIONS+=LLDB
 .endif
-# LIB32 is supported on amd64 and powerpc64
-.if (${__T} == "amd64" || ${__T} == "powerpc64")
+# LIB32 is not supported on all 64-bit architectures.
+.if (${__T} == "amd64" || ${__T:Maarch64*} != "" || ${__T} == "powerpc64")
 __DEFAULT_YES_OPTIONS+=LIB32
 .else
 BROKEN_OPTIONS+=LIB32