# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=libpeas
_versionedname=libpeas2
pkgbase=mingw-w64-${_versionedname}
pkgname=(
  "${MINGW_PACKAGE_PREFIX}-${_versionedname}"
  "${MINGW_PACKAGE_PREFIX}-${_versionedname}-docs"
)
pkgver=2.0.7
pkgrel=2
pkgdesc="A GObject-based plugins engine (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnome.pages.gitlab.gnome.org/libpeas/libpeas-2/'
msys2_repository_url='https://gitlab.gnome.org/GNOME/libpeas'
msys2_references=(
  'archlinux: libpeas-2'
  "cpe: cpe:/a:gnome:libpeas"
)
license=("spdx:LGPL-2.1-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-glade"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-python-gobject"
             "${MINGW_PACKAGE_PREFIX}-gi-docgen"
             "${MINGW_PACKAGE_PREFIX}-vala")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
        )
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-gobject: Python loader"
)
source=(https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-${pkgver}.tar.xz
        fix-build.patch)
sha256sums=('1e9a9d69761d2109eff5b7c11d8c96b4867ccfaca2b921eded49401192769ec9'
            'cd331d2abd26783775587cf018fce8c728a2affae291ff67f1c6963ddd8d453b')

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

  patch -p1 -i "${srcdir}"/fix-build.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    -Dgtk_doc=true \
    -Dgjs=false \
    -Dlua51=false \
    -Dvapi=true \
    ../${_realname}-${pkgver}

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

package_libpeas2() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}" --destdir "${pkgdir}"

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

  # split docs
  mkdir -p dest${MINGW_PREFIX}/share
  mv "${pkgdir}${MINGW_PREFIX}"/share/doc dest${MINGW_PREFIX}/share/doc
}

package_libpeas2-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
