# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=teal
_rockname=tl
pkgver=0.15.3
_pkgver="$pkgver-1"
pkgrel=0
pkgdesc="The compiler for Teal, a typed dialect of Lua"
url="https://github.com/teal-language/tl"
arch="noarch"
license="MIT"
_luaver=5.4
depends="
	lua$_luaver
	lua-filesystem
	lua-argparse
	"
checkdepends="
	lua-busted
	lua-cjson
	"
provides="lua-$_rockname=$pkgver-r$pkgrel"
source="https://github.com/teal-language/tl/archive/v$pkgver/teal-$pkgver.tar.gz
	use-cjson.patch
	spec-dont-require-compat53.patch
	"
builddir="$srcdir/$_rockname-$pkgver"

prepare() {
	default_prepare

	sed -i "s|/usr/bin/env lua\b|&$_luaver|" \
		tl spec/lexer/hashbang_spec.lua
}

build() {
	make selfbuild
}

check() {
	busted-$_luaver --suppress-pending
}

package() {
	local rockdir="$pkgdir/usr/lib/luarocks/rocks-common/$_rockname/$_pkgver"

	install -D -m755 tl -t "$pkgdir"/usr/bin/
	install -D -m644 tl.lua tl.tl -t "$pkgdir"/usr/share/lua/common/

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
38a93df0adc579e31f801ba08200113fb4fd41da80289f282ab3fb83ede72f3024c1cc754bba6df246c897c18e50dfb3767fe99ef4d755245e41dcae11fd2bed  teal-0.15.3.tar.gz
4e0f1fb043f556b5dc7457cbd22ddbe7574984976659d2055d9097635a2b238709d057596211583f484a72e6d8553c025c2d3315f789efa5fcc9c3abf94a8642  use-cjson.patch
cb7f6175e6f1d0b4dfaf6d029c64df15577573cb8f2387f5b496ca13ee427e964ee402b12322275a0b0e4f7b185382a13b98b707efcca7ebdf2e2ceac8b2ad74  spec-dont-require-compat53.patch
"
