# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=libgovirt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.3.9
pkgrel=2
pkgdesc="GObject wrapper for the oVirt REST API (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.gnome.org/GNOME/libgovirt'
msys2_references=(
  'archlinux: libgovirt'
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-librest"
         "${MINGW_PACKAGE_PREFIX}-libsoup3")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
source=("https://gitlab.gnome.org/GNOME/libgovirt/-/archive/v${pkgver}/libgovirt-v${pkgver}.tar.bz2"
        "001-remove-unwanted-compile-flags.patch")
sha256sums=('0085aad5e952812e95564c2c0af67a483169dc98dd471bddf864134b1736f50a'
            '9543d055adcc394baf196f5cf038e4ebdcdf37ac1f4bf6cd51742d8af341d3ed')

prepare() {
  cd ${_realname}-v${pkgver}
  patch -p1 -i "${srcdir}"/001-remove-unwanted-compile-flags.patch
}

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--buildtype=release")
  else
    _extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      "${_extra_config[@]}" \
      ../${_realname}-v${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

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