SUMMARY="A library to read/write TIFF images"
DESCRIPTION="TIFF the Tag Image File Format, is a widely used format for \
storing image data. Included in this software is a library, libtiff, for \
reading and writing TIFF and a small collection of tools for doing simple \
manipulations of TIFF images."
HOMEPAGE="http://www.libtiff.org/"
COPYRIGHT="1988-1997 Sam Leffler
	1991-1997 Silicon Graphics, Inc."
LICENSE="MIT"
REVISION="2"
SOURCE_URI="http://download.osgeo.org/libtiff/tiff-$portVersion.tar.gz
	ftp://ftp.remotesensing.org/pub/libtiff/tiff-$portVersion.tar.gz"
CHECKSUM_SHA256="f5d64dd4ce61c55f5e9f6dc3920fbe5a41e02c2e607da7117a35eb5c320cef6a"
PATCHES="tiff-$portVersion.patchset"

patchesBaseUri="https://gitweb.gentoo.org/repo/gentoo.git/plain/media-libs/tiff/files"
SOURCE_FILENAME_2="tiff-$portVersion-CVE-2012-4447.patch"
SOURCE_FILENAME_3="tiff-$portVersion-CVE-2012-4564.patch"
SOURCE_FILENAME_4="tiff-$portVersion-CVE-2012-5581.patch"
SOURCE_FILENAME_5="tiff-$portVersion-tiffinfo-exif.patch"
SOURCE_FILENAME_6="tiff-$portVersion-printdir-width.patch"
srcGitRev_2="b280d8459134b9f05fcc1525a2aa2d4134091cf4"
srcGitRev_3="62108c88946351318c1985e167d5c04d8fdd6645"
srcGitRev_4="05f9e0b614456fc348168a9f9f8c739660c8fefa"
srcGitRev_5="05f9e0b614456fc348168a9f9f8c739660c8fefa"
srcGitRev_6="4d119880422822032a408ee1201c20dddde1357c"
SOURCE_URI_2="$patchesBaseUri/$SOURCE_FILENAME_2?id=$srcGitRev_2#noarchive"
SOURCE_URI_3="$patchesBaseUri/$SOURCE_FILENAME_3?id=$srcGitRev_3#noarchive"
SOURCE_URI_4="$patchesBaseUri/$SOURCE_FILENAME_4?id=$srcGitRev_4#noarchive"
SOURCE_URI_5="$patchesBaseUri/$SOURCE_FILENAME_5?id=$srcGitRev_5#noarchive"
SOURCE_URI_6="$patchesBaseUri/$SOURCE_FILENAME_6?id=$srcGitRev_6#noarchive"
CHECKSUM_SHA256_2="373020d6c383778ee40f642d90e5d9f3a878f0c17a529825e43e1647d27332cf"
CHECKSUM_SHA256_3="525f667e2148229520b50d6136c0ecd345b8db9acc62fde945a5f13dae4d51f3"
CHECKSUM_SHA256_4="f47b30c8fc0578df7285f6cf318f29d410db4b82550b3fbc9582beeb9a834415"
CHECKSUM_SHA256_5="2b333f3161f88aef3f764de316c4e8f10906932d33ee575b98f7723b2bff1db7"
CHECKSUM_SHA256_6="597406f727b26fd06106e1e22a1e4e4620b3ffa54a49c2c4b0b8ee6b1d54908b"

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

PROVIDES="
	tiff$secondaryArchSuffix = $portVersion compat >= 3
	lib:libtiff$secondaryArchSuffix = $portVersion compat >= 3
	lib:libtiffxx$secondaryArchSuffix = $portVersion compat >= 3
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	tiff${secondaryArchSuffix}_devel = $portVersion compat >= 3
	devel:libtiff$secondaryArchSuffix = $portVersion compat >= 3
	devel:libtiffxx$secondaryArchSuffix = $portVersion compat >= 3
	"
REQUIRES_devel="
	tiff$secondaryArchSuffix == $portVersion base
	"

if [ -z "$secondaryArchSuffix" ]; then
	SUMMARY_tools="The TIFF tools"
	PROVIDES_tools="
		tiff_tools = $portVersion compat >= 3
		cmd:bmp2tiff = $portVersion compat >= 3
		cmd:fax2ps = $portVersion compat >= 3
		cmd:fax2tiff = $portVersion compat >= 3
		cmd:gif2tiff = $portVersion compat >= 3
		cmd:pal2rgb = $portVersion compat >= 3
		cmd:ppm2tiff = $portVersion compat >= 3
		cmd:ras2tiff = $portVersion compat >= 3
		cmd:raw2tiff = $portVersion compat >= 3
		cmd:rgb2ycbcr = $portVersion compat >= 3
		cmd:thumbnail = $portVersion compat >= 3
		cmd:tiff2bw = $portVersion compat >= 3
		cmd:tiff2pdf = $portVersion compat >= 3
		cmd:tiff2ps = $portVersion compat >= 3
		cmd:tiff2rgba = $portVersion compat >= 3
		cmd:tiffcmp = $portVersion compat >= 3
		cmd:tiffcp = $portVersion compat >= 3
		cmd:tiffcrop = $portVersion compat >= 3
		cmd:tiffdither = $portVersion compat >= 3
		cmd:tiffdump = $portVersion compat >= 3
		cmd:tiffinfo = $portVersion compat >= 3
		cmd:tiffmedian = $portVersion compat >= 3
		cmd:tiffset = $portVersion compat >= 3
		cmd:tiffsplit = $portVersion compat >= 3
		"
	REQUIRES_tools="
		haiku
		lib:libjpeg
		lib:libz
		tiff == $portVersion base
		"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libjpeg$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

PATCH()
{
	patch -p1 -i $sourceDir2/$SOURCE_FILENAME_2
	patch -p1 -i $sourceDir3/$SOURCE_FILENAME_3
	patch -p1 -i $sourceDir4/$SOURCE_FILENAME_4
	patch -p1 -i $sourceDir5/$SOURCE_FILENAME_5
	patch -p1 -i $sourceDir6/$SOURCE_FILENAME_6
}

BUILD()
{
	aclocal
	libtoolize --force --copy --install
	automake --add-missing
	autoconf
	autoheader
	runConfigure ./configure --with-docdir=$documentationDir
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libtiff*.la

	prepareInstalledDevelLibs libtiff libtiffxx

	# devel package
	packageEntries devel \
		$developDir

	# tools package
	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries tools \
			$binDir \
			$documentationDir
	fi

	# Remove stuff we don't need in the secondary architecture base package.
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $binDir
		rm -rf $documentationDir
	fi
}

TEST()
{
	make check
}
