#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-uucp
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/_uucp.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 "| uucp-1.05 |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/uucp-1.05.tar.gz
cd uucp-1.05
make
cat cu > $PKG/usr/bin/cu
cat uucp > $PKG/usr/bin/uucp
cat uuname > $PKG/usr/bin/uuname
cat uustat > $PKG/usr/bin/uustat
cat uux > $PKG/usr/bin/uux
cat uuchk > $PKG/usr/lib/uucp/uuchk
cat uucico > $PKG/usr/lib/uucp/uucico
cat uuconv > $PKG/usr/lib/uucp/uuconv
cat uuxqt > $PKG/usr/lib/uucp/uuxqt
man2gz cu.1 $PKG/usr/man/preformat/cat1/cu.1.gz $SRC/usr/man/man1/cu.1
man2gz uucp.1 $PKG/usr/man/preformat/cat1/uucp.1.gz $SRC/usr/man/man1/uucp.1
man2gz uustat.1 $PKG/usr/man/preformat/cat1/uustat.1.gz $SRC/usr/man/man1/uustat.1
man2gz uux.1 $PKG/usr/man/preformat/cat1/uux.1.gz $SRC/usr/man/man1/uux.1
man2gz uucico.8 $PKG/usr/man/preformat/cat8/uucico.8.gz $SRC/usr/man/man8/uucico.8
man2gz uuxqt.8 $PKG/usr/man/preformat/cat8/uuxqt.8.gz $SRC/usr/man/man8/uuxqt.8
makeinfo uucp.texi
cat uucp.info | gzip -9c > $INFO/uucp.info.gz
cat uucp.info-1 | gzip -9c > $INFO/uucp.info-1.gz
cat uucp.info-2 | gzip -9c > $INFO/uucp.info-2.gz
cat uucp.info-3 | gzip -9c > $INFO/uucp.info-3.gz
cat uucp.info-4 | gzip -9c > $INFO/uucp.info-4.gz
cp uucp.texi $TEX/uucp.texi

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

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