# $Id: PKGBUILD 148858 2012-02-05 11:53:06Z ibiru $
# Maintainer: Kevin Piche <kevin@archlinux.org>

pkgname=netpbm
pkgver=10.57.1
pkgrel=1
pkgdesc="A toolkit for manipulation of graphic images"
arch=('i686' 'x86_64')
license=('custom' 'BSD' 'GPL' 'LGPL')
url="http://netpbm.sourceforge.net/"
depends=('perl' 'libpng' 'libtiff' 'libxml2')
makedepends=('python2')
options=('!makeflags')
# Releases after 10.34 are available via SVN only.
# Get Advanced tarball here: http://netpbm.sourceforge.net/release.html#tarball
# Get version number from version.mk
# Get docs with: wget --recursive --relative -nH http://netpbm.sourceforge.net/doc/
source=(ftp://ftp.archlinux.org/other/netpbm/${pkgname}-${pkgver}.tar.gz \
        ftp://ftp.archlinux.org/other/netpbm/netpbm-doc-22Feb2009.tar.xz \
        netpbm-CAN-2005-2471.patch netpbm-security-code.patch netpbm-security-scripts.patch)
sha1sums=('cd0b99333faf994a680d77c5d217034df35ebd4e'
          'dfeba9f9a5fe987d64db0aadb5ca8c1b20fcead2'
          'b79cf9d42488fea065ba16262ed97694c47af08d'
          '4cd5b94a24886ecae3973c5ae104d8298fe5a1f5'
          '2ac31f714121e08e47af9337c6bbaab3cbfc5c75')

build() {
  cd "${srcdir}/advanced"
  patch -p1 < ../netpbm-CAN-2005-2471.patch
  patch -p1 < ../netpbm-security-code.patch
  patch -p1 < ../netpbm-security-scripts.patch
  sed -i 's|#!/usr/bin/python|#!/usr/bin/python2|' buildtools/makeman
  sed -i 's|@python|@python2|' buildtools/manpage.mk

  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
 
  sed -i 's|misc|share/netpbm|' common.mk
  sed -i 's|/link|/lib|' lib/Makefile
  sed -i 's|install.manweb install.man|install.man|' GNUmakefile

  make

  # Generating useful man pages with html doc
  cd  "${srcdir}/doc"
  make MAKEMAN="${srcdir}/advanced/buildtools/makeman" USERGUIDE=. \
    -f "${srcdir}/advanced/buildtools/manpage.mk" manpages
}

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

# Removing dummy man pages
  rm "${pkgdir}"/usr/share/man/man{1,3,5}/*

  cd  "${srcdir}/doc"
  make MAKEMAN="${srcdir}/advanced/buildtools/makeman" MANDIR="${pkgdir}/usr/share/man" \
    -f "${srcdir}/advanced/buildtools/manpage.mk" installman

# 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}/advanced/doc/copyright_summary" \
    "${pkgdir}/usr/share/licenses/${pkgname}/copyright_summary.txt"
}