# Template file for 'micropython'
pkgname=micropython
version=1.28.0
revision=1
build_wrksrc=ports/unix
hostmakedepends="pkg-config python3"
makedepends="libffi-devel"
short_desc="Python implementation for microcontrollers and constrained systems"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://micropython.org/"
distfiles="https://github.com/micropython/micropython/releases/download/v${version}/micropython-${version}.tar.xz"
checksum=4e43c59657b8da33b4bc503509a827cc3ea6cb66c446475c57776cf4467ba215


case "$XBPS_TARGET_MACHINE" in
	arm*-musl) nopie=yes ;; # building with PIE creates text relocations in the binary
	ppc*) broken="missing nlr_push" ;;
esac

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	makedepends+=" musl-legacy-compat"
fi

pre_configure() {
	vsed -i 's|-Werror||;/^COPT =/d' Makefile
}

do_build() {
	case "$XBPS_TARGET_MACHINE" in
		i686*) CFLAGS_FOR_BUILD+=" -msse2" ;;
	esac
	CFLAGS= make -C ../../mpy-cross V=1 CFLAGS_EXTRA="${CFLAGS_FOR_BUILD}" STRIP= ${makejobs}
	make V=1 CC=${CC} CFLAGS_EXTRA="${CFLAGS}" \
		LDFLAGS_EXTRA="${LDFLAGS}" STRIP= ${makejobs} all
}

do_check() {
	if [ "$XBPS_WORDSIZE" -eq 32 ]; then
		rm -f ../../tests/extmod/time_mktime.py
		rm -f ../../tests/basics/int_64_basics.py
	fi
	make ${makejobs} test V=1
}

do_install() {
	vbin build-standard/micropython
	vlicense ../../LICENSE
}
