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

_realname=gplugin
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.29.0
pkgrel=3
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="A GObject based library that implements a reusable plugin system (mingw-w64)"
license=("LGPL 2")
url="https://keep.imfreedom.org/gplugin/gplugin"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "gettext")
options=('strip' '!debug' 'staticlibs')
source=("${_realname}-${pkgver}.tar.xz::https://bintray.com/pidgin/releases/download_file?file_path=${_realname}-${pkgver}.tar.xz"
        001-win.patch)
sha256sums=('e5e48c328d15569f390bca0bfcd940d3d4245f348a4250edaec76c8c51dfd93f'
            '97020cd303307dd93d0f84f46542b84d41a32a1d975843e774fe36fb0071008d')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dgtk3=true \
    -Dgobject-introspection=true \
    -Dlua=false \
    -Dperl=false \
    -Dpython=false \
    -Dhelp2man=false \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ninja install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
