# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=unpaper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=7.0.0
pkgrel=2
pkgdesc="post-processing tool for scanned sheets of paper"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/unpaper/unpaper"
license=("spdx:GPL-2.0-only")
msys2_references=("archlinux: $_realname")
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-docbook-xsl"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/unpaper/unpaper/releases/download/unpaper-$pkgver/unpaper-$pkgver.tar.xz")
sha256sums=('2575fbbf26c22719d1cb882b59602c9900c7f747118ac130883f63419be46a80')

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--buildtype=release")
  else
    _extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    "${_extra_config[@]}" \
    --wrap-mode=nodownload \
    --default-library=both \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson.exe install --destdir "$pkgdir"

  cd "${srcdir}/${_realname}-${pkgver}"
  install -dm0755 ${pkgdir}${MINGW_PREFIX}/share/doc/
  cp -a doc ${pkgdir}${MINGW_PREFIX}/share/doc/unpaper
  install -D README.md NEWS ${pkgdir}${MINGW_PREFIX}/share/doc/unpaper/
}
