# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Maintainer: Maxime Gauduin <alucryd@archlinux.org>

_pkgname=httptools
pkgname=python-$_pkgname
pkgver=0.6.1
pkgrel=2
pkgdesc='Fast HTTP parser'
arch=('x86_64' 'aarch64')
url='https://github.com/MagicStack/httptools'
license=('MIT')
depends=('python' 'http-parser')
makedepends=('git' 'python-setuptools' 'python-wheel' 'cython')
_tag=de13727218c8e5855e6299ec2734f7c7b801d4a4
source=("git+$url#tag=$_tag"
        'git+https://github.com/nodejs/llhttp.git')
b2sums=('SKIP'
        'SKIP')

prepare() {
  cd $_pkgname

  sed -i 's|CYTHON_DEPENDENCY =.*|CYTHON_DEPENDENCY = "Cython"|' setup.py
  sed -i 's|../../vendor/http-parser/http_parser.h|/usr/include/http_parser.h|' $_pkgname/parser/cparser.pxd

  git rm vendor/http-parser

  git config --global protocol.file.allow always

  git submodule init
  git config submodule.vendor/llhttp.url "$srcdir"/llhttp
  git submodule update
}

pkgver() {
  cd $_pkgname
  git describe --tags | sed 's/^v//'
}

build() {
  cd $_pkgname
  python setup.py build build_ext --use-system-http-parser
}

package() {
  cd $_pkgname
  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
  install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

# vim: ts=2 sw=2 et:
