# Maintainer: Ray Donnelly <mingwandroid@gmail.com>
# Upstream Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Upstream Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

_realname=frei0r-plugins
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.1
pkgrel=1
pkgdesc='Minimalistic plugin API for video effects (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://frei0r.dyne.org/"
msys2_repository_url="https://github.com/dyne/frei0r"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-cairo"
             $([[ ${CARCH} == i686 ]] || echo \
               "${MINGW_PACKAGE_PREFIX}-gavl" \
               "${MINGW_PACKAGE_PREFIX}-opencv"))
optdepends=("${MINGW_PACKAGE_PREFIX}-cairo: cairoaffineblend, cairoblend, cairogradient and cairoimagegrid plugins")
if [[ ${CARCH} != i686 ]]; then
  optdepends+=("${MINGW_PACKAGE_PREFIX}-gavl: rgbparade, scale0tilt and vectorscope plugins"
               "${MINGW_PACKAGE_PREFIX}-opencv: facebl0r and facedetect plugins")
fi
source=("https://github.com/dyne/frei0r/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('318ec4a3042c94a00a58fccdc1eb0d911f36a22beb3504d27aefcca4598f40b0')
validpgpkeys=('6113D89CA825C5CEDD02C87273B35DA54ACB7D10') # Denis Roio (Jaromil)

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  local -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  if [[ ${CARCH} == i686 ]]; then
    _extra_config+=("-DWITHOUT_OPENCV=ON" "-DWITHOUT_GAVL=ON")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    ../frei0r-${pkgver}

  cmake --build .
}

check() {
  cd "build-${MSYSTEM}"
  # make check
}

package() {
  cd "build-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install .
}
