# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gtk-vnc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4.0
pkgrel=2
pkgdesc="VNC viewer widget for GTK+ (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://wiki.gnome.org/Projects/gtk(2d)vnc'
msys2_repository_url='https://gitlab.gnome.org/GNOME/gtk-vnc'
msys2_references=(
  "cpe: cpe:/a:gnome:gtk-vnc"
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vala")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        gvncviewer-1.2.0.patch
        001-fix-keymapgen-call.patch)
sha256sums=('1be64c4e4760c52b3ec33067290d1efa40ad4cecab6c673813804e3c559d9683'
            'f1733935c715db6d9e92bf9c76b75b4be7198f99ef4eecb6155890f8c64d0d4c'
            'e053dd9f647852e29967543f2a2944e9d10da679141a354e4269efd9d2163a28')

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

  patch -Np1 -i "${srcdir}"/gvncviewer-1.2.0.patch
  patch -Np1 -i "${srcdir}"/001-fix-keymapgen-call.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dwith-vala=enabled \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson test || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.LIB \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB
}
