#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-inn
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/_inn.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 "| inn1.4 |"
echo "+========+"
cd $TMP
tar xzvf $CWD/inn1.4.tar.gz
cd inn
make all
cd frontends
cat inews > $PKG/usr/lib/news/inews
cat rnews > $PKG/usr/lib/news/rnews
cat ctlinnd > $PKG/usr/lib/news/bin/ctlinnd
cat getlist > $PKG/usr/lib/news/bin/getlist
cat innconfval > $PKG/usr/lib/news/bin/innconfval
cat encode > $PKG/usr/lib/news/bin/rnews/encode
cat decode > $PKG/usr/lib/news/bin/rnews/decode
cd ../backends
cat archive > $PKG/usr/lib/news/bin/archive
cat batcher > $PKG/usr/lib/news/bin/batcher
cat buffchan > $PKG/usr/lib/news/bin/buffchan
cat cvtbatch > $PKG/usr/lib/news/bin/cvtbatch
cat filechan > $PKG/usr/lib/news/bin/filechan
cat innxmit > $PKG/usr/lib/news/bin/innxmit
cat nntpget > $PKG/usr/lib/news/bin/nntpget
cat overchan > $PKG/usr/lib/news/bin/overchan
cat shlock > $PKG/usr/lib/news/bin/shlock
cat shrinkfile > $PKG/usr/lib/news/bin/shrinkfile
cd ../expire
cat convdate > $PKG/usr/lib/news/bin/convdate
cat expire > $PKG/usr/lib/news/bin/expire
cat expireover > $PKG/usr/lib/news/bin/expireover
cat fastrm > $PKG/usr/lib/news/bin/fastrm
cat grephistory > $PKG/usr/lib/news/bin/grephistory
cat makeactive > $PKG/usr/lib/news/bin/makeactive
cat makehistory > $PKG/usr/lib/news/bin/makehistory
cat newsrequeue > $PKG/usr/lib/news/bin/newsrequeue
cat prunehistory > $PKG/usr/lib/news/bin/prunehistory
cd ../innd
cat innd > $PKG/usr/lib/news/etc/innd
cat inndstart > $PKG/usr/lib/news/etc/inndstart
cd ../nnrpd
cat nnrpd > $PKG/usr/lib/news/etc/in.nnrpd
cd ../doc
for page in *.1 ; do
  cat $page | gzip -9c > $PKG/usr/man/man1/$page.gz
done
for page in *.3 ; do
  cat $page | gzip -9c > $PKG/usr/man/man3/$page.gz
done
for page in *.5 ; do
  cat $page | gzip -9c > $PKG/usr/man/man5/$page.gz
done
for page in *.8 ; do
  cat $page | gzip -9c > $PKG/usr/man/man8/$page.gz
done

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

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