#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
PKG=$TMP/package-gimp-print
rm -rf $PKG
mkdir -p $PKG

VERSION=4.2.7
ARCH=i486
BUILD=1

# Let GIMP use the plug-in it comes with or it's a messy dependancy.
# This comes with some ghostscript patches that already seem to be
# built into ghostscript now :-)

cd $TMP
rm -rf gimp-print-${VERSION}
tar xjvf $CWD/gimp-print-${VERSION}.tar.bz2
cd gimp-print-${VERSION}
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
./configure --prefix=/usr \
  --infodir=/usr/info \
  --with-ijs \
  --with-cups \
  --without-gimp \
  --without-samples \
  --without-user-guide \
  --enable-escputil \
  --disable-static \
  --disable-nls \
  $ARCH-slackware-linux
make -j3
make install DESTDIR=$PKG
chown -R root.bin $PKG/usr/bin
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
rm -rf $PKG/usr/lib/gimp
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
gzip -9 $PKG/usr/man/man?/*.?
mkdir -p $PKG/usr/doc/gimp-print-${VERSION}
cp -a \
  ABOUT-NLS AUTHORS COPYING NEWS README \
  $PKG/usr/doc/gimp-print-${VERSION}
cp -a src/ghost/README $PKG/usr/doc/gimp-print-${VERSION}/README.ghostscript
rmdir $PKG/usr/share/gimp-print/samples/
rmdir $PKG/usr/share/gimp-print/
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n ../gimp-print-$VERSION-$ARCH-$BUILD.tgz