IGNOREPATH=/etc:/home:/var:/dev:/boot:/root:/tmp:/usr/local:/bin:/sbin:/mnt:/usr/src
STRIPLIB=y
STRIPBIN=y

VERSION=8.15.3svn185
# Used for documentation symlinks:
SHORTVER=8.15

PROGNAME="espgs (ESP Ghostscript) $VERSION"
DESC="\
espgs (ESP Ghostscript)                                                \n\
                                                                       \n\
ESP Ghostscript is a customized version of GNU Ghostscript, an         \n\
interpreter of Adobe Systems' PostScript(tm) and Portable Document     \n\
Format (PDF) languages.  Ghostscript is an essential part of the       \n\
printing subsystem, taking PostScript output from applications and     \n\
converting it into an appropriate printer or display format.           \n\
Ghostscript supports many printers directly, and more are supported    \n\
through gimp-print and HPIJS, which are add-on packages that work      \n\
with Ghostscript's IJS driver."

BUILD=1
MAINTAINER="Mark Post <mark.post@eds.com>"
SOURCE=http://sourceforge.net/projects/espgs/
PKGNAME=espgs-$VERSION-s390x-$BUILD
TAG=REC

compile() {
   # 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
   tar -yxvf $CWD/espgs-$VERSION.tar.bz2
   cd espgs-$VERSION

   # Make sure -lz is used with -lpng, or PNG detection will fail
   # and PNG devices will not be included.
#  zcat $CWD/espgs.png.lz.diff.gz | patch -p1 --verbose

   # Kludge around a substitution failure that would prevent IJS from building:
#  zcat $CWD/espgs.ijs.makefile.in.bug.diff.gz | patch -p1 --verbose

   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 {} \;

   cd ijs
   rm -f install-sh missing
   ln -sf /usr/share/automake-???/install-sh .
   ln -sf /usr/share/automake-???/missing .

   CFLAGS=-O2 \
   ./configure --prefix=/usr \
               --libdir='${exec_prefix}/lib64'
   make  # CFLAGS="-ansi -pedantic -Wmissing-prototypes"

   cd $TMP
   cd espgs-$VERSION

   # Build the version with X11/CUPS/Omni/gimp-print/etc support:
   CFLAGS=-O2 \
   ./configure --prefix=/usr \
               --enable-cups \
               --with-drivers=ALL \
               --with-ijs \
               --with-gimp-print \
               --with-omni \
               --with-x \
               --host=s390x-slackware-linux \
               --build=s390x-slackware-linux \
               --target=s390x-slackware-linux
   make clean
   make
}

install() {
   ( cd ijs
     make install DESTDIR=/package-espgs
   )

#  make install prefix=/package-espgs/usr datadir=/package-espgs/usr/share 
   make install prefix=/package-espgs/usr \
                mandir=/package-espgs/usr/man install_prefix=/package-espgs

# This little bit of nonsense is necessary because the pstoraster stuff doesn't
# use $prefix, it uses $install_prefix.  This results in other pieces that _do_
# use $prefix (_and_ $install_prefix) winding up in /package-espgs/package-espgs.
# Ugh.
   ( cd /package-espgs
     mv package-espgs/usr/share/ghostscript /package-espgs/usr/share
     rm -rf package-espgs
   )
 
   mkdir -p /package-espgs/usr/doc/espgs-$VERSION
   ( cd /package-espgs/usr/doc/espgs-$VERSION
     ln -sf /usr/share/ghostscript/$SHORTVER/doc doc
     ln -sf /usr/share/ghostscript/$SHORTVER/examples examples
   )

#  mkdir -p /package-espgs/usr/lib
#  ( cd ijs
#    cp -a libijs.a /package-espgs/usr/lib/libijs.a
#    cp -a ijs-config /package-espgs/usr/bin/ijs-config
#    mkdir -p /package-espgs/usr/include/ijs
#    cp -a ijs.h ijs_client.h ijs_server.h /package-espgs/usr/include/ijs
#  ) 

   # Now make a "basic" version of gs:
   CFLAGS=-O2 \
   ./configure --prefix=/usr \
               --enable-cups \
               --with-drivers=ALL \
               --with-ijs \
               --with-gimp-print \
               --with-omni \
               --with-x=no \
               --host=s390x-slackware-linux \
               --build=s390x-slackware-linux \
               --target=s390x-slackware-linux
   make clean
   make
   cp -a bin/gs /package-espgs/usr/bin/gs-no-x11

   rm -v /package-espgs/usr/man/de/man1/gs?j*
   ( cd /package-espgs/usr/man
     for dir in de/man1 man1; do
       ( cd $dir
         rm -f *.gz
         gzip -9 *.1
       )
     done
   )

   ( cd /package-espgs/usr/man/de/man1
     rm -rf eps2eps.1  ; ln -sf ps2ps.1.gz eps2eps.1.gz
     rm -rf ps2pdf12.1 ; ln -sf ps2pdf.1.gz ps2pdf12.1.gz
     rm -rf ps2pdf13.1 ; ln -sf ps2pdf.1.gz ps2pdf13.1.gz
   )

   ( cd /package-espgs/usr/man/man1
     rm -rf eps2eps.1  ; ln -sf ps2ps.1.gz eps2eps.1.gz
     rm -rf gsbj.1     ; ln -sf gslp.1.gz gsbj.1.gz
     rm -rf gsdj.1     ; ln -sf gslp.1.gz gsdj.1.gz
     rm -rf gsdj500.1  ; ln -sf gslp.1.gz gsdj500.1.gz
     rm -rf gslj.1     ; ln -sf gslp.1.gz gslj.1.gz
     rm -rf ps2pdf12.1 ; ln -sf ps2pdf.1.gz ps2pdf12.1.gz
     rm -rf ps2pdf13.1 ; ln -sf ps2pdf.1.gz ps2pdf13.1.gz
   )
}

attributes() {
   echo #chown -R root.bin $PKG/package-espgs/usr/bin
}

special() {
   cd $PKG
   mv package-espgs/* ./
   rmdir package-espgs

   cd $CTL
   cat $CWD/slack-desc > slack-desc

   sed -e 's%package-espgs/%%g' doinst.sh > doinst.sh.new
   cat doinst.sh.new > doinst.sh
   rm doinst.sh.new
}

