# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=libgdata
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.18.1
pkgrel=7
pkgdesc="Library for accessing GData webservices (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnome.org/"
msys2_references=(
  "cpe: cpe:/a:gnome:libgdata"
)
license=("spdx:LGPL-2.1-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         #"${MINGW_PACKAGE_PREFIX}-liboauth"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
             #"${MINGW_PACKAGE_PREFIX}-uhttpmock"
             #"${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        0003-wsock.patch
        build-fix.patch)
sha256sums=('dd8592eeb6512ad0a8cf5c8be8c72e76f74bfe6b23e4dd93f0756ee0716804c7'
            'ed4c9c441ee3bf4a5279c5d212b2c1116ce443763151b71975611406310575df'
            '32902d6420f555fb5db8806c49bebbefddf6a7b62a1ee01e8404069239e7976f')

prepare() {
  cd ${_realname}-${pkgver}

  # https://gitlab.gnome.org/GNOME/libgdata/-/merge_requests/44
  patch -p1 -i "${srcdir}"/0003-wsock.patch
  patch -p1 -i "${srcdir}"/build-fix.patch
}

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

  export CFLAGS+=" -Wno-implicit-function-declaration -Wno-incompatible-pointer-types"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    --wrap-mode=nofallback \
    -Dauto_features=enabled \
    -Dgnome=disabled \
    -Dgoa=disabled \
    -Dvapi=false \
    -Dman=true \
    -Dinstalled_tests=false \
    -Dalways_build_tests=false \
    ../${_realname}-${pkgver}

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

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson.exe test || true
}

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"
}
