# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-dromozoa-utf8
_rockname=dromozoa-utf8
pkgver=1.18
pkgrel=0
pkgdesc="Lua 5.3 compatible pure-Lua UTF-8 implementation"
url="https://github.com/dromozoa/dromozoa-utf8/"
arch="noarch"
license="GPL-3.0-or-later"
source="$pkgname-$pkgver.tar.gz::https://github.com/dromozoa/$_rockname/archive/v$pkgver.tar.gz
	test.sh.patch
	"
builddir="$srcdir/$_rockname-$pkgver"

case "$CARCH" in
	ppc64le|riscv64|loongarch64) checkdepends=""; _luajit="";;
	*) checkdepends="luajit"; _luajit="jit";;
esac

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	checkdepends="$checkdepends lua$_v"
	# for backward compatibility (Alpine <3.18)
	provides="$provides lua$_v-${pkgname#lua-}=$pkgver-r$pkgrel"
done

check() {
	local lver; for lver in $_luaversions $_luajit; do
		msg "Testing on lua$lver"
		./test.sh lua$lver
	done
}

package() {
	local lmod_dir="$pkgdir/usr/share/lua/common"
	local rockdir="$pkgdir/usr/lib/luarocks/rocks-common/$_rockname/$pkgver-1"

	mkdir -p "$lmod_dir"
	cp -r dromozoa "$lmod_dir"/

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

sha512sums="
819cc7c425f0ca126af42c7c9f7fccae42c008080ebed6f01653db253fd45272cfcc4dfba155d4a0c149dee8df2f4dea7072918bf4620258f65e874dbebcedcc  lua-dromozoa-utf8-1.18.tar.gz
5b24a1aef26a934aea9e116af857a0323d5e0b639f2d5ff66b6cc5310bf9c2315855f3034e3c5e40bda0e91f970ba90ebdd97c6eb08b2f6683b131fe5ba2ecb5  test.sh.patch
"
