#!/bin/sh
CWD=`pwd`

VERSION=${VERSION:-8.01}
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-0}
# TUPLE=$ARCH-slackware-linux
TUPLE=$ARCH-splack-linux

TMP=/tmp/gnughostscript-$VERSION
PKG=/tmp/package-gnugs

rm -rf $TMP $PKG

cd /tmp
tar zxfv $CWD/gnughostscript-$VERSION.tar.gz

# We need ijs
cd $TMP/ijs
mkdir -p $PKG/usr/lib64 $PKG/usr/bin
CFLAGS="-O2 -fPIC -L/usr/lib64" \
./configure --prefix=/usr
make CFLAGS="-ansi -pedantic -Wmissing-prototypes"
cat libijs.a > $PKG/usr/lib/libijs.a
cat ijs-config > $PKG/usr/bin/ijs-config
chown root.bin $PKG/usr/bin/ijs-config
chmod 755 $PKG/usr/bin/ijs-config
mkdir -p $PKG/usr/include/ijs
cp -a ijs.h ijs_client.h ijs_server.h $PKG/usr/include/ijs
( cd $PKG/usr/include/ijs
  chmod 644 ijs.h ijs_client.h ijs_server.h
  chown root.root ijs.h ijs_client.h ijs_server.h )
# Now the main source is compiled:
cd $TMP
CFLAGS="-O3" \
./configure \
	--prefix=/usr \
	--enable-cups \
	--with-x \
	--with-omni \
	--with-gimp-print \
	--with-drivers=all $TUPLE
make CFLAGS="-O3"
make install prefix=$PKG/usr

# time for the basic version
CFLAGS="-O3" ./configure \
	--prefix=/usr \
	--enable-cups=no \
	--with-drivers=all \
	--with-ijs \
	--with-gimp-print=no \
	--with-omni=no
	--with-x-no
make clean
make
cat bin/gs > $PKG/usr/bin/gs-no-x11
chmod 755 $PKG/usr/bin/gs-no-x11
mkdir -p $PKG/usr/doc/gnughostscript-$VERSION
( cd $PKG/usr/doc/gnughostscript-$VERSION
  rm -rf doc examples
	ln -sf /usr/share/ghostscript/$VERSION/doc doc
	ln -sf /usr/share/ghostscript/$VERSION/examples examples )

cd $PKG
sh $CWD/gnugs.fixup

mkdir -p install
cat $CWD/slack-desc > install/slack-desc
makepkg -l y -c n ../gnugs-$VERSION-$ARCH-$BUILD.tgz
