SUMMARY="HEIF file format decoder and encoder"
DESCRIPTION="libheif is an ISO/IEC 23008-12:2017 HEIF and AVIF (AV1 Image \
File Format) file format decoder and encoder.

HEIF and AVIF are new image file formats employing HEVC (h.265) or AV1 image \
coding, respectively, for the best compression ratios currently possible.

libheif makes use of libde265 for HEIF image decoding and x265 for encoding.
For AVIF, libaom, dav1d, or rav1e are used as codecs."
HOMEPAGE="https://github.com/strukturag/libheif"
COPYRIGHT="2017-2020 Struktur AG"
LICENSE="MIT
	GNU LGPL v3"
REVISION="1"
SOURCE_URI="https://github.com/strukturag/libheif/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="086145b0d990182a033b0011caadb1b642da84f39ab83aa66d005610650b3c65"

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

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

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

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

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

SUMMARY_tools="Tools for libheif package"
PROVIDES_tools="
	libheif${secondaryArchSuffix}_tools
	cmd:heif_convert$commandSuffix = $portVersion
	cmd:heif_enc$commandSuffix = $portVersion
	cmd:heif_info$commandSuffix = $portVersion
	cmd:heif_thumbnailer$commandSuffix = $portVersion
	"
REQUIRES_tools="
	libheif$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libdav1d$secondaryArchSuffix
	lib:libde265$secondaryArchSuffix
	lib:libx265$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libdav1d$secondaryArchSuffix
	devel:libde265$secondaryArchSuffix
	devel:libx265$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libheif$secondaryArchSuffix \
	$libDir/libheif.so.$libVersion \
	"$(getPackagePrefix tools)"/bin/heif-convert \
	"$(getPackagePrefix tools)"/bin/heif-enc \
	"$(getPackagePrefix tools)"/bin/heif-info \
	"$(getPackagePrefix tools)"/bin/heif-thumbnailer

BUILD()
{
	./autogen.sh

	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir \
		--disable-gdk-pixbuf \
		--enable-tests

	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool file
	rm $libDir/*.la

	prepareInstalledDevelLib libheif
	fixPkgconfig

	packageEntries devel \
		$developDir

	packageEntries tools \
		$commandBinDir \
		$manDir \
		$dataDir
}

TEST()
{
	make test
}
