# Template file for 'luarocks-lua53'
pkgname=luarocks-lua53
version=3.11.0
revision=1
build_style=configure
configure_args="
 --prefix=/usr
 --sysconfdir=/etc
 --lua-version=5.3
 --with-lua-include=/usr/include/lua5.3"
hostmakedepends="lua53-devel"
depends="lua53 curl unzip"
_desc="Package management for Lua modules"
short_desc="${_desc} (5.3.x)"
maintainer="Duncaen <duncaen@voidlinux.org>"
license="MIT"
homepage="https://luarocks.org/"
changelog="https://github.com/luarocks/luarocks/wiki/Release-history"
distfiles="https://luarocks.org/releases/luarocks-${version}.tar.gz"
checksum=25f56b3c7272fb35b869049371d649a1bbe668a56d24df0a66e3712e35dd44a6
alternatives="
 luarocks:luarocks:/usr/bin/luarocks-5.3
 luarocks:luarocks-admin:/usr/bin/luarocks-admin-5.3"

conf_files="/etc/luarocks/config-5.3.lua"

post_extract() {
	vsed -i -e 's;\(unzip_found=\).*;\1/usr/bin/unzip;' configure
}

post_build() {
	for lv in 5.1 5.2 5.4; do
		make LUA_VERSION=$lv LUA_INTERPRETER=lua$lv \
			 LUA_INCDIR=/usr/include/lua$lv ./build/config-$lv.lua
	done
}

pre_install() {
	vsed -i -e 's;env lua;env lua5.3;g' src/bin/luarocks{,-admin}
}

post_install() {
	vlicense COPYING

	vmkdir usr/bin
	for lv in 5.1 5.2 5.4; do
		make DESTDIR="${DESTDIR}" LUA_VERSION=$lv install-config
		make DESTDIR="${DESTDIR}" LUA_VERSION=$lv install-config

		echo "#!/bin/sh" > ${DESTDIR}/usr/bin/luarocks-$lv
		echo "exec luarocks-5.3 --lua-version $lv \"\$@\"" >> ${DESTDIR}/usr/bin/luarocks-$lv
		chmod +x ${DESTDIR}/usr/bin/luarocks-$lv

		echo "#!/bin/sh" > ${DESTDIR}/usr/bin/luarocks-admin-$lv
		echo "exec luarocks-admin-5.3 --lua-version $lv \"\$@\"" >> ${DESTDIR}/usr/bin/luarocks-admin-$lv
		chmod +x ${DESTDIR}/usr/bin/luarocks-admin-$lv
	done

	mv ${DESTDIR}/usr/bin/luarocks{,-5.3}
	mv ${DESTDIR}/usr/bin/luarocks-admin{,-5.3}
}

luarocks-lua54_package() {
	short_desc="${_desc} (5.4.x)"
	depends="${sourcepkg}>=${version}_${revision} lua54"
	conf_files="/etc/luarocks/config-5.4.lua"
	alternatives="
	 luarocks:luarocks:/usr/bin/luarocks-5.4
	 luarocks:luarocks-admin:/usr/bin/luarocks-admin-5.4"
	pkg_install() {
		vmove usr/bin/luarocks-5.4
		vmove usr/bin/luarocks-admin-5.4
		vmove etc/luarocks/config-5.4.lua
	}
}

luarocks-lua52_package() {
	short_desc="${_desc} (5.2.x)"
	depends="${sourcepkg}>=${version}_${revision} lua52"
	conf_files="/etc/luarocks/config-5.2.lua"
	alternatives="
	 luarocks:luarocks:/usr/bin/luarocks-5.2
	 luarocks:luarocks-admin:/usr/bin/luarocks-admin-5.2"
	pkg_install() {
		vmove usr/bin/luarocks-5.2
		vmove usr/bin/luarocks-admin-5.2
		vmove etc/luarocks/config-5.2.lua
	}
}

luarocks-lua51_package() {
	short_desc="${_desc} (5.1.x)"
	depends="${sourcepkg}>=${version}_${revision} lua51"
	conf_files="/etc/luarocks/config-5.1.lua"
	alternatives="
	 luarocks:luarocks:/usr/bin/luarocks-5.1
	 luarocks:luarocks-admin:/usr/bin/luarocks-admin-5.1"
	pkg_install() {
		vmove usr/bin/luarocks-5.1
		vmove usr/bin/luarocks-admin-5.1
		vmove etc/luarocks/config-5.1.lua
	}
}

luarocks_package() {
	depends="luarocks-lua53>=${version}_${revision}"
	short_desc="${_desc} (5.3.x) (transitional dummy package)"
	build_style=meta
}
