# Maintainer: Ignacio Casal Quinteiro <icq@gnome.org>

_realname=json-glib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.8
pkgrel=2
pkgdesc="JSON-GLib implements a full suite of JSON-related tools using GLib and GObject (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gnome.pages.gitlab.gnome.org/json-glib/"
msys2_repository_url="https://gitlab.gnome.org/GNOME/json-glib"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-python-docutils")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('55c5c141a564245b8f8fbe7698663c87a45a7333c2a2c56f06f811ab73b212dd')
noextract=("${_realname}-${pkgver}.tar.xz")

prepare() {
  bsdtar -xf "${_realname}-${pkgver}.tar.xz" || bsdtar -xf "${_realname}-${pkgver}.tar.xz" || true
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype plain \
    -Dman=true \
    -Dinstalled_tests=false \
    -Ddocumentation=disabled \
    "build-${MSYSTEM}" \
    "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}"
}

check() {
  meson test -C "build-${MSYSTEM}" || warning "Tests failed"
}

package() {
  meson install -C "build-${MSYSTEM}" --destdir "${pkgdir}"

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