# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_pkgname=lyaml
pkgname=lua-$_pkgname
pkgver=6.2
pkgrel=3
pkgdesc="LibYAML binding for Lua"
url="https://github.com/gvvaughan/lyaml"
arch="all"
license="MIT"
depends=""
makedepends="yaml-dev"
subpackages=""
replaces="lua-yaml"
source="$_pkgname-$pkgver.tar.gz::https://github.com/gvvaughan/lyaml/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-$_pkgname:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		cp -r "$builddir" "$srcdir"/build-$lver
		cd "$srcdir"/build-$lver
		lua$lver build-aux/luke
	done
}

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

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

	cd "$srcdir"/build-$lver

	lua$lver build-aux/luke PREFIX="$subpkgdir"/usr install
	rm -Rf "$subpkgdir"/usr/share/doc

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

sha512sums="357a89f096decb8b6ad89c2b0ffd93c27d424a9a2ba65f48370c585f7ffeff3f41addc3fe8785b3d8e81405a6f08a3855c4d8ba9d641b1f551fab269c3e87b51  lyaml-6.2.tar.gz"
