# Contributor: Mika Havela <mika.havela@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3"
pkgname=lua-expat
_name=expat
pkgver=1.3.0
pkgrel=2
pkgdesc="SAX XML parser based on the Expat library"
url="https://matthewwild.co.uk/projects/luaexpat/"
arch="all"
license="MIT"
depends=""
makedepends="expat-dev"
install=
subpackages=

for _i in $_luaversions; do
	makedepends="$makedepends lua${_i}-dev"
	subpackages="$subpackages lua${_i}-$_name:_split${_i/./}"
done

source="http://matthewwild.co.uk/projects/luaexpat/luaexpat-$pkgver.tar.gz"

_builddir="$srcdir"/luaexpat-1.3.0
build() {
	cd "$srcdir"
	for _i in $_luaversions; do
		cp -r "$_builddir" "$srcdir"/build-$_i || return 1
		cd "$srcdir"/build-$_i
		make LUA_V=$_i || return 1
	done
}

package() {
	cd "$srcdir"
	for _i in $_luaversions; do
		(cd "$srcdir"/build-$_i && make install LUA_V=$_i \
                        DESTDIR="$pkgdir") \
			|| return 1
	done
}

_split() {
	local d= _ver=$1
	pkgdesc="$pkgdesc for Lua $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/ || return 1
		fi
	done
}

for _i in $_luaversions; do
	eval "_split${_i/./}() { _split $_i; }"
done

md5sums="3c20b5795e7107f847f8da844fbfe2da  luaexpat-1.3.0.tar.gz"
sha256sums="d060397960d87b2c89cf490f330508b7def1a0677bdc120531c571609fc57dc3  luaexpat-1.3.0.tar.gz"
sha512sums="91884653310e2dc89ade6d1653875ac8607640a21853d3ccb1fd0f833812e41981fad5c40101732ec249104d2c50c9a332208d1e44423b8428065a223c60b4ae  luaexpat-1.3.0.tar.gz"
