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="1"
SOURCE_URI="https://download.osgeo.org/libtiff/tiff-$portVersion.tar.gz"
CHECKSUM_SHA256="eb0484e568ead8fa23b513e9b0041df7e327f4ee2d22db5a533929dfc19633cb"
SOURCE_DIR="tiff-$portVersion"
PATCHES="tiff4-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

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

PROVIDES="
	tiff4$secondaryArchSuffix = $portVersionCompat
	lib:libtiff$secondaryArchSuffix = $libVersionCompat
	lib:libtiffxx$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	tiff4${secondaryArchSuffix}_devel = $portVersionCompat
	devel:libtiff$secondaryArchSuffix = $libVersionCompat
	devel:libtiffxx$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	tiff4$secondaryArchSuffix == $portVersion base
	"
CONFLICTS_devel="
	tiff${secondaryArchSuffix}_devel
	"

if [ -z "$secondaryArchSuffix" ]; then
	SUMMARY_tools="The TIFF tools"
	PROVIDES_tools="
		tiff4_tools = $portVersion
		cmd:fax2ps
		cmd:fax2tiff
		cmd:pal2rgb
		cmd:ppm2tiff
		cmd:raw2tiff
#		cmd:rgb2ycbcr
#		cmd:thumbnail
		cmd:tiff2bw
		cmd:tiff2pdf
		cmd:tiff2ps
		cmd:tiff2rgba
		cmd:tiffcmp
		cmd:tiffcp
		cmd:tiffcrop
		cmd:tiffdither
		cmd:tiffdump
#		cmd:tiffgt
		cmd:tiffinfo
		cmd:tiffmedian
		cmd:tiffset
		cmd:tiffsplit
		"
	REQUIRES_tools="
		haiku
		tiff4 == $portVersion base
		lib:libjpeg
		lib:libz
		"
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
	"

debugList=(
	"$libDir"/libtiff.so.$libVersion
	"$libDir"/libtiffxx.so.$libVersion
	)
if [ -z "$secondaryArchSuffix" ]; then
	for i in `echo "$PROVIDES_tools" | sed -n -e "s/^\s*cmd://p"`; do
		debugList+=("${binDir/$portName/${portName}_tools}"/$i)
	done
fi
defineDebugInfoPackage $portName "${debugList[@]}"

PATCH()
{
	if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
		sed -i \
			-e 's/ios::pos_type/streampos/g' \
			-e 's/ios::off_type/streamoff/g' \
			libtiff/tif_stream.cxx
	fi
}

BUILD()
{
	autoreconf -fi
	runConfigure ./configure --with-docdir=$documentationDir/$portName
	make $jobArgs
}

INSTALL()
{
	make install

	rm -f $libDir/libtiff*.*a
	prepareInstalledDevelLibs libtiff libtiffxx
	fixPkgconfig

	# 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
}
