# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: M0Rf30

pkgbase=capstone
pkgname=(
  capstone
  python-capstone
)
pkgver=5.0.7
pkgrel=2
pkgdesc='Lightweight multi-platform, multi-architecture disassembly framework'
arch=(x86_64 aarch64)
url='https://www.capstone-engine.org/index.html'
license=(BSD-3-Clause)
makedepends=(
  glibc
  python
  python-build
  python-installer
  python-setuptools
  python-wheel
)
source=("https://github.com/aquynh/capstone/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('e09788d7dfca281f8f3773323d72e1157df777878d59ace6a8996495d505dec10051ce002f473fa5ff8aa60d5e6bb4cff5e55faffb074643cae7c4515e324994')
b2sums=('6e1d7d5aed9c1ef976aa97d7cf1363adfb41287bb8b26a5ae4ce5d0dc6ec318bdce551668486848a5f4005009c11b80ced77be911ab7ae79649923068eb646fe')

build() {
  cd $pkgbase-$pkgver
  CFLAGS+=" $CPPFLAGS -ffat-lto-objects"
  make V=1

  cd bindings/python
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgbase-$pkgver
  make check
}

package_capstone() {
  depends=(glibc)
  provides=(libcapstone.so)
  cd $pkgbase-$pkgver
  make DESTDIR="$pkgdir" install
  install -vDm 644 -t "$pkgdir/usr/share/doc/$pkgname" docs/README
  install -vDm 644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.TXT
}

package_python-capstone() {
  depends=(
    capstone
    glibc
    python
  )
  cd $pkgbase-$pkgver/bindings/python
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 -t "$pkgdir/usr/share/licenses/$pkgname" ../../LICENSE.TXT
}
