# 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.9
pkgrel=1
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=('e4fe24002aed02cdbc0626dafee5211646e5da6a208c8ef99cd2d4f08beb0022999684af55cd80214aea4067fad427abb5ed5b1f5433b42a1f9047092481c039')
b2sums=('b9c35d4e1330e4f60e32f873310269dc63274e95cd9fe64742ffd311d7cddf573dc8ddfee1728ae37761254249d27a896a67af9f844fe37e7f7a99a791c98933')

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
}
