# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgname=netpbm
pkgver=10.86.42
pkgrel=1
pkgdesc='A toolkit for manipulation of graphic images'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(Artistic-1.0 GPL-2.0-only LGPL-2.0.only MIT)
url="http://netpbm.sourceforge.net/"
depends=(bash
         gcc-libs
         glibc
         jbigkit
         libjpeg-turbo
         libpng
         libtiff
         libxml2
         perl
         zlib)
options=(!makeflags)
# Get docs with: wget --recursive --relative -nH http://netpbm.sourceforge.net/doc/
source=(https://downloads.sourceforge.net/project/netpbm/super_stable/$pkgver/netpbm-$pkgver.tgz
        https://sources.archlinux.org/other/packages/netpbm/netpbm-doc-31Jan2014.tar.xz{,.sig}
        netpbm-CAN-2005-2471.patch
        netpbm-security-code.patch
        netpbm-security-scripts.patch
        reproducible-man-gzip.patch)
sha256sums=('d4d2ca69d82b8d8518aee1d0a2f400664324afa8237859386764a41784d497f6'
            '74bcf840ee643c6917330c382484010cb99c004a3fcf05391bebcac63815acb3'
            'SKIP'
            '7348274b72b8285add042d0f45d124c9833206ee3440bd1846cfc792b9b4d5e5'
            '698645215d46bcee515d75847fc550ce99c5fcb6fae63dacdba1d773f327c80e'
            '5ee27b4187577cbb9e85f6b36c5e5a421e03927f9195f888be7be2b647a5ac9d'
            'b0be94fbfbf247552c5cc3f1cdd93e2d549f59c3d218350ccc1bea44e9bebc9b')
validpgpkeys=('5357F3B111688D88C1D88119FCF2CB179205AC90')

prepare() {
  cd $pkgname-$pkgver

  patch -p1 < ../netpbm-CAN-2005-2471.patch
  patch -p1 < ../netpbm-security-code.patch
  patch -p1 < ../netpbm-security-scripts.patch
  patch -p1 < ../reproducible-man-gzip.patch

  cp config.mk.in  config.mk
  [ "${CARCH}" = 'x86_64' ] && echo 'CFLAGS_SHLIB = -fPIC' >> config.mk
  echo "NETPBM_DOCURL = file://${srcdir}/doc" >> config.mk
  echo 'TIFFLIB = libtiff.so' >> config.mk
  echo 'JPEGLIB = libjpeg.so' >> config.mk
  echo 'PNGLIB = libpng.so' >> config.mk
  echo 'ZLIB = libz.so' >> config.mk
  echo 'JBIGLIB = /usr/lib/libjbig.a' >> config.mk

  sed -i 's|misc|share/netpbm|' common.mk
  sed -e 's|/sharedlink|/lib|' -e 's|/staticlink|/lib|' -i lib/Makefile
  sed -i 's|install.manwebmain install.manweb install.man|install.man|' GNUmakefile
}

build() {
  cd $pkgname-$pkgver
  make
  # Generating useful man pages with html doc
  # TODO: Enable when we have it updated
  # make MAKEMAN="${srcdir}/$pkgname-$pkgver/buildtools/makeman" USERGUIDE="-v ." \
  #   -C ../doc -f "${srcdir}/$pkgname-$pkgver/buildtools/manpage.mk" manpages
}

package() {
  cd $pkgname-$pkgver
  make pkgdir="${pkgdir}/usr" PKGMANDIR=share/man install-run install-dev

# Replace obsolete utility
  echo -e '#!/bin/sh\npamditherbw $@ | pamtopnm\n' > "${pkgdir}/usr/bin/pgmtopbm"

# Licensing.  Note that each program in the package has a separate license.
  install -D -m644 "${srcdir}/$pkgname-$pkgver/doc/copyright_summary" \
    "${pkgdir}/usr/share/licenses/${pkgname}/copyright_summary.txt"
}
