# Template file for 'lua54-unbound'
pkgname=lua54-unbound
version=1.0.0
revision=1
hostmakedepends="pkg-config"
makedepends="unbound-devel"
depends="lua54"
_desc="Binding to libunbound for Lua"
short_desc="${_desc} (5.4.x)"
maintainer="Luca Matei Pintilie <luca@lucamatei.com>"
license="MIT"
homepage="https://www.zash.se/luaunbound.html"
distfiles="https://code.zash.se/dl/luaunbound/luaunbound-${version}.tar.gz"
checksum=6de45aa64c21cf0ecbccb734b7c1eda8873a6135bbe142fbf353f772a90750d3

_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/./}"
		make \
			LD="$CC" \
			CC="$CC" \
			LUA_PC="${_lua_version}" \
			${makejobs}
	done
}

do_install() {
	for _lua_version in $_lua_versions; do
		cd "${wrksrc}/${_lua_version/./}"
		vinstall lunbound.so 755 usr/lib/lua/${_lua_version#lua}/
	done
	vlicense LICENSE
}

lua51-unbound_package() {
	depends="lua51"
	short_desc="${_desc} (5.1.x)"
	pkg_install() {
		vmove usr/lib/lua/5.1
		vlicense ${wrksrc}/lua51/LICENSE
	}
}

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

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