# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=libkml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=8
pkgdesc="Reference implementation of OGC KML 2.2 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/libkml/libkml/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             #"${MINGW_PACKAGE_PREFIX}-python"
             #"${MINGW_PACKAGE_PREFIX}-swig"
             )
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-uriparser"
         "${MINGW_PACKAGE_PREFIX}-zlib")
#optdepends=("${MINGW_PACKAGE_PREFIX}-python"
#            "${MINGW_PACKAGE_PREFIX}-swig")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/libkml/libkml/archive/${pkgver}.tar.gz"
        "001-libkml-1.3.0.patch"
        "002-resolve-conflicts-with-system-minizip.patch"
        "strptime.c")
sha256sums=('8892439e5570091965aaffe30b08631fdf7ca7f81f6495b4648f0950d7ea7963'
            '3692ee34904bbc2ba9a186df80e8d870162abf973151cb16715f26b752020875'
            '0a95ae7d92a584fe1a8bc93fa810a9b6b69e6e373ba10d51e1d86c836af5f885'
            '49433be91643aaccef032ded7d413782a6ed62f545883165814e13c0e1f4182c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-libkml-1.3.0.patch"
  patch -Np1 -i "${srcdir}/002-resolve-conflicts-with-system-minizip.patch"
  cp -f ../strptime.c src/kml/base/contrib
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DWITH_SWIG=OFF \
    -DWITH_PYTHON=OFF \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    "../${_realname}-${pkgver}"

  make
}

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