# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=micropython
pkgver=1.9.3
pkgrel=0
pkgdesc="A lean and efficient Python implementation for MCUs and constrained systems"
url="http://www.micropython.org/"

# ../py/persistentcode.c:397:2: error: #error mp_raw_code_save_file not implemented for this platform
arch="x86 x86_64 armhf ppc64le"

license="MIT"
depends=""
makedepends="libffi-dev python3"
subpackages="$pkgname-cross"
source="${pkgname}-${pkgver}.tar.gz::https://github.com/${pkgname}/${pkgname}/archive/v${pkgver}.tar.gz
	0000-unix-mpconfigport.patch
	python3.patch
	"
builddir="${srcdir}/${pkgname}-${pkgver}"

build() {
	cd "$builddir"
	make -C ports/unix PYTHON=python3
}

check() {
	cd "$builddir"

	# ffi callback fails on kernel with PaX
	rm tests/unix/ffi_callback.py

	make -C ports/unix test PYTHON=python3
}

package() {
	cd "$builddir"
	mkdir -p "${pkgdir}/usr/bin"
	install -m755 ports/unix/micropython "${pkgdir}/usr/bin/micropython"
}

cross() {
	pkgdesc="Compile micropython code to bytecode, which can be transfered to MCUs"
	cd "$builddir"
	mkdir -p "${subpkgdir}/usr/bin"
	install -m755 mpy-cross/mpy-cross "${subpkgdir}/usr/bin/mpy-cross"
}

sha512sums="d276dc9a300e400f5fd5742bfc8c641c0af2d3b7f3ae9221b811100d85e9c2a6c6c558775183c58dd4be39a31284c596c0e98c9bb2c8e60ce4cf0d83434d0a47  micropython-1.9.3.tar.gz
4c1de6a6477453e846998565402c69d1dd716cf692a3bb55aa16b6991722a94d8364c05f0603b981a7dd9e9af577a3f46910a60d501513af547ebbf3ed574711  0000-unix-mpconfigport.patch
8dbdc52e09f70b5eea461257ebc00031ab9d2c91a9bdbd7522e4ffd1eddddcd0dab3a171361e776543abca827a2f5d6ad01b06c10c8635db861bf79bfa065338  python3.patch"
