# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_wx_basever=3.2

_realname=spatialite-gui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
_pkgver=${pkgver}-beta1
pkgrel=11
pkgdesc='spatialite-gui is an open source Graphical User Interface (GUI) tool supporting SpatiaLite (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.gaia-gis.it/fossil/spatialite_gui/index'
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-geos"
         "${MINGW_PACKAGE_PREFIX}-libfreexl"
         "${MINGW_PACKAGE_PREFIX}-librasterlite2"
         "${MINGW_PACKAGE_PREFIX}-libspatialite"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread"
         "${MINGW_PACKAGE_PREFIX}-libxlsxwriter"
         "${MINGW_PACKAGE_PREFIX}-postgresql"
         "${MINGW_PACKAGE_PREFIX}-proj"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-virtualpg"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw"
)
source=("https://www.gaia-gis.it/gaia-sins/${_realname}-sources/${_realname/-/_}-${_pkgver}.tar.gz"
        '001-spatialite-gui-2.1.0-install-icons.patch'
        '002-fix-build-with-wxwidgets-3.2.patch')
sha256sums=('ba48d96df18cebc3ff23f69797207ae1582cce62f4596b69bae300ca3c23db33'
            '47fee2ec40c6d43db9ce1351ad3aea66c6de74579c9f65dda77538ba22455ce5'
            '4b77bb1463708d9fb9b1b61686653ccc6614782a4355dcc196df33c9260c75e3')

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

  patch -p0 -i "${srcdir}"/001-spatialite-gui-2.1.0-install-icons.patch
  patch -p1 -i "${srcdir}"/002-fix-build-with-wxwidgets-3.2.patch

  autoreconf -fiv
}

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

  LDFLAGS+=" -lpthread" \
  ../${_realname/-/_}-${_pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --with-wxconfig=${MINGW_PREFIX}/bin/wx-config-${_wx_basever}

  make
}

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

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname/-/_}-${_pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
