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

_realname=neon
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.31.2
pkgrel=2
pkgdesc="HTTP and WebDAV client library with a C interface (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://notroj.github.io/neon/"
license=('GPL' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('libtool' 'staticlibs') # FS#16067
source=(https://notroj.github.io/neon/${_realname}-${pkgver}.tar.gz
        neon-0.30.2-mingw-w64.patch
        neon-0.31.2-configure-stdcall.patch)
sha256sums=('cf1ee3ac27a215814a9c80803fcee4f0ede8466ebead40267a9bd115e16a8678'
            'a1e19dcd755784168542930a0e351506eb1bfc5d941904aa970f81b5b489a95d'
            '1eb9e381ad8ed975dafcc1718c7ef32e0b33a7d591939be614db2d799c57d336')
validpgpkeys=('190555472DCC589BEF01609C608A86DF9833CC49') #Joe Orton <joe@manyfish.uk>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/neon-0.30.2-mingw-w64.patch"
  # https://github.com/notroj/neon/commit/43a9b7e0d72ee97dcdbc102254ada20278eac80b
  patch -p1 -i "${srcdir}/neon-0.31.2-configure-stdcall.patch"

  ./autogen.sh
  #autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-expat \
    --enable-shared \
    --disable-static \
    --with-ssl=openssl \
    --with-ca-bundle=${MINGW_PREFIX}/ssl/certs/ca-bundle.crt
  make
}

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