#!/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
explodepkg $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 
}

# Just set this to the current version of TERM, and away it goes...
TERM="2.3.5"
echo "+============+"
echo "| term-$TERM |"
echo "+============+"
cd $TMP
tar xzvf $CWD/../termsrc/term-$TERM.tar.gz
cd term-$TERM
cp $CWD/../termsrc/configure.slackware .
configure.slackware
make install
make
make termtest
strip shared/libtermnet.so.$TERM termtest linecheck tdownload term tmon \
trdate tredir trsh tshutdown tudpredir tupload txconn 
cat termtest > $PKG/usr/bin/termtest
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.$TERM > $PKG/usr/lib/libtermnet.so.$TERM
man2gz linecheck.1 $PKG/usr/man/preformat/cat1/linecheck.1.gz $SRC/usr/man/man1/linecheck.1
man2gz term.1 $PKG/usr/man/preformat/cat1/term.1.gz $SRC/usr/man/man1/term.1
man2gz term_clients.1 $PKG/usr/man/preformat/cat1/term_clients.1.gz $SRC/usr/man/man1/term_clients.1
man2gz term_setup.1 $PKG/usr/man/preformat/cat1/term_setup.1.gz $SRC/usr/man/man1/term_setup.1
man2gz termrc.1 $PKG/usr/man/preformat/cat1/termrc.1.gz $SRC/usr/man/man1/termrc.1
man2gz termtest.1 $PKG/usr/man/preformat/cat1/termtest.1.gz $SRC/usr/man/man1/termtest.1
cp -a CHANGES COPYING CREDITS FAQ INSTALL READM* SCO.CHANGES TERMRC TODO Term.HOWTO $PKG/usr/doc/term
cp -a samples/* $PKG/usr/doc/term/samples
chown -R root.root $PKG/usr/doc/term

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

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