SUMMARY="A JSON implementation in C"
DESCRIPTION="JSON-C implements a reference counting object model that allows \
you to easily construct JSON objects in C, output them as JSON formatted \
strings and parse JSON formatted strings back into the C representation of \
JSON objects."
HOMEPAGE="https://github.com/json-c/json-c/wiki"
COPYRIGHT="2009-2012, 2016-2017 Eric Haszlakiewicz
	2004-2005, 2013 Metaparadigm Pte. Ltd.
	2009-2012 Hewlett-Packard Development Company, L.P.
	2008-2009 Yahoo! Inc.
	2016 Alexandru Ardelean"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://s3.amazonaws.com/json-c_releases/releases/json-c-$portVersion.tar.gz"
CHECKSUM_SHA256="b8d80a1ddb718b3ba7492916237bbf86609e9709fb007e7f7d4322f02341a4c6"
SOURCE_DIR="json-c-$portVersion"
PATCHES="json_c-$portVersion.patchset"

ARCHITECTURES="all ?x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

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

PROVIDES="
	json_c$secondaryArchSuffix = $portVersion
	lib:libjson_c$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	json_c${secondaryArchSuffix}_devel = $portVersion
	devel:libjson_c$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	json_c$secondaryArchSuffix == $portVersion base
	"

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

TEST_REQUIRES="
	cmd:cmp
	"

defineDebugInfoPackage json_c$secondaryArchSuffix \
	$libDir/libjson-c.so.$libVersion

BUILD()
{
	cmake -Bbuild $cmakeDirArgs . \
		-DENABLE_THREADING=ON \
		-DENABLE_RDRAND=OFF
	cmake --build build $jobArgs
}

INSTALL()
{
	cmake --build build --target install

	mkdir -p $(dirname $includeDir)
	mv $prefix/include $includeDir

	prepareInstalledDevelLib libjson-c
	fixPkgconfig
	packageEntries devel $developDir $libDir/cmake
}

TEST()
{
	cmake --build build --target test
}
