git: f252e69e93d1 - stable/13 - build target triple variable from sys/conf/newvers.sh

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sun, 07 Jan 2024 23:08:03 UTC
The branch stable/13 has been updated by dim:

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

commit f252e69e93d10e5b8c51ba7c99c88e98be2c1c56
Author:     Alfredo Dal'Ava Junior <alfredo@FreeBSD.org>
AuthorDate: 2022-05-03 11:09:38 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-01-07 23:04:32 +0000

    build target triple variable from sys/conf/newvers.sh
    
    Retrieve FreeBSD revision number directly from sys/conf/newvers.sh
    when building the compiler target triple value, avoiding manual
    intervention on other files every new release.
    
    Reviewed by:    imp
    MFC after:      2 months
    Sponsored by:   Instituto de Pesquisas Eldorado (eldorado.org.br)
    Differential Revision:  https://reviews.freebsd.org/D34429
    
    (cherry picked from commit f9ee4156741a205c93ae947595b5c48717107d9e)
---
 Makefile.inc1           | 4 ++--
 lib/clang/llvm.build.mk | 9 ++++++---
 share/mk/bsd.compat.mk  | 8 ++++----
 share/mk/src.sys.env.mk | 5 +++++
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index 42707c3ccfbc..948332a80043 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -136,9 +136,9 @@ TARGET_ABI=	gnueabi
 .endif
 .endif
 MACHINE_ABI?=	unknown
-MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd13.2
+MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${MACHINE_ABI}-freebsd${OS_REVISION}
 TARGET_ABI?=	unknown
-TARGET_TRIPLE?=	${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd13.2
+TARGET_TRIPLE?=	${TARGET_ARCH:S/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd${OS_REVISION}
 KNOWN_ARCHES?=	aarch64/arm64 \
 		amd64 \
 		armv6/arm \
diff --git a/lib/clang/llvm.build.mk b/lib/clang/llvm.build.mk
index 4ee9e8d5d63b..45a779584e74 100644
--- a/lib/clang/llvm.build.mk
+++ b/lib/clang/llvm.build.mk
@@ -13,6 +13,10 @@
 .error Please define SRCDIR before including this file
 .endif
 
+.ifndef OS_REVISION
+.error Please define OS_REVISION before including this file
+.endif
+
 .PATH:		${LLVM_BASE}/${SRCDIR}
 
 CFLAGS+=	-I${SRCTOP}/lib/clang/include
@@ -43,10 +47,9 @@ TARGET_ABI=	-gnueabi
 TARGET_ABI=
 .endif
 VENDOR=		unknown
-OS_VERSION=	freebsd13.2
 
-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}
+LLVM_TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-freebsd${OS_REVISION}${TARGET_ABI}
+LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-freebsd${OS_REVISION}
 
 CFLAGS+=	-DLLVM_DEFAULT_TARGET_TRIPLE=\"${LLVM_TARGET_TRIPLE}\"
 CFLAGS+=	-DLLVM_HOST_TRIPLE=\"${LLVM_BUILD_TRIPLE}\"
diff --git a/share/mk/bsd.compat.mk b/share/mk/bsd.compat.mk
index 1cb6ab9567c9..ef485b843f99 100644
--- a/share/mk/bsd.compat.mk
+++ b/share/mk/bsd.compat.mk
@@ -29,7 +29,7 @@ LIB32CPUFLAGS=	-march=${COMPAT_CPUTYPE}
 .endif
 .if ${COMPAT_COMPILER_TYPE} == gcc
 .else
-LIB32CPUFLAGS+=	-target x86_64-unknown-freebsd13.2
+LIB32CPUFLAGS+=	-target x86_64-unknown-freebsd${OS_REVISION}
 .endif
 LIB32CPUFLAGS+=	-m32
 LIB32_MACHINE=	i386
@@ -50,7 +50,7 @@ LIB32CPUFLAGS=	-mcpu=${COMPAT_CPUTYPE}
 .if ${COMPAT_COMPILER_TYPE} == "gcc"
 LIB32CPUFLAGS+=	-m32
 .else
-LIB32CPUFLAGS+=	-target powerpc-unknown-freebsd13.2
+LIB32CPUFLAGS+=	-target powerpc-unknown-freebsd${OS_REVISION}
 .endif
 
 LIB32_MACHINE=	powerpc
@@ -68,9 +68,9 @@ LIB32CPUFLAGS=	-march=${COMPAT_CPUTYPE}
 .endif
 .else
 .if ${COMPAT_ARCH:Mmips64el*} != ""
-LIB32CPUFLAGS=  -target mipsel-unknown-freebsd13.2
+LIB32CPUFLAGS=  -target mipsel-unknown-freebsd${OS_REVISION}
 .else
-LIB32CPUFLAGS=  -target mips-unknown-freebsd13.2
+LIB32CPUFLAGS=  -target mips-unknown-freebsd${OS_REVISION}
 .endif
 .endif
 LIB32CPUFLAGS+= -mabi=32
diff --git a/share/mk/src.sys.env.mk b/share/mk/src.sys.env.mk
index 0a7f8ea800cc..c857972e47c4 100644
--- a/share/mk/src.sys.env.mk
+++ b/share/mk/src.sys.env.mk
@@ -22,6 +22,11 @@ RELTOP?= 	${RELDIR:C,[^/]+,..,g}
 RELOBJTOP?=	${RELTOP}
 RELSRCTOP?=	${RELTOP}
 
+.if !defined(OS_REVISION)
+OS_REVISION!=eval `sh ${SRCTOP}/sys/conf/newvers.sh -V REVISION` && echo $$REVISION || echo
+.export OS_REVISION
+.endif
+
 # site customizations that do not depend on anything!
 
 # Save MAKEOBJDIRPREFIX and don't let src-env.conf modify it.