#!/bin/sh
# Set initial variables:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-espgs
VER=8.15.4
VERSION=8.15
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
# 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 $TMP
rm -rf espgs-$VER
tar xjf $CWD/espgs-$VER-source.tar.bz2
cd espgs-$VER
chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
# Make sure -lz is used with -lpng, or PNG detection will fail
# and PNG devices will not be included.
cd ijs
rm -rf install.sh missing
ln -sf /usr/share/automake-1.9/install-sh .
ln -sf /usr/share/automake-1.9/missing .
./configure \
 --prefix=/usr \
 --build=$TARGET
make || exit
make install
make install DESTDIR=$PKG

# Now the main source is compiled:
# Build the version with X11/CUPS/Omni/gimp-print/etc support:
cd $TMP/espgs-$VER
./configure \
 --prefix=/usr \
 --enable-cups \
 --with-drivers=ALL \
 --with-ijs \
 --with-gimp-print \
 --with-omni \
 --with-x \
 --mandir=/usr/man \
 --enable-threads \
 --enable-dynamic \
 --build=$TARGET
make || exit
make install_prefix=$PKG install
make distclean

# Now make a "basic" version of gs:
cd $TMP/espgs-$VER
./configure \
 --prefix=/usr \
 --enable-cups \
 --with-drivers=ALL \
 --with-ijs \
 --with-gimp-print \
 --with-omni \
 --with-x=no \
 --mandir=/usr/man \
 --enable-threads \
 --enable-dynamic \
 --build=$TARGET
make || exit
cat bin/gs > $PKG/usr/bin/gs-no-x11

( gzip -9 $PKG/usr/man/{man1,de/man1}/* )
( rm -rf $PKG/usr/man/{man1,de/man1}/*.1 )
( cd $PKG/usr/man/man1 ; ln -sf gslp.1.gz gsbj.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf gslp.1.gz gsdj.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf gslp.1.gz gsdj500.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf gslp.1.gz gslj.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf ps2ps.1.gz eps2eps.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf ps2pdf.1.gz ps2pdf12.1.gz )
( cd $PKG/usr/man/man1 ; ln -sf ps2pdf.1.gz ps2pdf13.1.gz )
( cd $PKG/usr/man/de/man1 ; ln -sf ps2ps.1.gz eps2eps.1.gz )
( cd $PKG/usr/man/de/man1 ; ln -sf ps2pdf.1.gz ps2pdf12.1.gz )
( cd $PKG/usr/man/de/man1 ; ln -sf ps2pdf.1.gz ps2pdf13.1.gz )

( cd $PKG
 find . -type f | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . -type f | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/espgs-$VER-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/espgs.build.log
