# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=janet
pkgver=1.35.2
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
	musl-strerror.patch"

# 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="
6a259bd3e2e88b0183d164b33991bb248f5fc1b340e4ae04184328b89477932b92f490c9a813e224a91e229865e908f59fc3f3e1a3a1dafc84685e2c16a09696  janet-1.35.2.tar.gz
21e8873b339f21c5b2fe1e4c166ffe9a6e7def18138d9c8a595ba44bf2867525d9e3e058183d15d24cfc7201128aa3c8a47dc59900d288e2018fa8665e06a969  musl-strerror.patch
"
