# Template file for 'lua54-luadbi'
pkgname=lua54-luadbi
version=0.5
revision=5
create_wrksrc="yes"
makedepends="lua51-devel lua52-devel lua53-devel lua54-devel sqlite-devel
 postgresql-libs-devel libmariadbclient-devel"
_desc="Lua database interface library"
short_desc="${_desc} (5.4.x)"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://code.google.com/archive/p/luadbi/"
distfiles="https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/luadbi/luadbi.$version.tar.gz"
checksum=49116458dd80052536bf5d7e2b2a1f5a0fa42a671ce77f1cb7355ef7faeb331e

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

_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

	cd ${wrksrc}/lua54
	make CC="$CC" AR="$AR" RANLIB="$RANLIB" CFLAGS="${_common_cflags} -I${XBPS_CROSS_BASE}/usr/include/lua5.4" ${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/

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

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

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

lua53-luadbi_package() {
	short_desc="${_desc} (5.3.x)"
	pkg_install() {
		vmove usr/lib/lua/5.3
		vmove usr/share/lua/5.3
		vlicense ${wrksrc}/lua53/COPYING
	}
}

lua-luadbi_package() {
	depends="lua53-luadbi>=${version}_${revision}"
	short_desc="${_desc} (5.3.x) (transitional dummy package)"
	metapackage=yes
}
