# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=gnumeric
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.12.59
pkgrel=5
pkgdesc="The GNOME spreadsheet. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='http://www.gnumeric.org'
license=('spdx:GPL-3.0-only OR GPL-2.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-goffice"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libgsf"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-pango")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             #"${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-gobject"
             "${MINGW_PACKAGE_PREFIX}-libgda"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools")
optdepends=("${MINGW_PACKAGE_PREFIX}-libgda")
source=("https://download.gnome.org/sources/gnumeric/${pkgver%.*}/gnumeric-$pkgver.tar.xz"
        "001-fix-clash-between-intltool-and-gettext.patch"
        "002-no-more-warnings.patch"
        "003-remove-undefined-function.patch"
        "004-disable-some-plugins.patch"
        "005-do-not-build-gnumeric-chm-on-mingw.patch"
        "006-no-fake-index-theme-on-mingw.patch"
        "007-disable-doc.patch"
        "008-fix-find-python-h.patch")
sha256sums=('cb3750b176d641f9423df721b831658c829557552f8887fedf8a53d907eceb51'
            'a7b6299ac7df75f7d5c080014dbba0240f7cb2ec3d02db9f0b4cea33c725e05a'
            '44493d65d9d28070300fd626a0965288c9d8c38cce38808cc9bc43278a4b3e1b'
            '447942a91e4def819ee9cd234893def2a8281846e11a5091efcc57065f88f3ba'
            '5838fb65109d33a6d280de9c747a0b101f30d1cd40316c83ecc46b8d28353ff3'
            '2460b0b7010eea94c8ce8f9da12e4d1d3267bcdcef81a5a14bf2a036a1dd766a'
            'a01489960b06312d76e54eb9bb2500856d4aa4e910f9754a96487c129e0c2f40'
            'bca988670b6fd30f57577cb2942131029860493cf50a45245b9ddf17d8f9b612'
            '887b75137b3f0d71717fb86cf60f10dd62df6a3aeb2ae6680157c0260ad2517f')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

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

  apply_patch_with_msg \
    001-fix-clash-between-intltool-and-gettext.patch \
    002-no-more-warnings.patch \
    003-remove-undefined-function.patch \
    004-disable-some-plugins.patch \
    005-do-not-build-gnumeric-chm-on-mingw.patch \
    006-no-fake-index-theme-on-mingw.patch \
    007-disable-doc.patch \
    008-fix-find-python-h.patch

  autoreconf -fiv
}

build() {
  [[ -d "build-${MSYSTEM}" ]] && rm -rf "build-${MSYSTEM}"
  cp -r ${_realname}-${pkgver} "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  export lt_cv_deplibs_check_method='pass_all'

  CFLAGS+=" -Wno-implicit-function-declaration -DGNM_VAR_DECL=extern" \
  ./configure \
    --prefix="${MINGW_PREFIX}" \
    --enable-shared \
    --with-gda \
    --disable-schemas-compile \
    --without-python \
    PYTHON=${MINGW_PREFIX}/bin/python

  make
}

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

  make install DESTDIR="${pkgdir}"

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