# Template file for 'lua54-lualdap'
pkgname=lua54-lualdap
version=1.2.5
revision=4
create_wrksrc=yes
build_style=gnu-makefile
hostmakedepends="pkg-config"
makedepends="lua51-devel lua52-devel lua53-devel lua54-devel libldap-devel"
_desc="LDAP bindings for Lua"
short_desc="${_desc} (5.4.x)"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://github.com/lualdap/lualdap"
distfiles="https://github.com/lualdap/lualdap/archive/v${version}.tar.gz"
checksum=3e028faa6a5798cf2f3d50b9853b9b3fb6eb562b62010747bd5b6f50b57bb1cc

post_extract() {
	mv lualdap-${version} lua
	cp -a lua lua51
	cp -a lua lua52
	cp -a lua lua53
	cp -a lua lua54
}

do_build() {
	for luaver in 5.1 5.2 5.3 5.4; do
		cd ${wrksrc}/lua${luaver//.}
		vsed -i "s|^LUA_VERSION.*|LUA_VERSION = ${luaver}|g" config
		make \
		  CC=$CC \
		  LD=$CC \
		  CFLAGS="$(pkg-config --cflags lua${luaver})" \
		  LDLIBS="$(pkg-config --libs lua${luaver}) -lldap" \
		  LUA_MODULES="$(pkg-config --variable=INSTALL_CMOD lua${luaver})" \
		  ${makejobs}
	done
}

do_install() {
	for luaver in 5.1 5.2 5.3 5.4; do
		vmkdir usr/lib/lua/$luaver
		cd ${wrksrc}/lua${luaver//.}
		make \
		  CC=$CC \
		  LD=$CC \
		  CFLAGS="$(pkg-config --cflags lua${luaver})" \
		  LDLIBS="$(pkg-config --libs lua${luaver}) -lldap" \
		  LUA_MODULES="$(pkg-config --variable=INSTALL_CMOD lua${luaver})" \
	  	  DESTDIR="${DESTDIR}" \
	  	  install
	done
	vlicense ${wrksrc}/lua54/LICENSE.md
}

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

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

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

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