SUMMARY="ECMAScipt compatible parser and engine"
DESCRIPTION="This library provides an ECMAScript compatible interpreter.
The ECMA standard is based on well known scripting languages such as \
Netscape's JavaScript and Microsoft's JScript."
HOMEPAGE="https://github.com/KDE/kjs/"
COPYRIGHT="2010-2021 KDE Organisation"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/KDE/kjs/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="031b685a246b3c8c6ae4868a46dce9003b346d1eb6a36238bac2ee4326ef6126"
PATCHES="kjs-$portVersion.patchset"

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

PROVIDES="
	kjs$secondaryArchSuffix = $portVersion
	cmd:kjs5$secondaryArchSuffix = $portVersion
	lib:libKF5JS$secondaryArchSuffix = $portVersion compat >= 5
	lib:libKF5JSApi$secondaryArchSuffix = $portVersion compat >= 5
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libKF5DocTools$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	"

PROVIDES_devel="
	kjs${secondaryArchSuffix}_devel = $portVersion
	devel:libKF5JS$secondaryArchSuffix = $portVersion compat >= 5
	devel:libKF5JSApi$secondaryArchSuffix = $portVersion compat >= 5
	"
REQUIRES_devel="
	kjs$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	docbook_xml_dtd
	docbook_xsl_stylesheets == 1.79.2
	extra_cmake_modules$secondaryArchSuffix >= $portVersion
	devel:libKF5DocTools$secondaryArchSuffix == $portVersion
	devel:libpcre$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix >= 5.7
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	#disable docs generation
	sed -e '/add_subdirectory(docs)/ s/^#*/#/' -i CMakeLists.txt
	sed -e '/kdoctools_install(po)/ s/^#*/#/' -i CMakeLists.txt
	sed -e '/add_subdirectory(kjs5)/ s/^#*/#/' -i docs/CMakeLists.txt
	sed -e '/kdoctools_create_manpage/ s/^#*/#/' -i docs/kjs5/CMakeLists.txt

	mkdir -p build
	cd build

	cmake .. $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DKDE_INSTALL_PLUGINDIR=$addOnsDir/Qt5 \
		-DECM_MKSPECS_INSTALL_DIR=$dataDir/Qt5/mkspecs \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake \
		-DDocBookXSL_DIR=/system/data/xml/docbook/xsl-stylesheets-1.79.2

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLibs \
		libKF5JS \
		libKF5JSApi

	packageEntries devel \
		$libDir/cmake \
		$dataDir/Qt5/mkspecs \
		$developDir
}

TEST()
{
	cd build
	make test
}
