SUMMARY="Open h.265 codec implementation"
DESCRIPTION="libde265 is an open source implementation of the h.265 video \
codec. It is written from scratch and has a plain C API to enable a simple \
integration into other software.

libde265 supports WPP and tile-based multithreading and includes SSE \
optimizations. The decoder includes all features of the Main profile and \
correctly decodes almost all conformance streams (see \
https://github.com/strukturag/libde265/wiki/Decoder-conformance)."
HOMEPAGE="https://homepage/of/projectx.org"
COPYRIGHT="2013-2014 Struktur AG"
LICENSE="GNU LGPL v3
	MIT"
REVISION="1"
SOURCE_URI="https://github.com/strukturag/libde265/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="c5ab61185f283f46388c700c43dc08606b0e260cd53f06b967ec0ad7a809ff11"

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

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

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

PROVIDES="
	libde265$secondaryArchSuffix = $portVersion
	lib:libde265$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

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

SUMMARY_tools="Collection tools from libde265"
PROVIDES_tools="
	libde265${secondaryArchSuffix}_tools
	cmd:acceleration_speed$commandSuffix
	cmd:bjoentegaard$commandSuffix
	cmd:block_rate_estim$commandSuffix
	cmd:dec265$commandSuffix
	cmd:enc265$commandSuffix
	cmd:gen_enc_table$commandSuffix
	cmd:hdrcopy$commandSuffix
	cmd:rd_curves$commandSuffix
	cmd:sherlock265$commandSuffix
	cmd:tests$commandSuffix
	cmd:yuv_distortion$commandSuffix
	"
REQUIRES_tools="
	libde265$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libSDL_1.2$secondaryArchSuffix
	lib:libswscale$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libSDL_1.2$secondaryArchSuffix
	devel:libswscale$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libde265$secondaryArchSuffix \
	$libDir/libde265.so.$libVersion \
	"$(getPackagePrefix tools)"/bin/acceleration_speed \
	"$(getPackagePrefix tools)"/bin/bjoentegaard \
	"$(getPackagePrefix tools)"/bin/block-rate-estim \
	"$(getPackagePrefix tools)"/bin/dec265 \
	"$(getPackagePrefix tools)"/bin/enc265 \
	"$(getPackagePrefix tools)"/bin/gen-enc-table \
	"$(getPackagePrefix tools)"/bin/hdrcopy \
	"$(getPackagePrefix tools)"/bin/rd-curves \
	"$(getPackagePrefix tools)"/bin/sherlock265 \
	"$(getPackagePrefix tools)"/bin/tests \
	"$(getPackagePrefix tools)"/bin/yuv-distortion

BUILD()
{
	./autogen.sh

	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir

	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool file
	rm $libDir/*.la

	prepareInstalledDevelLib libde265
	fixPkgconfig

	packageEntries devel \
		$developDir

	packageEntries tools \
		$commandBinDir
}
