SUMMARY="Pattern-matching library for Lua"
DESCRIPTION="LPeg is a new pattern-matching library for Lua, based on \
Parsing Expression Grammars (PEGs). This text is a reference manual \
for the library. For a more formal treatment of LPeg, as well as \
some discussion about its implementation, \
see A Text Pattern-Matching Tool based on Parsing Expression Grammars."
HOMEPAGE="http://www.inf.puc-rio.br/~roberto/lpeg/"
COPYRIGHT="2007-2017 Lua.org, PUC-Rio."
LICENSE="MIT"
REVISION="1"
SOURCE_URI="http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-$portVersion.tar.gz"
CHECKSUM_SHA256="48d66576051b6c78388faad09b70493093264588fcd0f258ddaab1cdd4a15ffe"
SOURCE_DIR="lpeg-$portVersion"

ARCHITECTURES="all !x86_gcc2 ?x86"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	lpeg$secondaryArchSuffix = $portVersion
	lib:lpeg$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix >= 5.3
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liblua$secondaryArchSuffix >= 5.3
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

PATCH()
{
	sed -i \
		's/(os.setlocale("C") == "C")/(os.setlocale("C") == "POSIX")/' \
		test.lua
}

BUILD()
{
	LUAVERSION_WITHOUT_DOT=$(lua -v | sed 's/Lua //' | head -c3 | tr -d '.')
	make LUADIR="$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir/lua$LUAVERSION_WITHOUT_DOT"
}

INSTALL()
{
	LUAVERSION=$(lua -v | sed 's/Lua //' | head -c3)
	mkdir -p $libDir/lua/$LUAVERSION
	cp lpeg.so $libDir/lua/$LUAVERSION
}

TEST()
{
	make test
}
