SUMMARY="An open-source HEVC encoder"
DESCRIPTION="Kvazaar is still under development."
HOMEPAGE="https://ultravideo.cs.tut.fi/#encoder"
COPYRIGHT="2021 Tampere University, ITU/ISO/IEC, project contributors"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="https://github.com/ultravideo/kvazaar/releases/download/v$portVersion/kvazaar-$portVersion.tar.xz"
CHECKSUM_SHA256="a76998462924ab8409cf8de4947ba5a5023daa33207676e9c4eefc2bbd46c834"
SOURCE_URI_2="https://vcgit.hhi.fraunhofer.de/jct-vc/HM/-/archive/HM-16.24/HM-HM-16.24.tar.bz2"
CHECKSUM_SHA256_2="560e750cefe2ad0edae0687735ae3a4d8f34d033809775af70efdbfcf85fcba2"
SOURCE_DIR_2="HM-HM-16.24"
PATCHES_2="kvazaar-$portVersion-source2.patchset"

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

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

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

PROVIDES="
	kvazaar$secondaryArchSuffix = $portVersion
	cmd:kvazaar
	lib:libkvazaar$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcryptopp$secondaryArchSuffix
	"

PROVIDES_devel="
	kvazaar${secondaryArchSuffix}_devel = $portVersion
	devel:libkvazaar$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	kvazaar$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcryptopp$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmp
	cmd:diff
	cmd:find
	cmd:gawk
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:yasm
	"
TEST_REQUIRES="
	cmd:cmake
	cmd:ffmpeg
	"


defineDebugInfoPackage kvazaar$secondaryArchSuffix \
	"$libDir"/libkvazaar.so.$libVersion

BUILD()
{
	mkdir -p build && cd build
	export CPPFLAGS=-DPIC
	ACLOCAL=: AUTOCONF=: AUTOMAKE=: AUTOHEADER=: \
		runConfigure --omit-dirs binDir ../configure --bindir="$commandBinDir" \
		--with-cryptopp
	make $jobArgs
}

INSTALL()
{
	make -C build install

	rm -f $libDir/lib*.la $libDir/lib*.a
	prepareInstalledDevelLibs libkvazaar
	fixPkgconfig
	packageEntries devel $developDir
}

TEST()
{
	cd $sourceDir2
	cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
	make -C build VERBOSE=1 $jobArgs

	PATH=$PATH:$sourceDir2/bin/umake/gcc-11.2/x86_64/release/
	ln -srf	$sourceDir2/bin/umake/gcc-11.2/x86_64/release/TAppDecoder \
		 $sourceDir2/bin/umake/gcc-11.2/x86_64/release/TAppDecoderStatic
	cd $sourceDir
	make -C build check
}
