# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=keystone
pkgver=0.9.1
pkgrel=1
pkgdesc="Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings"
url="http://www.keystone-engine.org"
arch="all"
license="custom"
depends=""
makedepends="cmake python3-dev"
install=""
subpackages="$pkgname-dev $pkgname-doc $pkgname-python"
source="$pkgname-$pkgver.tar.gz::https://github.com/keystone-engine/$pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	mkdir -p build-shared && cd build-shared
	cmake -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=ON \
      -G "Unix Makefiles" ..
	cd ..
	make -C build-shared || return 1
}

package() {
	cd "$builddir"
	make -C build-shared DESTDIR="$pkgdir" install
}

doc() {
	pkgdesc="Documentation and samples for $pkgname"
	arch="noarch"
	cd "$builddir"
	mkdir -p "${subpkgdir}/usr/share/doc/${pkgname}"
	mv samples "${subpkgdir}/usr/share/doc/${pkgname}"
}

python() {
	pkgdesc="$pkgname python3 bindings"
	depends="python3 keystone"
	arch="noarch"
	cd "$builddir"/bindings/python
	python3 setup.py build
	python3 setup.py install --prefix=/usr --root="$subpkgdir"
}

md5sums="966e0395a3733f68518a2833e64134c1  keystone-0.9.1.tar.gz"
sha256sums="e9d706cd0c19c49a6524b77db8158449b9c434b415fbf94a073968b68cf8a9f0  keystone-0.9.1.tar.gz"
sha512sums="3bd9c3793d5862a0a8628b52da381625e62445f661dbd5ed715723e7d9db01ce3f9586e5ca0a5cc71e8ceb6c912050f5c28e3ccd540e72c8abcfd2f0d1bbae17  keystone-0.9.1.tar.gz"
