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

_realname=gcab
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.6
pkgrel=3
pkgdesc="A GObject library to create cabinet files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://wiki.gnome.org/msitools'
msys2_references=(
  "cpe: cpe:/a:gnome:gcab"
)
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-${pkgver}.tar.xz"
        "0001-tests-Use-gcab_test_get_filename-to-construct-test-p.patch")
sha256sums=('2f0c9615577c4126909e251f9de0626c3ee7a152376c15b5544df10fc87e560b'
            '42635dce16dead559b4347729d694cc1fb8bd3c8e537126de4b927bd634f8b27')
msys2_repository_url="https://gitlab.gnome.org/GNOME/gcab"

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

  # https://gitlab.gnome.org/GNOME/gcab/-/merge_requests/17
  patch -Nbp1 -i "${srcdir}/0001-tests-Use-gcab_test_get_filename-to-construct-test-p.patch"
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype=plain \
    -Ddocs=false \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

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

  ${MINGW_PREFIX}/bin/meson test
}

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

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

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