#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-comms
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/_comms.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 "| minicom-1.71 |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/minicom-1.71.tar.gz
cd minicom-1.71
zcat $CWD/minicom-1.71.diff.gz | patch
cd source
make
cat minicom > $PKG/usr/bin/minicom
cat runscript > $PKG/usr/bin/runscript
cat xminicom > $PKG/usr/X11R6/bin/xminicom
cd ../man
for page in minicom.1 runscript.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
echo "+=============+"
echo "| lrzsz-0.12a |"
echo "+=============+"
cd ../lrzsz-0.12a
make linux
cat lrz > $PKG/usr/bin/lrz
cat lsz > $PKG/usr/bin/lsz
for page in lrz.1 lsz.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
echo '.so man1/lrz.1' | gzip -9c > $PKG/usr/man/man1/rz.1.gz
echo '.so man1/lsz.1' | gzip -9c > $PKG/usr/man/man1/sz.1.gz

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

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