# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lua-mosquitto
pkgver=0.2
pkgrel=1
pkgdesc="Bindingd to libmosquitto for Lua"
url="https://github.com/flukso/lua-mosquitto"
arch="all"
license="MIT"
depends=""
makedepends="mosquitto-dev"
subpackages=""
source="$pkgname-$pkgver.tar.gz::https://github.com/flukso/$pkgname/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#lua-}:_package"
done

prepare() {
	default_prepare || return 1

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver" || return 1
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make -C "$builddir-$lver" LUAPKGC=lua$lver || return 1
	done
}

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

_package() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$pkgname/$pkgver-1"

	cd "$builddir-$lver"
	make install DESTDIR="$subpkgdir" \
		LUA_LIBDIR=/usr/lib \
		LUAPKGC=lua$lver

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

md5sums="4954191018ad2cfed6273e2547750e6c  lua-mosquitto-0.2.tar.gz"
sha256sums="1468e82e3ddb52fe68d042b2b5ae704f3a794184165f59743acc8ff6ed805703  lua-mosquitto-0.2.tar.gz"
sha512sums="02a96ede4ac594ef9bcb838816f55e6f4c5fe8daaad21e2fd8d123a307f326ec599f42fe6e56527e0da195883c73fec945fde77bc07f69f85840871a5f1c9490  lua-mosquitto-0.2.tar.gz"
