#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-gcl
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Function to handle manpage source:
man2gz () { # $1 is source page name, $2 is target name for preformatted
            # output (full path && name) and $3 is the same, but for the
            # source.
  mkdir -p `dirname $2`
  groff -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+=========+"
echo "| gcl-2.0 |"
echo "+=========+"
cd $TMP
tar xzvf $CWD/gcl-2.0.tar.gz
cd gcl-2.0
zcat $CWD/gcl-2.0.diff.gz | patch
add-defs 386-linux
make
# Seems like actually doing the "make install" is the best way to make sure
# everything is done "just exactly perfect". :^)
# So, we'll have to purge any existing stuff first...
if [ -d /usr/lib/gcl-2.0 ]; then
  ( cd /usr/lib ; rm -r gcl-2.0 )
fi
make install PREFIX_DIR=/usr
strip /usr/lib/gcl-2.0/unixport/saved_gcl /usr/lib/gcl-2.0/gcl-tk/gcltkaux
mkdir -p $PKG/usr/doc/gcl-2.0
cp -a COPYING.LIB-2.0 ChangeLog MACHINES README $PKG/usr/doc/gcl-2.0
cp -a doc $PKG/usr/doc/gcl-2.0
mkdir -p $PKG/usr/lib
( cd /usr/lib ; cp -a gcl-2.0 $PKG/usr/lib )
mkdir -p $PKG/usr/bin
chown root.bin $PKG/usr/bin
( cd /usr/bin ; cp -a gcl $PKG/usr/bin )
chown root.bin $PKG/usr/bin/gcl
mkdir -p $PKG/install
cat << EOF > $PKG/install/doinst.sh
( cd usr/bin ; rm -rf gcl.exe )
( cd usr/bin ; ln -s /usr/lib/gcl-2.0/unixport/saved_gcl gcl.exe )
EOF

# Build the package:
cd $PKG
tar czvf $TMP/gcl-2.0.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/gcl-2.0
  rm -rf $PKG
fi
