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

_realname=py3c
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=1.3.1
pkgrel=1
pkgdesc="A Python 2/3 compatibility layer for C extensions"
arch=('i686' 'x86_64')
license=('MIT')
url="https://github.com/encukou/py3c"
depends=("python")
makedepends=("python-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/encukou/py3c/archive/v${pkgver}.tar.gz")
sha256sums=('f3e138623a87cde2cd7d8e98b51447e033d43a3f639c5054185c859fa1888727')
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}"
  /usr/bin/python setup.py build
  make prefix=/usr py3c.pc
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make prefix="${pkgdir}"/usr install
  /usr/bin/python setup.py install --prefix=/usr --root="${pkgdir}" -O1

  # 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/
}
