SUMMARY="A parser generator tool and an incremental parsing library"
DESCRIPTION="Tree-sitter is a parser generator tool and an incremental \
parsing library.
It can build a concrete syntax tree for a source file and efficiently update \
the syntax tree as the source file is edited."
HOMEPAGE="https://github.com/tree-sitter/tree-sitter"
COPYRIGHT="2018 Max Brunsfeld"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="4a8070b9de17c3b8096181fe8530320ab3e8cca685d8bee6a3e8d164b5fb47da"
SOURCE_FILENAME="tree-sitter-v$portVersion.tar.gz"
SOURCE_DIR="tree-sitter-$portVersion"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	tree_sitter$secondaryArchSuffix = $portVersion
	cmd:tree_sitter = $portVersion
	lib:libtree_sitter$secondaryArchSuffix = 0.0 compat >= 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	tree_sitter${secondaryArchSuffix}_devel = $portVersion
	devel:libtree_sitter$secondaryArchSuffix = 0.0 compat >= 0
	"
REQUIRES_devel="
	tree_sitter$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cargo$secondaryArchSuffix
	cmd:make
	cmd:gcc$secondaryArchSuffix
	"

BUILD()
{
	cargo fetch --locked
	make PREFIX=$prefix \
		INCLUDEDIR=$includeDir \
		LIBDIR=$libDir $jobArgs
	cd cli
	cargo build --release --locked --offline --all-features
}

INSTALL()
{
	make PREFIX=$prefix \
		INCLUDEDIR=$includeDir \
		LIBDIR=$libDir install

	mkdir -p $prefix/bin
	cp target/release/tree-sitter $prefix/bin

	prepareInstalledDevelLib libtree-sitter
	fixPkgconfig

	packageEntries devel \
		$developDir
}
