#!/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
cp $CWD/Makefile .
make libtermnet.so.2.3.5
make
make termtest
strip 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 libtermnet.so.$TERM > $PKG/usr/lib/libtermnet.so.$TERM
for page in linecheck.1 term.1 term_clients.1 term_setup.1 termrc.1 termtest.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
for target in tmon.1.gz trdate.1.gz trdated.1.gz tredir.1.gz trsh.1.gz \
tshutdown.1.gz tudpredir.1.gz tupload.1.gz txconn.1.gz tdownload.1.gz ; do
  echo '.so man1/term_clients.1' | gzip -9c > $PKG/usr/man/man1/$target
done
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
