# Maintainer: Alexey Kasatkin <alexeikasatkin@gmail.com>
# ArchLinux maintainer: Brian Galey <bkgaley at gmail dot com>
# Contributor: Aldeano <aldea.diaguita at gmail dot com>

_realname=spatialite-tools
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.0.1
pkgrel=1
pkgdesc='Set of CLI tools for spatialite (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.gaia-gis.it/fossil/spatialite-tools/index'
license=('GPL3+')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libspatialite"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-readosm")
options=('!libtool')
source=("https://www.gaia-gis.it/gaia-sins/${_realname}-sources/${_realname}-${pkgver}.tar.gz")
sha256sums=('9604c205e87f037789bc52302c66ccd1371c3e98c74e8ec4e29b0752de35171c')

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

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  LDFLAGS+=" -liconv"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  make
}

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