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

_realname=libdazzle
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.40.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="A companion library to GObject and Gtk+"
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
options=('strip' 'staticlibs')
license=("LGPL")
url="https://gitlab.gnome.org/GNOME/libdazzle"
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "0001-build-on-win32.patch"
        "0002-Install-to-bin-dir.patch"
        "0003-Include-counter-headers-not-for-Win32.patch")
sha256sums=('dba99a7e65fa6662c012b306e5d0f99ff3b466a46059ea7aa0104aaf65ce4ba5'
            '4078776e59f690829008b83008f967a9974bbaacce09e5a81bd9cad3a7893efc'
            '8585b4889cd1ce2c6a50634ff75f28a23f8d1b9ebf5f465e363e7897247ee12c'
            '9b2e711405255bf6e4cdc3aa1559f4d08882e9f1e3ee01cde327e96eda76076f')

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

  patch -p1 -i "${srcdir}/0001-build-on-win32.patch"
  patch -p1 -i "${srcdir}/0002-Install-to-bin-dir.patch"

  # https://gitlab.gnome.org/GNOME/libdazzle/-/merge_requests/51
  patch -p1 -i "${srcdir}/0003-Include-counter-headers-not-for-Win32.patch"
}

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

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

  meson compile
}

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

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