#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-lpr
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/_lpr.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 "| lpr |"
echo "+=====+"
cd $TMP
tar xzvf $CWD/lpr.tar.gz
cd lpr
make
cd lpr/lpc
cat lpc > $PKG/usr/sbin/lpc
cat lpc.8 | gzip -9c > $PKG/usr/man/man8/lpc.8.gz
cd ../filters
cat lpf > $PKG/usr/sbin/lpf
cd ../lpd
cat lpd > $PKG/usr/sbin/lpd
cat lpd.8 | gzip -9c > $PKG/usr/man/man8/lpd.8.gz
cd ../lpq
cat lpq > $PKG/usr/bin/lpq
cat lpq.1 | gzip -9c > $PKG/usr/man/man1/lpq.1.gz
cd ../lpr
cat lpr > $PKG/usr/bin/lpr
cat lpr.1 | gzip -9c > $PKG/usr/man/man1/lpr.1.gz
cd ../lprm
cat lprm > $PKG/usr/bin/lprm
cat lprm.1 | gzip -9c > $PKG/usr/man/man1/lprm.1.gz
cd ../lptest
cat lptest > $PKG/usr/sbin/lptest
cat lptest.1 | gzip -9c > $PKG/usr/man/man1/lptest.1.gz
cd ../pac
cat pac > $PKG/usr/sbin/pac
cat pac.8 | gzip -9c > $PKG/usr/man/man8/pac.8.gz
cd ..
cat printcap.5 | gzip -9c > $PKG/usr/man/man5/printcap.5.gz

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

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