# Template file for 'lua51-luasocket'
pkgname=lua51-luasocket
version=3.1.0
revision=2
build_style=gnu-makefile
depends="lua51"
_desc="Network support for the Lua language"
short_desc="${_desc} (5.1.x)"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://lunarmodules.github.io/luasocket/"
distfiles="https://github.com/lunarmodules/luasocket/archive/refs/tags/v${version}.tar.gz"
checksum=bf033aeb9e62bcaa8d007df68c119c966418e8c9ef7e4f2d7e96bddeca9cca6e

_lua_versions="lua5.1 lua5.2 lua5.3 lua5.4"
for _lua_version in $_lua_versions; do
	hostmakedepends+=" ${_lua_version/./}"
	makedepends+=" ${_lua_version/./}-devel"
done

post_extract() {
	mkdir -p lua51
	mv * lua51 || true
	cp -a lua51 lua52
	cp -a lua51 lua53
	cp -a lua51 lua54
}

do_build() {
	for _lua_version in $_lua_versions; do
		cd "${wrksrc}/${_lua_version/./}/src/"
		make \
			LD="$CC" \
			CC="$CC" \
			LUAINC="${XBPS_CROSS_BASE}/usr/include/${_lua_version}" \
			LUAVER="${_lua_version#lua}" \
			LUAV="${_lua_version#lua}" \
			PLAT=linux \
			${makejobs} \
			all-unix
	done
}

do_install() {
	for _lua_version in $_lua_versions; do
		cd "${wrksrc}/${_lua_version/./}/src/"
		make \
			STRIP=true \
			PREFIX=/usr \
			prefix=/usr \
			DESTDIR="${DESTDIR}" \
			LUAVER="${_lua_version#lua}" \
			LUAV="${_lua_version#lua}" \
			LDIR_linux="lib/lua/${_lua_version#lua}" \
			PLAT=linux \
			install
	done
}

post_install() {
	vlicense ./lua51/LICENSE
}

luasocket_package() {
	depends="lua51-luasocket>=${version}_${revision}"
	short_desc+=" (transitional dummy package)"
	build_style=meta
}

lua52-luasocket_package() {
	depends="lua52"
	short_desc="${_desc} (5.2.x)"
	pkg_install() {
		vmove usr/lib/lua/5.2
		vlicense ${wrksrc}/lua52/LICENSE
	}
}

lua53-luasocket_package() {
	depends="lua53"
	short_desc="${_desc} (5.3.x)"
	pkg_install() {
		vmove usr/lib/lua/5.3
		vlicense ${wrksrc}/lua53/LICENSE
	}
}

lua54-luasocket_package() {
	depends="lua54"
	short_desc="${_desc} (5.4.x)"
	pkg_install() {
		vmove usr/lib/lua/5.4
		vlicense ${wrksrc}/lua54/LICENSE
	}
}
