# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=lua-crypt
pkgver=1.1.0
pkgrel=0
pkgdesc="A crypt(3)-style module for Lua. Brings its own implementations, entirely independent of your local libc"
url="https://github.com/jprjr/lua-crypt"
arch="all"
license="MIT"
options="!check" # make check not implemented
source="lua-crypt-$pkgver.tar.gz::https://github.com/jprjr/lua-crypt/archive/$pkgver.tar.gz"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_package"
done

prepare() {
	default_prepare

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

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		cd "$builddir-$lver"
		make LUA=lua$lver
	done
}

package() {
	install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}

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

	cd "$builddir-$lver"
	install -Dm644 crypt.lua -t "$subpkgdir"/usr/share/lua/$lver/
	install -Dm644 crypt/core.so -t "$subpkgdir"/usr/lib/lua/$lver/crypt/

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

sha512sums="
9669e188ce13a4a129e30ebe48687c510c8724a31c1d5d713946409ea53752336f3735df6d1d400257c19e5029914987aeaaa636fb7c26ec06ece6ea2f01cddc  lua-crypt-1.1.0.tar.gz
"
