# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
setvar pkgname = 'lua-dromozoa-utf8'
setvar _pkgname = 'dromozoa-utf8'
setvar pkgver = '1.3'
setvar pkgrel = '1'
setvar pkgdesc = ""Lua 5.3 compatible pure-Lua UTF-8 implementation""
setvar url = ""https://github.com/dromozoa/dromozoa-utf8/""
setvar arch = ""all""
setvar license = ""GPL3""
setvar depends = """"
setvar checkdepends = """"
setvar source = ""$pkgname-$pkgver.tar.gz::https://github.com/dromozoa/$_pkgname/archive/v$pkgver.tar.gz""
setvar builddir = ""$srcdir/$_pkgname-$pkgver""

# luajit is not available for selected arches
case (CARCH) {
	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 {
	local out
	cd $builddir

	local lver; for lver in $_luaversions $_luajit {
		msg "Testing on lua$lver"
		setvar out = $(lua$lver test.lua test.exp 2>&1) || do {
			echo "Tests failed, printing last 30 lines of the output..."
			printf '%s\n' $out | tail -n 30
			return 1
		}
	}
}

proc package {
	mkdir -p $pkgdir
}

proc _subpackage {
	local lver="${subpkgname:3:3}"
	setvar pkgdesc = ""$pkgdesc (for Lua $lver)""
	setvar depends = ""lua$lver""
	setvar 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 dromozoa "$lmod_dir"/

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

setvar sha512sums = ""c1894692f80cc2204683b7a8f540d59b1a23447bc61492acef3c6bac7f50884ca39b0b372e2d56f4473b92a8263da2c705243e7c341eea43583578964bedd4f4  lua-dromozoa-utf8-1.3.tar.gz""