#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
# We want to build sendmail on top of this later.
PKG=$TMP/package-sendmail
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/_procmail.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 "| procmail-3.10-2 |"
echo "+=================+"
cd $TMP
tar xzvf $CWD/procmail-3.10-2.tar.gz
cd procmail-3.10
zcat $CWD/procmail-3.10-2.diff.gz | patch -p0
make
cd src
strip formail lockfile mailstat procmail
cat formail > $PKG/usr/bin/formail
cat lockfile > $PKG/usr/bin/lockfile
cat mailstat > $PKG/usr/bin/mailstat
cat procmail > $PKG/usr/bin/procmail
cd ../man
for file in formail.1 lockfile.1 procmail.1 ; do
  gzip -9c $file > $PKG/usr/man/man1/$file.gz
done
for file in procmailex.5 procmailrc.5 procmailsc.5 ; do
  gzip -9c $file > $PKG/usr/man/man5/$file.gz
done
mkdir -p $PKG/usr/doc/procmail
cd ..
cp -a FAQ FEATURES HISTORY INSTALL README $PKG/usr/doc/procmail

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

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