# Maintainer: Alberto Fanjul Alonso <albfan@gnome.org>

_realname=libgit2-glib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=0.99.0
pkgver=$_pkgver.1
pkgrel=3
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="GLib wrapper for libgit2 (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-libgit2>=0.99"
         "${MINGW_PACKAGE_PREFIX}-libssh2"
         "${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel")
options=('strip' 'staticlibs')
license=("LGPL2.1")
url="https://wiki.gnome.org/Projects/Libgit2-glib"
source=("https://download.gnome.org/sources/${_realname}/${_pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "Fix-vapi-generation-on-msys2.patch"
        "Invalid-path-resolving-relative-path-on-windows.patch")
sha256sums=('e05a75c444d9c8d5991afc4a5a64cd97d731ce21aeb7c1c651ade1a3b465b9de'
            '2aadb0a4887c9874f6785e5669e9af138d749a4fa54883fd87a8c729e0c5a508'
            '343deb91f8bb70631efd4e7eb91170c0ae0afa49205dfe9d1444a647fc3e83a0')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/Fix-vapi-generation-on-msys2.patch
  patch -p1 -i ${srcdir}/Invalid-path-resolving-relative-path-on-windows.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    -Dvapi=true \
    -Dgtk_doc=true \
    ../${_realname}-${pkgver}

  ninja
}

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

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