# Maintainer: Timo Teräs <timo.teras@iki.fi>
_luaversions="5.1 5.2 5.3"
pkgname=lua-ldbus
pkgver=20150430
_commitid=9f6db626600eb7e04000368da947e0c5cd175fb5
pkgrel=2
pkgdesc="Lua D-Bus bindings"
url="https://github.com/daurnimator/ldbus"
arch="all"
license="MIT"
depends=""
subpackages=""
makedepends="dbus-dev"
install=""
source="ldbus-$pkgver.tar.gz::https://github.com/daurnimator/ldbus/archive/$_commitid.tar.gz
	0001-fix-lua_State-usage-for-callbacks.patch
	fix-makefile.patch
	"

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

_builddir="$srcdir"/ldbus-$_commitid/src
prepare() {
	local i
	cd "$srcdir"/ldbus-$_commitid
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	for _i in $_luaversions; do
		msg "Build for Lua $_i"
		make LUA_VERSION=$_i LUA_LIBDIR="$pkgdir"/usr/lib/lua/$_i all || return 1
	done
}

package() {
	cd "$_builddir"
	for _i in $_luaversions; do
		msg "Install for Lua $_i"
		make LUA_VERSION=$_i LUA_LIBDIR="$pkgdir"/usr/lib/lua/$_i install || return 1
	done
	rm -f "$pkgdir"/usr/lib/*.la
}

_split() {
	local d= _ver=$1
	pkgdesc="$pkgdesc - for Lua $_ver"
	depends=
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	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="0688d0bc571483a28341c53acc57ded9  ldbus-20150430.tar.gz
4bc07c735305000e6c4498e001665a0d  0001-fix-lua_State-usage-for-callbacks.patch
e6c33b8dbe4baa5575458f793ff67515  fix-makefile.patch"
sha256sums="3f8eabe8a7f73214bc774faa428d1bb3a4a4b8c0f6712c2fffa4646b71020cfd  ldbus-20150430.tar.gz
0aefb31c23b2b0da83d3722a5fd84fe65f5f96719bbea4549e5dd5287386b44a  0001-fix-lua_State-usage-for-callbacks.patch
136f38538d4c63288baebee869bf1cd8cc17e5370f0bf07cac71e30ae110d88c  fix-makefile.patch"
sha512sums="cab609800b3d67bb6fd533b62179345430e822ad30c711bc8f35cb079353108339288eb7adc374a681bb4f42b66cfd025cff4591fd9cbef045acad41e72d3073  ldbus-20150430.tar.gz
77d631acfa58ad28868a7ccd8a3ec3f5e44357f0243cdf373037955b5961bc84094790d137a05a47b3cd26665d5afcfc1491b361dd895797fe317fe7e947a252  0001-fix-lua_State-usage-for-callbacks.patch
ee9dfa64598cb856602d70f7d15b4783423799ed428ed3c2f6f28d1085dd14c34204cd38fa390574b982237858d0c8970f5f517827310d780afe2bd32e496380  fix-makefile.patch"
