git: e2f3e8c5e89c - stable/12 - Revert "Avoid using TARGET_ARCH in llvm.build.mk"

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Mon, 17 Oct 2022 15:40:54 UTC
The branch stable/12 has been updated by kevans:

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

commit e2f3e8c5e89c745429968220a12e2de9e79b4a07
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2022-10-14 03:04:47 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2022-10-17 15:40:17 +0000

    Revert "Avoid using TARGET_ARCH in llvm.build.mk"
    
    This reverts commit 8534e6be8110a8126268a38dc0557a2d15615ce9, and adds
    a cautionary note that there are dragons about that should be considered
    when changing it.
    
    PR:             267026
    Reviewed by:    dim, imp
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D36981
    
    (cherry picked from commit ed7910fbac07ee39d10528994e49ada2d0f2d754)
---
 lib/clang/llvm.build.mk | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/clang/llvm.build.mk b/lib/clang/llvm.build.mk
index 1cd7b5f518cd..22d6b02c78a5 100644
--- a/lib/clang/llvm.build.mk
+++ b/lib/clang/llvm.build.mk
@@ -26,14 +26,19 @@ CFLAGS+=	-DHAVE_VCS_VERSION_INC
 CFLAGS+=	-DNDEBUG
 .endif
 
+# Note that using TARGET_ARCH here is essential for a functional native-xtools
+# build!  For native-xtools, we're building binaries that will work on the
+# *host* machine (MACHINE_ARCH), but they should default to producing binaries
+# for the *target* machine (TARGET_ARCH).
+TARGET_ARCH?=	${MACHINE_ARCH}
 BUILD_ARCH?=	${MACHINE_ARCH}
 
 # Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
 # arm (for armv4 and armv5 CPUs) always uses the soft float ABI.
 # For all other targets, we stick with 'unknown'.
-.if ${MACHINE_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
+.if ${TARGET_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
 TARGET_ABI=	-gnueabihf
-.elif ${MACHINE_ARCH:Marm*}
+.elif ${TARGET_ARCH:Marm*}
 TARGET_ABI=	-gnueabi
 .else
 TARGET_ABI=
@@ -41,7 +46,7 @@ TARGET_ABI=
 VENDOR=		unknown
 OS_VERSION=	freebsd12.4
 
-LLVM_TARGET_TRIPLE?=	${MACHINE_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-${OS_VERSION}${TARGET_ABI}
+LLVM_TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-${OS_VERSION}${TARGET_ABI}
 LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-${OS_VERSION}
 
 CFLAGS+=	-DLLVM_DEFAULT_TARGET_TRIPLE=\"${LLVM_TARGET_TRIPLE}\"