From 0eafd4cd77602ccc5a1b0a487be6a2b47c402706 Mon Sep 17 00:00:00 2001
From: Marek Szuba <marecki@gentoo.org>
Date: Fri, 30 Jun 2017 14:50:24 +0159
Subject: [PATCH] dev-libs/beignet: do not try enabling OpenCL 2.0 support on
 unsupported ABIs

Beignet CMake scripts handle this the right way so let's work with them instead
of against them. Now if USE=ocl20 it will get enabled for abi_x86_64 and
gracefully fall back to 1.2 for the others, whereas USE=-ocl20 still explicitly
disables it for all ABIs.

With many thanks to aballier.

Gentoo-Bug: 622964

Package-Manager: Portage-2.3.6, Repoman-2.3.1
---
 dev-libs/beignet/beignet-1.3.1-r1.ebuild | 103 +++++++++++++++++++++++
 dev-libs/beignet/beignet-9999.ebuild     |   2 +-
 2 files changed, 104 insertions(+), 1 deletion(-)
 create mode 100644 dev-libs/beignet/beignet-1.3.1-r1.ebuild

diff --git a/dev-libs/beignet/beignet-1.3.1-r1.ebuild b/dev-libs/beignet/beignet-1.3.1-r1.ebuild
new file mode 100644
index 0000000000000..44c6896db127f
--- /dev/null
+++ b/dev-libs/beignet/beignet-1.3.1-r1.ebuild
@@ -0,0 +1,103 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+PYTHON_COMPAT=( python{2_7,3_4,3_5} )
+CMAKE_BUILD_TYPE="Release"
+
+inherit python-any-r1 cmake-multilib flag-o-matic toolchain-funcs
+
+DESCRIPTION="OpenCL implementation for Intel GPUs"
+HOMEPAGE="https://01.org/beignet"
+
+LICENSE="LGPL-2.1+"
+SLOT="0"
+IUSE="ocl-icd ocl20"
+
+if [[ "${PV}" == "9999" ]]; then
+	inherit git-r3
+	EGIT_REPO_URI="git://anongit.freedesktop.org/beignet"
+	KEYWORDS=""
+else
+	KEYWORDS="~amd64"
+	SRC_URI="https://01.org/sites/default/files/${P}-source.tar.gz"
+	S=${WORKDIR}/Beignet-${PV}-Source
+fi
+
+COMMON="media-libs/mesa
+	sys-devel/clang:0=
+	>=sys-devel/llvm-3.6:0=
+	ocl20? ( >=sys-devel/llvm-3.9:0= )
+	>=x11-libs/libdrm-2.4.70[video_cards_intel]
+	x11-libs/libXext
+	x11-libs/libXfixes"
+RDEPEND="${COMMON}
+	app-eselect/eselect-opencl"
+DEPEND="${COMMON}
+	${PYTHON_DEPS}
+	ocl-icd? ( dev-libs/ocl-icd )
+	virtual/pkgconfig"
+
+PATCHES=(
+	"${FILESDIR}"/no-debian-multiarch.patch
+	"${FILESDIR}"/${P}-oclicd_no_upstream_icdfile.patch
+	"${FILESDIR}"/${PN}-1.2.0_no-hardcoded-cflags.patch
+	"${FILESDIR}"/llvm-terminfo.patch
+)
+
+DOCS=(
+	docs/.
+)
+
+pkg_pretend() {
+	if [[ ${MERGE_TYPE} != "binary" ]]; then
+		if tc-is-gcc; then
+			if [[ $(gcc-major-version) -eq 4 ]] && [[ $(gcc-minor-version) -lt 6 ]]; then
+				eerror "Compilation with gcc older than 4.6 is not supported"
+				die "Too old gcc found."
+			fi
+		fi
+	fi
+}
+
+pkg_setup() {
+	python_setup
+}
+
+src_prepare() {
+	# See Bug #593968
+	append-flags -fPIC
+
+	cmake-utils_src_prepare
+	# We cannot run tests because they require permissions to access
+	# the hardware, and building them is very time-consuming.
+	cmake_comment_add_subdirectory utests
+}
+
+multilib_src_configure() {
+	VENDOR_DIR="/usr/$(get_libdir)/OpenCL/vendors/${PN}"
+
+	local mycmakeargs=(
+		-DCMAKE_INSTALL_PREFIX="${VENDOR_DIR}"
+		-DOCLICD_COMPAT=$(usex ocl-icd)
+		$(usex ocl2 "" "-DENABLE_OPENCL_20=OFF")
+	)
+
+	cmake-utils_src_configure
+}
+
+multilib_src_install() {
+	VENDOR_DIR="/usr/$(get_libdir)/OpenCL/vendors/${PN}"
+
+	cmake-utils_src_install
+
+	insinto /etc/OpenCL/vendors/
+	echo "${VENDOR_DIR}/lib/${PN}/libcl.so" > "${PN}-${ABI}.icd" || die "Failed to generate ICD file"
+	doins "${PN}-${ABI}.icd"
+
+	dosym "lib/${PN}/libcl.so" "${VENDOR_DIR}"/libOpenCL.so.1
+	dosym "lib/${PN}/libcl.so" "${VENDOR_DIR}"/libOpenCL.so
+	dosym "lib/${PN}/libcl.so" "${VENDOR_DIR}"/libcl.so.1
+	dosym "lib/${PN}/libcl.so" "${VENDOR_DIR}"/libcl.so
+}
diff --git a/dev-libs/beignet/beignet-9999.ebuild b/dev-libs/beignet/beignet-9999.ebuild
index e842fbc151775..9e1ae6ff87f6a 100644
--- a/dev-libs/beignet/beignet-9999.ebuild
+++ b/dev-libs/beignet/beignet-9999.ebuild
@@ -80,7 +80,7 @@ multilib_src_configure() {
 	local mycmakeargs=(
 		-DCMAKE_INSTALL_PREFIX="${VENDOR_DIR}"
 		-DOCLICD_COMPAT=$(usex ocl-icd)
-		-DENABLE_OPENCL_20=$(usex ocl20)
+		$(usex ocl2 "" "-DENABLE_OPENCL_20=OFF")
 	)
 
 	cmake-utils_src_configure