# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=libtiff
pkgver=4.6.0
pkgrel=5
pkgdesc='Library for manipulation of TIFF images'
url='http://www.simplesystems.org/libtiff/'
arch=('x86_64')
license=('custom')
depends=('gcc-libs' 'glibc' 'jbigkit' 'libjpeg-turbo' 'libjpeg.so' 'zlib' 'xz' 'zstd')
makedepends=('freeglut' 'git' 'glu' 'mesa')
optdepends=('freeglut: for using tiffgt')
provides=('libtiff.so' 'libtiffxx.so')
source=("git+https://gitlab.com/libtiff/libtiff.git?signed#tag=v${pkgver}")
sha256sums=('039e243f1f37459833b9c3475e62d245f9593e61e8f4be5843f2d7af711c45f9')
b2sums=('e3c31b9afefecdcafb52d174840c2eee8cb4dd43ff1a81eef52a09e0753cfb247775baa7a42b865e518f2cdaa04828e4acbb43a0ead373b1251b2d0c03f8d0a6')
  'EBDFDB21B020EE8FD151A88DE301047DE1198975' # Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
  'B1FA7D81EEB8E66399178B9733EBBFC47B3DD87D' # Even Rouault <even.rouault@spatialys.com>
)

prepare() {
  cd libtiff
  # CVE-2023-6277
  git cherry-pick -n 5320c9d89c054fa805d037d84c57da874470b01a
  # CVE-2023-52356
  git cherry-pick -n 51558511bdbbcffdce534db21dbaf5d54b31638a
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --enable-ld-version-script
    --mandir=/usr/share/man
    --with-docdir=/usr/share/doc/${pkgname}
  )

  cd libtiff
  ./configure "${configure_options[@]}"
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd libtiff
  make check
}

package() {
  cd libtiff
  make DESTDIR="${pkgdir}" install
  install -Dm 644 LICENSE.md -t "${pkgdir}/usr/share/licenses/${pkgname}/"
}

# vim: ts=2 sw=2 et:
