# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libsecret
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.21.2
pkgrel=2
pkgdesc="Library for storing and retrieving passwords and other secrets (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://wiki.gnome.org/Projects/Libsecret"
msys2_repository_url="https://gitlab.gnome.org/GNOME/libsecret"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "0001-port-to.mingw.patch"
        "0002-remove-dbus-portal.patch"
        "0003-meson-fixes.patch")
sha256sums=('e4a341496a0815e64c8d3b8fabab33d7bae7efdeab77b843669731d5b181dcee'
            '8eb491d024ec2430af6f760c430d120bac0eb49fe6ae5c1d78e50a94ed0b7def'
            '5019dd9efe6781e80a7fa5a338ec6d20f1c7ec2896e163bce11348605645472d'
            '43a27b10c326ac283ee5ad90f3c805298266f8f954af33d2f0ce6ce7d2c39461')
msys2_repository_url="https://gitlab.gnome.org/GNOME/libsecret"

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

  patch -Np1 -i "${srcdir}/0001-port-to.mingw.patch"
  patch -Np1 -i "${srcdir}/0002-remove-dbus-portal.patch"
  patch -Np1 -i "${srcdir}/0003-meson-fixes.patch"
}

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

  # clang error from vala generated file
  export CFLAGS="${CFLAGS} -Wno-incompatible-function-pointer-types"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    --wrap-mode=nofallback \
    -Dauto_features=enabled \
    -Dgtk_doc=false \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson.exe compile
}

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

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

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