# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
_luaversions="5.1 5.2 5.3"
pkgname=lua-lunix
_pkgname=lunix
pkgver=20150923
pkgrel=1
pkgdesc="Comprehensive Unix API Module for Lua"
url="https://github.com/wahern/lunix"
arch="all"
license="MIT"
depends=""
makedepends=""
subpackages=""
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-$_pkgname:_package"
done
source="$pkgname-$pkgver.tar.gz::https://github.com/wahern/lunix/archive/tag-$pkgver.tar.gz
	fix-musl-siglist.patch"
builddir="$srcdir/$_pkgname-tag-$pkgver"

build() {
	cd "$builddir"

	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make all$lver || return 1
	done
}

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

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

	cd "$builddir"
	make prefix="/usr" DESTDIR="$subpkgdir" install$lver

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

md5sums="b7341c5f4a5cf5bb0ac1b9fdc3eb174a  lua-lunix-20150923.tar.gz
479fd7d993059e6ea657c0ac4ed5c510  fix-musl-siglist.patch"
sha256sums="1c395d1fb46813effd9348708ddd240bd7c39dc68d73216fae184f60fd6d8517  lua-lunix-20150923.tar.gz
39151eefb5003b8919bb6c78d905019fe2ace51b5b4c40587dcf15f2ab3532c5  fix-musl-siglist.patch"
sha512sums="cf9fb83ebf99387b79de7afb741f6b8a496911c981be1fd5d51842f2e42c5accc9415e9a026bc17e05b1cade14782f123f6508f8024a8b146e726d26ea8cbdec  lua-lunix-20150923.tar.gz
4e797cb6a6dc353f0082315b3141862ac8c640bc4b21e856c66e23b24322984b1864dd5df1972fd676c47038080d5122c76a76af1dbc1c1f71c068a3a32535b9  fix-musl-siglist.patch"
