SUMMARY="Dynamic Lisp dialect and bytecode vm"
DESCRIPTION="Janet is a functional and imperative programming language \
and bytecode interpreter. It is a modern lisp, but lists are replaced by \
other data structures with better utility and performance (arrays, tables, \
structs, tuples). The language also supports bridging to native code written \
in C, meta-programming with macros, and bytecode assembly."
HOMEPAGE="https://janet-lang.org/"
COPYRIGHT="2019 Calvin Rose and contributors"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://github.com/janet-lang/janet/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="f14de9e2e1db5707e48a15f4262f4ce8c9ff99b2b3abc59ea6a1493d54bd4ed4"
SOURCE_FILENAME="janet-$portVersion.tar.gz"
PATCHES="janet-1.3.1.patch"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${portVersion%%.*}"

PROVIDES="
	janet$secondaryArchSuffix = $portVersion
	cmd:janet$commandSuffix
	cmd:jpm$commandSuffix
	lib:libjanet$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	janet${secondaryArchSuffix}_devel = $portVersion
	devel:libjanet$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	janet$secondaryArchSuffix == $portVersion base
	"

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

defineDebugInfoPackage janet$secondaryArchSuffix \
	"$commandBinDir/janet$commandSuffix" \
	"$libDir/libjanet.so.$libVersion"

BUILD()
{
	make $jobArgs INCLUDEDIR="$includeDir" LIBDIR="$libDir"
}

INSTALL()
{
	make install BINDIR="$commandBinDir" \
		INCLUDEDIR="$includeDir" \
		LIBDIR="$libDir" \
		MANPATH="$manDir/man1" \
		PREFIX="$prefix"

	prepareInstalledDevelLib libjanet
	fixPkgconfig

	packageEntries devel \
		"$developDir"
}

TEST()
{
	make test
}
