# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=lua-luatz
_pkgname=${pkgname/lua-/}
pkgver=0.4.1
_ver=${pkgver//./-}
_pkgver=${_ver/-/.}
pkgrel=0
pkgdesc="Time, Date and Timezone library for lua"
url="https://daurnimator.github.io/luatz/"
arch="noarch"
license="MIT"
checkdepends="lua-busted luajit"
depends="tzdata"
# /etc/locatime is not installed by default
options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/daurnimator/luatz/archive/v$_pkgver.tar.gz"
builddir="$srcdir"/$_pkgname-$_pkgver

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

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

check() {
	local lver; for lver in $_luaversions jit; do
		msg "Testing on lua$lver"
		lua$lver /usr/bin/busted
	done
}

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

	cd $builddir
	mkdir -p "$lmod_dir"
	cp -r $_pkgname "$lmod_dir"/

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

sha512sums="87e53afa85aa66cc0359d9581eb3dd9974f6ceb11cb57b0bfc6745d9bb1b6dbc90520fb6834e5de85b7fc46ff44c5d35dfd7136547a1973585f8cbf8707b45d1  lua-luatz-0.4.1.tar.gz"
