# Maintainer: Jing Yufei <master-hash@outlook.com>

_realname=pdfpc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.7.0
pkgrel=2
pkgdesc="Presenter console with multi-monitor support for PDF files"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/pdfpc/pdfpc/'
msys2_references=(
  'anitya: 13340'
  'archlinux: pdfpc'
  'gentoo: app-text/pdfpc'
)
license=('spdx:GPL-3.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-discount"
  "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
  "${MINGW_PACKAGE_PREFIX}-gstreamer"
  "${MINGW_PACKAGE_PREFIX}-gtk3"
  "${MINGW_PACKAGE_PREFIX}-json-glib"
  "${MINGW_PACKAGE_PREFIX}-libgee"
  "${MINGW_PACKAGE_PREFIX}-libsoup3"
  "${MINGW_PACKAGE_PREFIX}-pango"
  "${MINGW_PACKAGE_PREFIX}-poppler"
  "${MINGW_PACKAGE_PREFIX}-qrencode")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-vala")
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-gst-libav: more codecs for video playback support"
  "${MINGW_PACKAGE_PREFIX}-gst-plugin-gtk: for video playback"
  "${MINGW_PACKAGE_PREFIX}-gst-plugins-good: more codecs for video playback support"
)
source=("https://github.com/pdfpc/pdfpc/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-relative-path-backport-pr-750.patch")
sha256sums=('0083a958a2e9288a15c31aabb76b3eadf104672b4e815017f31ffa0d87db02ec'
            '0344f079d5e7ee293b32ad57eeb8cc699e5728b574df49407c71057807c743d8')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-relative-path-backport-pr-750.patch" # delete after next release
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  # MDVIEW requires webkit2gtk
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DMDVIEW=OFF \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"

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