PORTNAME=	libclc
DISTVERSION=	${DISTVERSION_${FLAVOR}}
DISTVERSION_llvm22=	22.1.5
DISTVERSION_llvm21=	21.1.8
DISTVERSION_llvm20=	20.1.8
DISTVERSION_llvm19=	19.1.7
DISTVERSION_llvm18=	18.1.8
DISTVERSION_llvm17=	17.0.6
DISTVERSION_llvm16=	16.0.6
DISTVERSION_llvm15=	15.0.7
CATEGORIES=	devel
MASTER_SITES=	https://github.com/llvm/llvm-project/releases/download/llvmorg-${DISTVERSION}/
DISTNAME=	libclc-${DISTVERSION}.src
PKGNAMESUFFIX=	-${FLAVOR}

MAINTAINER=	x11@FreeBSD.org
COMMENT=	Required library functions for OpenCL C programming language
WWW=		https://libclc.llvm.org/

LICENSE=	LLVM
LICENSE_FILE=	${WRKSRC}/LICENSE.TXT
LICENSE_NAME=	Apache License 2.0 with LLVM Exceptions
LICENSE_PERMS=	dist-mirror dist-sell pkg-mirror pkg-sell auto-accept

BUILD_DEPENDS=	spirv-llvm-translator-${FLAVOR}>0:devel/spirv-llvm-translator@${FLAVOR} \
		libedit>=0:devel/libedit

FLAVORS=	${15 16 17 18 19 20 21 22:L:S/^/llvm/}

USES=		cmake compiler:c++11-lib llvm:${FLAVOR:S/llvm//},build python:build tar:xz
USE_LDCONFIG=	${PREFIX}/${FLAVOR}/lib

BINARY_ALIAS=	python=${PYTHON_CMD}
CMAKE_ARGS+=	-DLLVM_DIR:PATH="${LOCALBASE}/${FLAVOR}" \
		-DCMAKE_PREFIX_PATH="${LOCALBASE}/${FLAVOR}"
CMAKE_INSTALL_PREFIX=		${PREFIX}/${FLAVOR}
DISTINFO_FILE=	${.CURDIR}/distinfo.${FLAVOR}
NO_ARCH=	yes

.include <bsd.port.pre.mk>

.if ${FLAVOR} == llvm15
BROKEN_FreeBSD_16=	Base libc++ is now too fresh for Clang 15 to compile
.endif

.if ${FLAVOR:S/llvm//} >= 22
DISTNAME=	llvm-project-${DISTVERSION}.src
WRKSRC_SUBDIR=	libclc
.endif

.for i in ${FLAVORS:S/llvm//}
.if ${FLAVOR:S/llvm//} >= ${i}
PLIST_SUB+=	LLVM_GE${i}="" LLVM_LT${i}="@comment "
.else
PLIST_SUB+=	LLVM_GE${i}="@comment " LLVM_LT${i}=""
.endif
.endfor
PLIST_SUB+=	LLVM_VERSION=${FLAVOR}

post-patch:
	@${REINPLACE_CMD} \
		's,$${CMAKE_INSTALL_DATADIR}/pkgconfig,$${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig,' \
		${WRKSRC}/CMakeLists.txt

.include <bsd.port.post.mk>
