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

_realname=py3c
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=1.4
pkgrel=5
pkgdesc="A Python 2/3 compatibility layer for C extensions"
arch=('i686' 'x86_64')
license=('spdx:MIT')
url="https://github.com/encukou/py3c"
msys2_references=(
  "purl: pkg:pypi/py3c"
)
depends=("python")
makedepends=(
  'make'
  'gcc'
  "python-setuptools"
  "python-build"
  "python-installer"
)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/encukou/py3c/archive/v${pkgver}.tar.gz")
sha256sums=('abc745079ef906148817f4472c3fb4bc41d62a9ea51a746b53e09819494ac006')
noextract=(${_realname}-${pkgver}.tar.gz)

build() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C $srcdir || true

  cd "${srcdir}/${_realname}-${pkgver}"
  python -m build --wheel --skip-dependency-check --no-isolation
  make prefix=/usr py3c.pc
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make prefix="${pkgdir}"/usr install

  python -m installer --destdir="${pkgdir}" dist/*.whl

  # Remove headers in broken location
  rm -r "${pkgdir}"/usr/include/python*

  # Remove pkgdir full path reference
  sed -i "s|${pkgdir}||g" "${pkgdir}"/usr/share/pkgconfig/py3c.pc

  install -Dm644 LICENSE.MIT -t "$pkgdir"/usr/share/licenses/$pkgname/
}
