# $Id$
# Maintainer: Eric BĂ©langer <eric@archlinux.org>

pkgname=libtiff
pkgver=4.0.3
pkgrel=5
pkgdesc="Library for manipulation of TIFF images"
arch=('i686' 'x86_64')
url="http://www.remotesensing.org/libtiff/"
license=('custom')
depends=('gcc-libs' 'libjpeg' 'zlib' 'xz')
makedepends=('freeglut' 'glu' 'mesa' 'jbigkit')
optdepends=('freeglut: for using tiffgt')
source=(ftp://ftp.remotesensing.org/pub/libtiff/tiff-${pkgver}.tar.gz
        tiff-3.9.7-CVE-2012-4447.patch
	tiff-3.9.7-CVE-2012-4564.patch
	tiff-4.0.3-CVE-2013-1960.patch
	tiff-4.0.3-CVE-2013-1961.patch
	tiff-4.0.3-libjpeg-turbo.patch
	tiff-4.0.3-tiff2pdf-colors.patch
	tiff-4.0.3-CVE-2013-4231.patch
	tiff-4.0.3-CVE-2013-4232.patch
	libtiff-CVE-2013-4244.patch)
sha1sums=('652e97b78f1444237a82cbcfe014310e776eb6f0'
          '41be661638282dae0d07bd2788414cb6650f8981'
          '6cb3d480908132335c05c769b5a51f951413725d'
          '5903355afdd0bb27ea3746339e2196720f9fac9d'
          '29a91870cca5d4cd9ca1c464f8074088eddc3fb8'
          '02d57835df50d3f84587571ec52b36f5af838de2'
          '23443ad0bc130d70860b6cc6d19b69584ae7a6cc'
          '969f588e9da5991e7f17dddf69ae59424b05fa16'
          '2a23c55d081bed74ac8dd99541a93d312cc72b64'
          '01c6792ba2470493da4d990edae8de6c13bd4670')

prepare() {
  cd tiff-${pkgver}
  patch -p0 -i "${srcdir}/tiff-4.0.3-tiff2pdf-colors.patch"
  patch -p1 -i "${srcdir}/tiff-3.9.7-CVE-2012-4447.patch"
  patch -p1 -i "${srcdir}/tiff-3.9.7-CVE-2012-4564.patch"
  patch -p1 -i "${srcdir}/tiff-4.0.3-CVE-2013-1960.patch"
  patch -p1 -i "${srcdir}/tiff-4.0.3-CVE-2013-1961.patch"
  patch -p1 -i "${srcdir}/tiff-4.0.3-libjpeg-turbo.patch"
  patch -p1 -i "${srcdir}/libtiff-CVE-2013-4244.patch"
  cd tools
  patch -p0 -i "${srcdir}/tiff-4.0.3-CVE-2013-4231.patch"
  patch -p0 -i "${srcdir}/tiff-4.0.3-CVE-2013-4232.patch"
}

build() {
  cd tiff-${pkgver}
  ./configure --prefix=/usr
  make
}

check() {
  cd tiff-${pkgver}
  make check
}

package() {
  cd tiff-${pkgver}
  make DESTDIR="${pkgdir}" install
  install -D -m644 COPYRIGHT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}