# Template file for 'LuaJIT'
pkgname=LuaJIT
version=2.0.4
revision=1
short_desc="A Just-In-Time Compiler for Lua"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://www.luajit.org"
license="MIT"
distfiles="http://luajit.org/download/$pkgname-$version.tar.gz"
checksum=620fa4eb12375021bef6e4f237cbd2dd5d49e56beb414bee052c746beef1807d

if [ "$XBPS_MACHINE" = "x86_64" ]; then
	hostmakedepends="gcc-multilib"
fi

do_build() {
	local _cflags=$CFLAGS
	local _ldflags=$LDFLAGS
	local _cross_cc

	if [ "$XBPS_MACHINE" = "x86_64" ]; then
		_cross_cc="cc -m32"
	else
		_cross_cc=cc
	fi

	unset CFLAGS LDFLAGS
	make ${makejobs} \
		PREFIX=/usr \
		CC=${CC} \
		TARGET_CFLAGS="$_cflags" \
		TARGET_LDFLAGS="$_ldflags" \
		TARGET_STRIP=: \
		HOST_CC="$_cross_cc"
}

do_install() {
	make DPREFIX=${DESTDIR}/usr DESTDIR=${DESTDIR} \
		INSTALL_SHARE=${DESTDIR}/usr/share PREFIX=/usr install

	ln -fs libluajit-5.1.so.2.0.4 ${DESTDIR}/usr/lib/libluajit-5.1.so.2
}

LuaJIT-devel_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
	}
}
