git: 4df0e66a3662 - main - llvm.mk: add export/noexport to handle CC/CXX/CPP exports

From: Tobias C. Berner <tcberner_at_FreeBSD.org>
Date: Wed, 13 Sep 2023 05:18:23 UTC
The branch main has been updated by tcberner:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4df0e66a3662ac9d427c2dcd79eb8555236083dd

commit 4df0e66a3662ac9d427c2dcd79eb8555236083dd
Author:     Tobias C. Berner <tcberner@FreeBSD.org>
AuthorDate: 2023-07-10 18:57:28 +0000
Commit:     Tobias C. Berner <tcberner@FreeBSD.org>
CommitDate: 2023-09-13 05:16:58 +0000

    llvm.mk: add export/noexport to handle CC/CXX/CPP exports
    
    Reviewed by:    bofh
    Differential Revision:  https://reviews.freebsd.org/D37747
---
 CHANGES         |  7 +++++++
 Mk/Uses/llvm.mk | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/CHANGES b/CHANGES
index 2f6c9a61499d..bc1188ea4016 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,13 @@ in the release notes and/or placed into UPDATING.
 
 All ports committers are allowed to commit to this file.
 
+20230823:
+AUTHOR: tcberner@FreeBSD.org
+
+  USES=llvm.mk now supports 'export' (default) and 'noexport' arguments.
+  When export is set, CC, CXX and CPP will be set to the path corresponding
+  to the chosen llvm-version.
+
 20230821:
 AUTHOR: jhale@FreeBSD.org
 
diff --git a/Mk/Uses/llvm.mk b/Mk/Uses/llvm.mk
index 931ad99156f8..54cd2364255b 100644
--- a/Mk/Uses/llvm.mk
+++ b/Mk/Uses/llvm.mk
@@ -14,6 +14,10 @@
 #         min=number:     use specified min if ${LLVM_DEFAULT} is lower
 #         max=number:     use specified max if ${LLVM_DEFAULT} is higher
 #
+# * environment
+#         export:         do export CC, CXX,... variables [default]
+#         noexport:       do not export CC,CXX,... variables
+#
 # An example usage might be:
 #         USES=   llvm
 #   or
@@ -35,6 +39,7 @@ _INCLUDE_USES_LLVM_MK=	YES
 _LLVM_MK_VALID_VERSIONS=	10 11 12 13 14 15 16
 _LLVM_MK_VALID_CONSTRAINTS=	min max
 _LLVM_MK_VALID_MODES=		build run lib
+_LLVM_MK_VALID_EXPORTS=		export noexport
 
 # === parse mode arguments ===
 _LLVM_MK_MODES=	# empty
@@ -66,6 +71,21 @@ _LLVM_MK_VERSION=	${LLVM_DEFAULT}
 .    endif
 .  endif
 
+# === parse environment arguments ===
+_LLVM_MK_EXPORT=	# empty
+.  for _export in ${_LLVM_MK_VALID_EXPORTS}
+.    if ${llvm_ARGS:M${_export}}
+.      if !empty(_LLVM_MK_EXPORT)
+BROKEN=		USES=llvm:${llvm_ARGS} contains multiple export definitions
+.      else
+_LLVM_MK_EXPORT=	${_export}
+.      endif
+.    endif
+.  endfor
+.  if empty(_LLVM_MK_EXPORT)
+_LLVM_MK_EXPORT=	export
+.  endif
+
 # === handle constraints ===
 .  for _constraint in ${_LLVM_MK_VALID_CONSTRAINTS}
 _version=	${llvm_ARGS:M${_constraint}=[0-9]*:S/${_constraint}=//}
@@ -115,4 +135,10 @@ LLVM_LIBLLVM=		${_LLVM_MK_LIBLLVM}
 LLVM_VERSION=		${_LLVM_MK_VERSION}
 LLVM_PREFIX=		${_LLVM_MK_PREFIX}
 
+.  if empty(_LLVM_MK_EXPORT:Mnoexport)
+CC=			${LLVM_PREFIX}/bin/clang
+CXX=			${LLVM_PREFIX}/bin/clang++
+CPP=			${LLVM_PREFIX}/bin/clang-cpp
+.  endif
+
 .endif