# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=libvpl
pkgver=%version%
pkgrel=%release%
pkgdesc='Intel Video Processing Library'
arch=('x86_64')
url='https://intel.github.io/libvpl/'
license=('MIT')
depends=('libdrm' 'libva' 'libx11' 'wayland')
optdepends=('intel-media-sdk: runtime for legacy Intel GPUs'
            'onevpl-intel-gpu: runtime for Tiger Lake and newer GPUs')
makedepends=('cmake' 'libpciaccess' 'wayland-protocols')
provides=('onevpl' 'libvpl.so')
conflicts=('onevpl')
replaces=('onevpl')
source=("https://github.com/intel/libvpl/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('ad956ea7ecf14614325f59dfb44cc5ba08e2fcac373342d61c7db152ac651253')

build() {
    export CFLAGS+=' -DNDEBUG'
    export CXXFLAGS+=' -DNDEBUG'
    cmake -B build -S "libvpl-${pkgver}" \
        -G 'Unix Makefiles' \
        -DCMAKE_BUILD_TYPE:STRING='None' \
        -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
        -DCMAKE_INSTALL_SYSCONFDIR:PATH='/etc' \
        -DBUILD_EXAMPLES:BOOL='OFF' \
        -DBUILD_TESTS:BOOL='ON' \
        -DINSTALL_EXAMPLE_CODE:BOOL='OFF' \
        -DVPL_INSTALL_LICENSEDIR:PATH="share/licenses/${pkgname}" \
        -Wno-dev
    cmake --build build
}

check() {
    ctest --test-dir build --output-on-failure
}

package() {
    DESTDIR="$pkgdir" cmake --install build
    
    local _file
    while read -r -d '' _file
    do
        if ! grep -q '^vpl-' <<< "$_file"
        then
            mv "${pkgdir}/usr/bin"/{,vpl-}"$_file"
        fi
    done < <(find "${pkgdir}/usr/bin" -mindepth 1 -maxdepth 1 -type f -print0 | sed -z 's|.*/||')
}
