# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-argparse
_pkgname=argparse
pkgver=0.5.0
pkgrel=1
pkgdesc="Feature-rich command line parser for Lua"
url="https://github.com/mpeterv/argparse"
arch="noarch"
license="MIT"
depends=""
checkdepends="lua-busted"
subpackages=""
source="$pkgname-$pkgver.tar.gz::https://github.com/mpeterv/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

# luajit is not available for selected arches
case "$CARCH" in
	s390x) _luajit="";;
	*) checkdepends="$checkdepends luajit" _luajit="jit";;
esac

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

check() {
	cd "$builddir"
	mkdir .bin

	local lver; for lver in $_luaversions $_luajit; do
		msg "Testing on lua$lver"

		ln -sf /usr/bin/lua$lver .bin/lua
		LUA_PATH="$builddir/src/?.lua;;" \
			PATH="$builddir/.bin:$PATH" \
			lua /usr/bin/busted
	done
}

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

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

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

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

sha512sums="29ab0d53a985fee135ff8f4237129df338b9fcea3da7c10450bab8de4f7fde64f96bf863c97dc403388c21551a66280049c6f49531c5ea483f3fa0801e685422  lua-argparse-0.5.0.tar.gz"
