# Maintainer: Bruno Pagani (a.k.a. ArchangeGabriel) <archange@archlinux.org>
# Contributor: Antoine Lubineau <antoine@lubignon.info>
# Contributor: Leopold Bloom <blinxwang@gmail.com>
# Contributor: Michal Krenek (a.k.a. Mikos) <m.krenek@gmail.com>

pkgname=beignet
pkgver=1.3.2+12+gfc5f430c
pkgrel=2
pkgdesc="An open source OpenCL implementation for Intel IvyBridge & Haswell iGPUs"
arch=('x86_64')
url="https://01.org/${pkgname}"
license=('LGPL')
depends=('glu' 'llvm-libs' 'clang' 'mesa' 'opencl-headers')
makedepends=('git' 'llvm' 'cmake' 'python' 'ocl-icd')
provides=('opencl-intel' 'opencl-driver')
conflicts=('opencl-intel')
_commit=fc5f430cb7b7a8f694d86acbb038bd5b38ec389c  # master as of 2018-08-20
source=("git+https://anongit.freedesktop.org/git/beignet.git#commit=$_commit"
        'llvm8.patch')
sha256sums=('SKIP'
            'f16b13a3263b5042081094cd20c9e09c20a3a6d6e1dd796f460e4f447cfbb598')

prepare() {
    mkdir -p build
    cd ${pkgname}

    # Remove implementation of cl_intel_device_side_avc_motion_estimation
    # (conflicts with the implemention in Clang 8)
    git revert -n 9b7ca443cf7b 9cb7ff4c285d

    patch -Np0 -i ../llvm8.patch
}

build() {
    cd build
    cmake ../${pkgname} \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=/usr/lib \
        -DCMAKE_BUILD_TYPE=RELEASE
    make
}

package() {
    cd build
    make DESTDIR="${pkgdir}" install
    # Remove headers already provided by 'opencl-headers'
    cd "${pkgdir}/usr/include/CL"
    rm cl.h cl_egl.h cl_ext.h cl_gl.h cl_gl_ext.h cl_platform.h opencl.h
}
