# Template file for 'lua-luadbi'
pkgname=lua-luadbi
version=0.5
revision=1
makedepends="lua-devel lua51-devel lua52-devel sqlite-devel postgresql-libs-devel libmysqlclient-devel"
_desc="Lua database interface library"
short_desc="${_desc} - Lua 5.3"
maintainer="John Regan <john@jrjrtech.com>"
license="MIT"
homepage="http://luadbi.googlecode.com/"
distfiles="${homepage}files/luadbi.$version.tar.gz"
wrksrc="${pkgname#lua-}-${version}"
checksum=49116458dd80052536bf5d7e2b2a1f5a0fa42a671ce77f1cb7355ef7faeb331e
create_wrksrc="yes"

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

_common_cflags="-pedantic -Wall -O2 -shared -fpic -I${XBPS_CROSS_BASE}/usr/include/mysql -I${XBPS_CROSS_BASE}/usr/include/postgresql/server -I."

if [[ -n "${CROSS_BUILD}" ]]; then
	_common_cflags+=" -I${XBPS_CROSS_BASE}/usr/include"
fi

do_build() {
	cd ${wrksrc}/lua51
	make CC="$CC" AR="$AR" RANLIB="$RANLIB" CFLAGS="${_common_cflags} -I${XBPS_CROSS_BASE}/usr/include/lua5.1" ${makejobs} free

	cd ${wrksrc}/lua52
	make CC="$CC" AR="$AR" RANLIB="$RANLIB" CFLAGS="${_common_cflags} -I${XBPS_CROSS_BASE}/usr/include/lua5.2" ${makejobs} free

	cd ${wrksrc}/lua53
	make CC="$CC" AR="$AR" RANLIB="$RANLIB" CFLAGS="${_common_cflags} -I${XBPS_CROSS_BASE}/usr/include/lua5.3" ${makejobs} free

}

do_install() {
	cd ${wrksrc}/lua51
	for lib in *.so; do
		vinstall ${lib} 755 usr/lib/lua/5.1
	done
	vinstall DBI.lua 644 usr/share/lua/5.1/

	cd ${wrksrc}/lua52
	for lib in *.so; do
		vinstall ${lib} 755 usr/lib/lua/5.2
	done
	vinstall DBI.lua 644 usr/share/lua/5.2/

	cd ${wrksrc}/lua53
	for lib in *.so; do
		vinstall ${lib} 755 usr/lib/lua/5.3
	done
	vinstall DBI.lua 644 usr/share/lua/5.3/
	vlicense COPYING
}

lua52-luadbi_package() {
	short_desc="${_desc} - Lua 5.2"
	pkg_install() {
		vmove usr/lib/lua/5.2
		vmove usr/share/lua/5.2
		vlicense ${wrksrc}/lua52/COPYING
	}
}

lua51-luadbi_package() {
	short_desc="${_desc} - Lua 5.1"
	pkg_install() {
		vmove usr/lib/lua/5.1
		vmove usr/share/lua/5.1
		vlicense ${wrksrc}/lua51/COPYING
	}
}
