# Template file for 'lua-lualdap'
pkgname=lua-lualdap
version=1.2.0
revision=1
build_style=gnu-makefile
hostmakedepends="pkg-config"
makedepends="lua51-devel lua52-devel lua-devel libldap-devel"
short_desc="LDAP bindings for Lua"
maintainer="John Regan <john@jrjrtech.com>"
license="MIT"
homepage="http://git.zx2cf.com/lualdap"
distfiles="http://git.zx2c4.com/lualdap/snapshot/lualdap-${version}.tar.xz"
checksum=126c50f013ebf329c1771ab4d489f5e6eb7b11d2a64412414f1c6bc6e8a69ed8
wrksrc="lualdap-${version}"

post_extract() {
	cd ${wrksrc}
	for p in ${FILESDIR}/*.patch; do
		patch -p0 -i "${p}"
	done
	mkdir -p lua51
	mv * lua51 || true
	cp -a lua51 lua52
	cp -a lua51 lua53
}

do_build() {
	for luaver in 5.1 5.2 5.3; do
		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})" \
		  ${makejobs}
	done
}

do_install() {
	for luaver in 5.1 5.2 5.3; do
		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="${PKGDESTDIR}" \
	  	  install
	done
	vlicense "${FILESDIR}/COPYING"
}

lua51-lualdap_package() {
	short_desc+=" - Lua 5.1"
	pkg_install() {
		vmove usr/lib/lua/5.1
		vlicense "${FILESDIR}/COPYING"
	}
}

lua52-lualdap_package() {
	short_desc+=" - Lua 5.2"
	pkg_install() {
		vmove usr/lib/lua/5.2
		vlicense "${FILESDIR}/COPYING"
	}
}
