# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
setvar pkgname = 'lua-toml'
setvar pkgver = '1.0.1'
setvar pkgrel = '0'
setvar pkgdesc = ""TOML decoder/encoder for Lua""
setvar url = ""https://github.com/jonstoler/lua-toml""
setvar arch = ""noarch""
setvar license = ""Happy""
setvar depends = """"
setvar checkdepends = ""lua-busted""
setvar source = ""$pkgname-$pkgver.tar.gz::https://github.com/jonstoler/$pkgname/archive/v$pkgver.tar.gz""
setvar builddir = ""$srcdir/$pkgname-$pkgver""

# luajit is not available for selected arches
case (CARCH) {
	ppc64le | s390x { setvar _luajit = """"}
	* { setvar checkdepends = ""$checkdepends luajit"," _luajit = ""jit""}
}

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

proc check {
	cd $builddir

	local lver; for lver in $_luaversions $_luajit {
		msg "Testing on lua$lver"
		lua$lver /usr/bin/busted || return 1
	}
}

proc package {
	mkdir -p $pkgdir
}

proc _subpackage {
	local lver="${subpkgname:3:3}"
	setvar pkgdesc = ""$pkgdesc $lver""
	setvar depends = ""lua$lver""
	setvar install_if = ""$pkgname=$pkgver-r$pkgrel lua$lver""
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-0"

	cd $builddir
	install -m 644 -D toml.lua "$subpkgdir"/usr/share/lua/$lver/toml.lua

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

setvar sha512sums = ""84b8187e24e3e03b31bd9662faceaf6e59e4f15ad63d17a077ed158ee73710297be4ee0d1e503c2d06304bbca100bcf6ff0b92ef58d7accd834e014ac4972add  lua-toml-1.0.1.tar.gz""