SUMMARY="Free Lossless Image Format"
DESCRIPTION="FLIF is a lossless image format based on MANIAC compression. \
MANIAC (Meta-Adaptive Near-zero Integer Arithmetic Coding) is a variant of \
CABAC (context-adaptive binary arithmetic coding), where the contexts are \
nodes of decision trees which are dynamically learned at encode time.

FLIF outperforms PNG, FFV1, lossless WebP, lossless BPG and lossless \
JPEG2000 in terms of compression ratio.

Moreover, FLIF supports a form of progressive interlacing (essentially a \
generalization/improvement of PNG's Adam7) which means that any prefix \
(e.g. partial download) of a compressed file can be used as a reasonable \
lossy encoding of the entire image."
HOMEPAGE="https://flif.info/"
COPYRIGHT="2016 Jon Sneyers
	Pieter Wuille"
LICENSE="Apache v2
	GNU GPL v3
	GNU LGPL v3"
REVISION="1"
srcGitRev="74ea92bf1ab2db18ae6d2a521dff946fcc679618"
SOURCE_URI="https://github.com/FLIF-hub/FLIF/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="aeeb4d24f19204f2b0cecc41ee1ebdda1c1ae730f0c6fa4969f67aab7e5eccac"
SOURCE_FILENAME="flif-$portVersion-$srcGitRev.tar.gz"
SOURCE_DIR="FLIF-$srcGitRev"
PATCHES="flif-$portVersion.patchset"

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

PROVIDES="
	flif$secondaryArchSuffix = $portVersion
	cmd:apng2flif$secondaryArchSuffix = $portVersion
	cmd:dflif$secondaryArchSuffix = $portVersion
	cmd:flif$secondaryArchSuffix = $portVersion
	cmd:gif2flif$secondaryArchSuffix = $portVersion
	lib:libflif$secondaryArchSuffix = 0
	lib:libflif_dec$secondaryArchSuffix = 0
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	flif${secondaryArchSuffix}_devel = $portVersion
	devel:libflif$secondaryArchSuffix = 0
	devel:libflif_dec$secondaryArchSuffix = 0
	"
REQUIRES_devel="
	flif$secondaryArchSuffix == $portVersion base
	"

PROVIDES_tools="
	flif${secondaryArchSuffix}_tools
	cmd:viewflif$secondaryArchSuffix = $portVersion
	"
REQUIRES_tools="
	flif$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libSDL2_2.0$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libpng16$secondaryArchSuffix
	devel:libSDL2_2.0$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:convert$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cd src
	cmake . $cmakeDirArgs
	make $jobArgs
}

INSTALL()
{
	cd src
	make install

	prepareInstalledDevelLibs libflif libflif_dec

	mkdir -p "$developLibDir"/pkgconfig
	cat > "$developLibDir"/pkgconfig/flif.pc << EOF
prefix=${prefix}
exec_prefix=${prefix}
libdir=${libDir}
includedir=${includeDir}

Name: flif
Description: Free Lossless Image Format
Version: ${portVersion}
Libs: -L${developLibDir} -lflif -lflif_dec
Cflags: -I${includeDir}
EOF

	packageEntries devel \
		$developDir
	packageEntries tools \
		$binDir/viewflif
}

TEST()
{
	cd src
	make test
}
