# Maintainer: LI Xuzhang <lixuzhang@gmail.com>

_realname=postgis
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.3
pkgrel=1
pkgdesc="Spatial and Geographic objects for PostgreSQL (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://postgis.net/"
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=( "${MINGW_PACKAGE_PREFIX}-gcc-libs"
          "${MINGW_PACKAGE_PREFIX}-gdal"
          "${MINGW_PACKAGE_PREFIX}-geos"
          "${MINGW_PACKAGE_PREFIX}-gettext"
          "${MINGW_PACKAGE_PREFIX}-json-c"
          "${MINGW_PACKAGE_PREFIX}-libxml2"
          "${MINGW_PACKAGE_PREFIX}-postgresql"
          #"${MINGW_PACKAGE_PREFIX}-protobuf-c"
          "${MINGW_PACKAGE_PREFIX}-proj")
options=('staticlibs' 'strip')
source=("https://download.osgeo.org/postgis/source/${_realname}-${pkgver}.tar.gz"
        pg_config
        001-fix-disable-protobuf.patch)
sha256sums=('07fedbd046cbed55d24bb22474890a4651d0223b6e12d2dac1517b9a43674817'
            '3cd5a095cd4de7cb7d5f5fa9dbc02dfe02297ae1743c2961e70d9110d214f64f'
            '9df17f9e83af71979e746a06c13ace584a1ab97a1d138e7884c17a339fe4b957')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-disable-protobuf.patch

  ./autogen.sh
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -rf "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-protobuf \
    --with-pgconfig=${srcdir}/pg_config

  make
}

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