#!/bin/bash
#
# espgs.build
# Build espgs for Slackware
# Modified by Stuart Winter <stuart@armedslack.org> for ARMedslack
# and for use with slacktrack.
# 18-Sep-04

VERSION=$1
# Used (maybe) for documentation symlinks:
SHORTVER=$(echo $VERSION | cut -f 1,2 -d .)

# Extract source:
cd $SLACKTRACKSCRATCHDIR
tar jxvvf $CWD/$PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# OK, first we need the IJS library and include files.
# Since it doesn't use an soname, and is very small (about 20K)
# there's no good reason to compile it shared, and it would be
# likely to be a bad idea anyway as the author says the protocol
# is still very much in flux.
( cd ijs
  rm -f install.sh missing
  ln -sf /usr/share/automake-*/install-sh .
  ln -sf /usr/share/automake-*/missing .
  # Configure:
  CFLAGS="$SLKCFLAGS" \
  ./configure \
     --prefix=/usr || failconfig
  # Build:
  make || failmake
  # Install onto file system:
  make install )

# Now the main source is compiled.
# Build the version with X11/CUPS/Omni/gimp-print/etc support:
# Configure:
CFLAGS="$SLKCFLAGS" \
./configure \
   --prefix=/usr \
   --enable-cups \
   --with-drivers=ALL \
   --with-ijs \
   --with-gimp-print \
   --with-omni \
   --with-x \
   $ARCH-slackware-linux || failconfig
# Build:
make clean
make || failmake
# Install onto filesystem:
make install

# Now make a "basic" version of gs:
# Configure:
CFLAGS="$SLKCFLAGS" \
./configure \
   --prefix=/usr \
   --enable-cups \
   --with-drivers=ALL \
   --with-ijs \
   --with-gimp-print \
   --with-omni \
   --with-x=no \
   $ARCH-slackware-linux || failconfig
# Build:
make clean
make || failmake
# Install onto filesystem:
install -m755 bin/gs /usr/bin/gs-no-x11

# Install docs:
# This is modified from the Slackware espgs.build script because we're
# working within slacktrack/installwatch pseudo root filesystem:
( cd $SLACKTRACKFAKEROOT
  mkdir -p usr/doc/$PACKAGE-$VERSION
  cd usr/doc/$PACKAGE-$VERSION
  rm -rf doc examples
  if [ -d ../../share/ghostscript/$VERSION ]; then
    ln -sf ../../share/ghostscript/$VERSION/doc doc
    ln -sf ../../share/ghostscript/$VERSION/examples examples
  elif [ -d ../../share/ghostscript/$SHORTVER ]; then
    ln -sf ../../share/ghostscript/$SHORTVER/doc doc
    ln -sf ../../share/ghostscript/$SHORTVER/examples examples
  else
    echo
    echo "/usr/share/ghostscript/$VERSION and /usr/share/ghostscript/$SHORTVER"
    echo "not found!  Please adjust the build script."
    echo "halting."
    # this should get your attention
    sleep 12000
  fi )

# Fix up package: this stuff is taken from the .fixup script.
( cd $SLACKTRACKFAKEROOT

  # This shouldn't be in the package:
  rm -rf usr/share/libtool

  ( cd usr/man/man1
    rm -f ansi2knr.1
    ln -sf ps2ps.1  eps2eps.1
    ln -sf gslp.1   gsbj.1
    ln -sf gslp.1   gsdj.1
    ln -sf gslp.1   gsdj500.1
    ln -sf gslp.1   gslj.1
    ln -sf ps2pdf.1 ps2pdf12.1
    ln -sf ps2pdf.1 ps2pdf13.1 )

  ( cd usr/man/de/man1
    rm -f ansi2knr.1
    ln -sf ps2ps.1  eps2eps.1
    ln -sf ps2pdf.1 ps2pdf12.1
    ln -sf ps2pdf.1 ps2pdf13.1 )
)

# Install package description:
rm -rf /install
cd / && slackdesc
