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

_realname=libsecret
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.20.4
pkgrel=2
pkgdesc="Library for storing and retrieving passwords and other secrets (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://wiki.gnome.org/Projects/Libsecret"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${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")
options=('!libtool' 'strip')
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=('325a4c54db320c406711bf2b55e5cb5b6c29823426aa82596a907595abb39d28'
            '28bf8c3e22f10746177e7128e8293d2d0934f80daef37cf0e648492a07636bf8'
            '4e2cec3b9a89e73580394fd9b05aefe8ac1979e5aff783ca27dd1a603c741d69'
            '43a27b10c326ac283ee5ad90f3c805298266f8f954af33d2f0ce6ce7d2c39461')

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() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

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

  ninja
}

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

  DESTDIR="${pkgdir}" ninja install
}
