# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libplacebo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.120.3
pkgrel=1
pkgdesc="Reusable library for GPU-accelerated video/image rendering primitives (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://code.videolan.org/videolan/libplacebo"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glslang"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libepoxy"
         "${MINGW_PACKAGE_PREFIX}-shaderc"
         "${MINGW_PACKAGE_PREFIX}-spirv-tools"
         "${MINGW_PACKAGE_PREFIX}-vulkan")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-mako"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers")
license=('LGPLv2.1')
source=("https://code.videolan.org/videolan/libplacebo/-/archive/v${pkgver}/libplacebo-v${pkgver}.tar.gz")
sha256sums=('27b748abc26d64cb3ed0407f3068eda81b5bda06d74f2e74e059008755a1ef78')

prepare() {
  cd "${srcdir}/${_realname}-v${pkgver}"

}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  local _incdir="$(cygpath -wm ${MINGW_PREFIX}/include/glslang)"

  CFLAGS+=" -I${_incdir}" \
  CXXFLAGS+=" -I${_incdir}" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    -Ddemos=false \
    -Dlcms=enabled \
    -Dglslang=enabled \
    -Dshaderc=enabled \
    -Dvulkan=enabled \
    "../${_realname}-v${pkgver}"

  ${MINGW_PREFIX}/bin/ninja.exe
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja.exe install

  install -Dm644 "${srcdir}/${_realname}-v${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
