# Maintainer: Alexey Pavlov <alexpux@gmail.om>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=httplib2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.19.1
pkgrel=1
pkgdesc="Comprehensive HTTP client library, supporting many features (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url="https://github.com/httplib2/httplib2"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-certifi"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-python-pyparsing")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/httplib2/httplib2/archive/v${pkgver}.tar.gz
        cert.patch)
sha256sums=('26702e32b4e6a88e0230d3d51b4d07b68cda8d25cef7205cbf32e5313cdef274'
            '3503625ade773c17c9c44f4017aec634ff03db0073eb3ec11e6882a466d7aae6')

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

  # Patch, ref FS#40179
  patch -p1 -i "${srcdir}/cert.patch"

  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
}
