# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-luassert
_pkgname=luassert
pkgver=1.7.10
pkgrel=1
pkgdesc="Assertion library for Lua"
url="https://github.com/Olivine-Labs/luassert"
arch="noarch"
license="MIT"
subpackages=""
source="$pkgname-$pkgver.tar.gz::https://github.com/Olivine-Labs/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
# This module needs lua-busted to run tests, but lua-busted depends on
# lua-luassert and we wanna avoid circular dependencies.
options="!check"

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver lua$lver-say"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local destdir="$subpkgdir/usr/share/lua/$lver/$_pkgname"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir"
	mkdir -p "$destdir"
	cp -r src/* "$destdir"/

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

sha512sums="2d5ca354b5f7b971f0d3420c305d921143cd7f9e1a6f4559cb466b833886a00a045e7b7c594bd9ec3c929b3d5bb8a7a4a6de75a6599e5cba7614b7652061bf05  lua-luassert-1.7.10.tar.gz"
