# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=janet
pkgver=1.36.0
pkgrel=0
pkgdesc="Dynamic Lisp dialect and bytecode VM"
url="https://janet-lang.org/"
license="MIT"
arch="all"
makedepends="meson"
subpackages="$pkgname-static $pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/janet-lang/janet/archive/v$pkgver.tar.gz"

# Bump tic-80 when upgrading/rebuilding.

# secfixes:
#   1.22.0-r0:
#     - CVE-2022-30763

build() {
	abuild-meson \
		-Db_lto=true \
		-Depoll=true \
		-Dos_name="alpine" \
		. output
	meson compile -C output
}

check() {
	# Disable certain tests on certain carches
	case "$CARCH" in
		s390x)
			#suite-buffer uint16/32 & float32/64 tests fail
			_tests=$(meson test --list -C output | sed '/suite-buffer.janet/d')
		;;
		# Run all tests unless otherwise directed.
		*)
			_tests=$(meson test --list -C output)
		;;
	esac

	meson test --print-errorlogs --no-rebuild -C output $_tests
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	install -dm755 "$pkgdir"/usr/share/doc/janet
	cp -a examples "$pkgdir"/usr/share/doc/janet
}

sha512sums="
1cfc24cfb949839d9aa36952e3746473a963c32344e9f05e3250671f4a6f8d244fcbb26d5faf09b296b12aacf721b5287eaf84ef8b7d8b93502e2d38093cb2b8  janet-1.36.0.tar.gz
"
