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

_realname=libgda
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.9
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="Data abstraction library based on GLib (mingw-w64)"
license=("LGPL 2")
url="https://www.gnome.org"
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview3"
         "${MINGW_PACKAGE_PREFIX}-goocanvas"
         "${MINGW_PACKAGE_PREFIX}-iso-codes"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt"
         "${MINGW_PACKAGE_PREFIX}-glade")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-iso-codes"
             #"${MINGW_PACKAGE_PREFIX}-db"
             "${MINGW_PACKAGE_PREFIX}-firebird2"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-openldap"
             "automake-wrapper"
             "autoconf"
             "flex"
             "gettext"
             "gnome-doc-utils"
             "gtk-doc"
             "libintl"
             "libtool"
             "make"
             "patch")
options=('strip' '!debug' 'staticlibs')
source=(https://download.gnome.org/sources/${_realname}/${pkgver:0:3}/${_realname}-${pkgver}.tar.xz
        001-lemon.patch
        002-mysql-m4.patch
        003-give-cc-to-gir-scanner.all.patch
        004-add-missing-symbols.patch
        005-hack-convert-path-back-to-unix.patch)
sha256sums=('59caed8ca72b1ac6437c9844f0677f8a296d52cfd1c0049116026abfb1d87d9b'
            'e61c10e41ea2b343c6a50d0cbf1f2912b9d9273882249a998f60cda2f4a94d4c'
            '5a9959715e63a82e5bf62bb3e6ffbe4d4b587094d13b671e2a676720c765e048'
            'a0a2e3ca548feedc6502f29ff0ef5f047bf2a7dabd7722011147872a5aea733b'
            '852956cb1f2cd77174b53ab56f509f4766442277d236b0e0eed5650f288d9c89'
            '88718da49d5c9671f4b7c7ac4a859762012c723928f3ad7c7000bad776200596')

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

  patch -p1 -i ${srcdir}/001-lemon.patch
  patch -p1 -i ${srcdir}/002-mysql-m4.patch
  patch -p1 -i ${srcdir}/003-give-cc-to-gir-scanner.all.patch
  patch -p1 -i ${srcdir}/004-add-missing-symbols.patch
  patch -p1 -i ${srcdir}/005-hack-convert-path-back-to-unix.patch

  autoreconf -fi
}

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

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-gda-gi \
    --enable-introspection \
    --enable-gtk-doc-html=no \
    --without-help \
    --enable-system-mdbtools=no \
    --enable-gi-system-install=no \
    --with-ldap=${MINGW_PREFIX} \
    --with-mysql=${MINGW_PREFIX} \
    --with-mysql-libdir-name=lib \
    --with-postgres=${MINGW_PREFIX} \
    --with-firebird=${MINGW_PREFIX} \
    --with-bdb=${MINGW_PREFIX}

  make
}

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