#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-termbin
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

# Explode the package framework:
cd $PKG
tar xzvf $CWD/_termbin.tar.gz

# 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 "| term-2.3.5 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/../termsrc/term-2.3.5.tar.gz
cd term-2.3.5
cp $CWD/../termsrc/configure.slackware .
configure.slackware
make install
make
make
cat linecheck > $PKG/usr/bin/linecheck
cat tdownload > $PKG/usr/bin/tdownload
cat term > $PKG/usr/bin/term
cat tmon > $PKG/usr/bin/tmon
cat trdate > $PKG/usr/bin/trdate
cat tredir > $PKG/usr/bin/tredir
cat trsh > $PKG/usr/bin/trsh
cat tshutdown > $PKG/usr/bin/tshutdown
cat tudpredir > $PKG/usr/bin/tudpredir
cat tupload > $PKG/usr/bin/tupload
cat txconn > $PKG/usr/bin/txconn
cat libtermnet.a > $PKG/usr/lib/libtermnet.a
cat shared/libtermnet.sa > $PKG/usr/lib/libtermnet.sa
cat shared/libtermnet.so.2.3.5 > $PKG/usr/lib/libtermnet.so.2.3.5

# Build the package:
cd $PKG
tar czvf $TMP/termbin.tgz .

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