# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=shapelib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.0
pkgrel=1
pkgdesc="simple C API for reading and writing ESRI Shapefiles (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://shapelib.maptools.org/"
license=("LGPL" "MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-proj")
options=(strip staticlibs)
source=("https://download.osgeo.org/shapelib/${_realname}-${pkgver}.tar.gz")
sha256sums=('1fc0a480982caef9e7b9423070b47750ba34cd0ba82668f2e638fab1d07adae1')

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

build() {
  #export lt_cv_deplibs_check_method='pass_all'
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  
  CPPFLAGS+=" -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"
  
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
