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

_realname=libvirt-glib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="libvirt GLib and GObject mapping library (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libvirt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('!strip' 'debug' 'staticlibs')
license=("LGPL 2.1")
url="https://www.gnome.org/"
#install=${_realname}-${CARCH}.install
source=(https://libvirt.org/sources/glib/${_realname}-${pkgver}.tar.gz
        001-win.patch)
sha256sums=('7fff8ca9a2b723dbfd04223b1c7624251c8bf79eb57ec27362a7301b2dd9ebfe'
            '8f787245ffc5d91f628c1965a45baf0af61eb3afcf4da8642b763e578275c6c9')

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

  autoreconf -fi
}

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

  mkdir -p docs/libvirt-gconfig/html
  cp -rf ../${_realname}-${pkgver}/docs/libvirt-gconfig/html/* docs/libvirt-gconfig/html
  mkdir -p docs/libvirt-glib/html
  cp -rf ../${_realname}-${pkgver}/docs/libvirt-glib/html/* docs/libvirt-glib/html
  mkdir -p docs/libvirt-gobject/html
  cp -rf ../${_realname}-${pkgver}/docs/libvirt-gobject/html/* docs/libvirt-gobject/html

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=$pkgdir install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
