SUMMARY="A lossless image compression library"
DESCRIPTION="JBIG-KIT is a software implementation of the JBIG1 data \
compression standard (ITU-T T.82), which was designed for bi-level image \
data, such as scanned documents. This library is available in portable C \
code. It is widely used in fax products, printer firmware, printer drivers, \
document management systems and imaging software."
HOMEPAGE="https://www.cl.cam.ac.uk/~mgk25/jbigkit/"
COPYRIGHT="1995-2014 Markus Kuhn
	1989, 1991 Jef Poskanzer"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://www.cl.cam.ac.uk/~mgk25/download/jbigkit-$portVersion.tar.gz"
CHECKSUM_SHA256="de7106b6bfaf495d6865c7dd7ac6ca1381bd12e0d81405ea81e7f2167263d932"
PATCHES="jbigkit-$portVersion.patchset"

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

libVersion=$portVersion
libVersionCompat="$libVersion compat >= 2"

PROVIDES="
	jbigkit$secondaryArchSuffix = $portVersion
	lib:libjbig$secondaryArchSuffix = $libVersionCompat
	lib:libjbig85$secondaryArchSuffix = $libVersionCompat
	"
if [ -z "$secondaryArchSuffix" ]; then
PROVIDES="$PROVIDES
	cmd:jbgtopbm = $portVersion
	cmd:jbgtopbm85 = $portVersion
	cmd:pbmtojbg = $portVersion
	cmd:pbmtojbg85 = $portVersion
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	jbigkit${secondaryArchSuffix}_devel = $portVersion
	devel:libjbig$secondaryArchSuffix = $libVersionCompat
	devel:libjbig85$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	jbigkit$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	#required for test
	cmd:cmp
	"

defineDebugInfoPackage jbigkit$secondaryArchSuffix \
	"$libDir"/libjbig.so.$libVersion \
	"$libDir"/libjbig85.so.$libVersion

BUILD()
{
	make all $jobArgs
}

INSTALL()
{
	if [ -z "$secondaryArchSuffix" ]; then
		cd pbmtools
		install -m 0755 -d "$binDir" "$manDir"/man5
		# install the tools
		install -m 0755 -t "$binDir" jbgtopbm{,85} pbmtojbg{,85}
		# install man pages
		install -m 0644 -t "$manDir"/man5 pbm.5 pgm.5
		cd ..
	fi

	# install headers and libs
	cd libjbig
	install -m 0755 -d "$developLibDir" "$libDir" "$includeDir"
	install -m 0644 -t "$includeDir" *.h
	install -m 0644 -t "$libDir" libjbig{,85}.so.2.1
	install -m 0644 -t "$developLibDir" libjbig{,85}.a
	cd "$libDir"
	ln -fs libjbig.so.2.1 libjbig.so.2
	ln -fs libjbig.so.2.1 libjbig.so
	ln -fs libjbig85.so.2.1 libjbig85.so.2
	ln -fs libjbig85.so.2.1 libjbig85.so

	prepareInstalledDevelLibs libjbig libjbig85

	packageEntries devel \
		$developDir
}

TEST()
{
	make test
}
