SUMMARY="A powerful, fast, light-weight, embeddable scripting language"
DESCRIPTION="Lua combines simple procedural syntax with powerful data \
description constructs based on associative arrays and extensible semantics. \
Lua is dynamically typed, runs by interpreting bytecode for a register-based \
virtual machine, and has automatic memory management with incremental garbage \
collection, making it ideal for configuration, scripting, and rapid \
prototyping."
HOMEPAGE="http://www.lua.org"
LICENSE="MIT"
REVISION="6"

ARCHITECTURES="x86 x86_gcc2"
SECONDARY_ARCHITECTURES="x86 x86_gcc2"

SOURCE_URI="http://www.lua.org/ftp/lua-5.1.4.tar.gz"
CHECKSUM_SHA256="b038e225eaf2a5b57c9bcc35cd13aa8c6c8288ef493d52970c9545074098af3a"
COPYRIGHT="1994-2009, Lua.org, PUC-Rio"
PATCHES="lua-5.1.4.patchset"

PROVIDES="
	lua${secondaryArchSuffix} = $portVersion compat >= 5.1
	cmd:lua${secondaryArchSuffix} = $portVersion compat >= 5.1
	cmd:lua5.1${secondaryArchSuffix} = $portVersion compat >= 5.1
	cmd:luac${secondaryArchSuffix} = $portVersion compat >= 5.1
	lib:liblua${secondaryArchSuffix} = $portVersion compat >= 5.1
	"
REQUIRES="
	haiku${secondaryArchSuffix}
	"
PROVIDES_devel="
	lua${secondaryArchSuffix}_devel = $portVersion compat >= 5.1
	devel:liblua$secondaryArchSuffix = $portVersion compat >= 5.1
	devel:liblua5.1$secondaryArchSuffix = $portVersion compat >= 5.1
	"
REQUIRES_devel="
	lua$secondaryArchSuffix == $portVersion
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:make
	cmd:gcc${secondaryArchSuffix}
	"


BUILD()
{
	make haiku
}

INSTALL()
{
    make install INSTALL_TOP="$prefix" INSTALL_MAN="$manDir/man1" \
        INSTALL_INC="$includeDir/lua5.1" INSTALL_LMOD="$dataDir/lua/5.1" \
        INSTALL_LIB="$libDir" INSTALL_BIN="$binDir"

	mkdir -p $libDir/pkgconfig
	cp etc/lua.pc $libDir/pkgconfig/lua.pc

	ln -s liblua.so $libDir/liblua.so.5.1
	ln -s liblua.a $libDir/liblua5.1.a

	mv $binDir/lua $binDir/lua5.1
	ln -s $binDir/lua5.1 $binDir/lua

	prepareInstalledDevelLib liblua
	prepareInstalledDevelLib liblua5.1
	fixPkgconfig

	# The includes are in a subdirectory of includeDir, and fixPkgconfig breaks
	# that.
	sed -i -e "s,^includedir=.*,includedir=$prefix/$relativeIncludeDir/lua5.1," \
   		$developLibDir/pkgconfig/lua.pc
	
	packageEntries devel $developDir
}
