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

_realname=neon
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.36.0
pkgrel=1
pkgdesc="HTTP and WebDAV client library with a C interface (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://notroj.github.io/neon/"
msys2_repository_url="https://github.com/notroj/neon"
msys2_references=(
  "cpe: cpe:/a:neon:neon"
  "cpe: cpe:/a:webdav:neon"
)
license=('spdx:LGPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://notroj.github.io/neon/${_realname}-${pkgver}.tar.gz
        0001-m4-check-libintl-functions.patch
        0002-makefile-fix-doc-dir.patch
        neon-0.30.2-mingw-w64.patch)
sha256sums=('70cc7f2aeebde263906e185b266e04e0de92b38e5f4ecccbf61e8b79177c2f07'
            '835157a864bfbc53f68a5a71b83edbbf93311fb480e12172d64fec92618f35e9'
            '0104d00028a563eddc746539fa5b0085a0dc4e8dc28baa6c71caed374b246903'
            '526ed60a64f66f8163c83d3fd2ce7635389d1439a38e707e167893143008f8b7')
validpgpkeys=('190555472DCC589BEF01609C608A86DF9833CC49') #Joe Orton <joe@manyfish.uk>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-m4-check-libintl-functions.patch"
  patch -p1 -i "${srcdir}/0002-makefile-fix-doc-dir.patch"
  patch -p1 -i "${srcdir}/neon-0.30.2-mingw-w64.patch"

  ./autogen.sh
  #autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

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

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

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/bin/neon-config
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/libneon.la
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/neon.pc
}
