git: 5ca22080ae08 - main - Mk/Uses/compiler.mk: Support newer C++ standards

From: Felix Palmen <zirias_at_FreeBSD.org>
Date: Sun, 11 Sep 2022 11:36:16 UTC
The branch main has been updated by zirias:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5ca22080ae08a6707bbcb9af0529e9d54aa832d5

commit 5ca22080ae08a6707bbcb9af0529e9d54aa832d5
Author:     Felix Palmen <zirias@FreeBSD.org>
AuthorDate: 2022-08-25 08:36:02 +0000
Commit:     Felix Palmen <zirias@FreeBSD.org>
CommitDate: 2022-09-11 11:34:29 +0000

    Mk/Uses/compiler.mk: Support newer C++ standards
    
    * Add c++20-lang and c++2b-lang arguments
    * Respect LLVM_DEFAULT if it fullfills the requirements
    
    PR:                     244810, 266029
    Exp-run by:             antoine
    Approved by:            bapt, tcberner (mentor)
    Differential Revision:  https://reviews.freebsd.org/D35889
---
 Mk/Uses/compiler.mk | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/Mk/Uses/compiler.mk b/Mk/Uses/compiler.mk
index e8191c822942..d668873e1f2a 100644
--- a/Mk/Uses/compiler.mk
+++ b/Mk/Uses/compiler.mk
@@ -8,6 +8,8 @@
 # c++11-lang:	The port needs a compiler understanding C++11
 # c++14-lang:	The port needs a compiler understanding C++14
 # c++17-lang:	The port needs a compiler understanding C++17
+# c++20-lang:	The port needs a compiler understanding C++20
+# c++2b-lang:	The port needs a compiler understanding C++2b
 # gcc-c++11-lib:The port needs g++ compiler with a C++11 library
 # c++11-lib:	The port needs a compiler understanding C++11 and with a C++11 ready standard library
 # c11:		The port needs a compiler understanding C11
@@ -33,7 +35,8 @@ _INCLUDE_USES_COMPILER_MK=	yes
 compiler_ARGS=	env
 .  endif
 
-VALID_ARGS=	c++11-lib c++11-lang c++14-lang c++17-lang c11 features env nestedfct c++0x gcc-c++11-lib
+VALID_ARGS=	c++11-lib c++11-lang c++14-lang c++17-lang c++20-lang \
+		c++2b-lang c11 features env nestedfct c++0x gcc-c++11-lib
 
 _CC_hash:=	${CC:hash}
 _CXX_hash:=	${CXX:hash}
@@ -50,6 +53,10 @@ _COMPILER_ARGS+=	features c++11-lang
 _COMPILER_ARGS+=	features c++14-lang
 .  elif ${compiler_ARGS} == c++17-lang
 _COMPILER_ARGS+=	features c++17-lang
+.  elif ${compiler_ARGS} == c++20-lang
+_COMPILER_ARGS+=	features c++20-lang
+.  elif ${compiler_ARGS} == c++2b-lang
+_COMPILER_ARGS+=	features c++2b-lang
 .  elif ${compiler_ARGS} == c11
 _COMPILER_ARGS+=	features c11
 .  elif ${compiler_ARGS} == features
@@ -129,7 +136,8 @@ COMPILER_FEATURES=	libstdc++
 .    endif
 
 CSTD=	c89 c99 c11 gnu89 gnu99 gnu11
-CXXSTD=	c++98 c++0x c++11 c++14 c++17 gnu++98 gnu++11 gnu++14 gnu++17
+CXXSTD=	c++98 c++0x c++11 c++14 c++17 c++20 c++2b \
+	gnu++98 gnu++11 gnu++14 gnu++17 gnu++20 gnu++2b
 
 .    for std in ${CSTD} ${CXXSTD}
 _LANG=c
@@ -159,25 +167,41 @@ CHOSEN_COMPILER_TYPE=	gcc
 .    endif
 .  endif
 
-.  if (${_COMPILER_ARGS:Mc++17-lang} && !${COMPILER_FEATURES:Mc++17}) || \
+.  if (${_COMPILER_ARGS:Mc++2b-lang} && !${COMPILER_FEATURES:Mc++2b}) || \
+(${_COMPILER_ARGS:Mc++20-lang} && !${COMPILER_FEATURES:Mc++20}) || \
+(${_COMPILER_ARGS:Mc++17-lang} && !${COMPILER_FEATURES:Mc++17}) || \
 (${_COMPILER_ARGS:Mc++14-lang} && !${COMPILER_FEATURES:Mc++14}) || \
 (${_COMPILER_ARGS:Mc++11-lang} && !${COMPILER_FEATURES:Mc++11}) || \
 (${_COMPILER_ARGS:Mc++0x} && !${COMPILER_FEATURES:Mc++0x}) || \
 (${_COMPILER_ARGS:Mc11} && !${COMPILER_FEATURES:Mc11})
+.    if ${_COMPILER_ARGS:Mc++2b-lang}
+_LLVM_MINVER=	14
+.    elif ${_COMPILER_ARGS:Mc++20-lang}
+_LLVM_MINVER=	11
+.    else
+_LLVM_MINVER=	0
+.    endif
 .    if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2
 USE_GCC=	yes
 CHOSEN_COMPILER_TYPE=	gcc
-.    elif ${COMPILER_TYPE} == gcc
-.      if ${ALT_COMPILER_TYPE} == clang
+.    elif ${COMPILER_TYPE} == gcc || \
+	(${COMPILER_VERSION:C/[0-9]$//}<${_LLVM_MINVER})
+.      if ${ALT_COMPILER_TYPE} == clang && \
+	(${ALT_COMPILER_VERSION:C/[0-9]$//}>=${_LLVM_MINVER})
 CPP=	clang-cpp
 CC=	clang
 CXX=	clang++
 CHOSEN_COMPILER_TYPE=	clang
 .      else
-BUILD_DEPENDS+=	${LOCALBASE}/bin/clang10:devel/llvm10
-CPP=	${LOCALBASE}/bin/clang-cpp10
-CC=	${LOCALBASE}/bin/clang10
-CXX=	${LOCALBASE}/bin/clang++10
+.        if ${LLVM_DEFAULT:C/^[789]0$/0/}<${_LLVM_MINVER}
+_LLVM_REQ=	${_LLVM_MINVER}
+.        else
+_LLVM_REQ=	${LLVM_DEFAULT}
+.        endif
+BUILD_DEPENDS+=	clang${_LLVM_REQ}:devel/llvm${_LLVM_REQ}
+CPP=	${LOCALBASE}/bin/clang-cpp${_LLVM_REQ}
+CC=	${LOCALBASE}/bin/clang${_LLVM_REQ}
+CXX=	${LOCALBASE}/bin/clang++${_LLVM_REQ}
 CHOSEN_COMPILER_TYPE=	clang
 .      endif
 .    endif