#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
 TMP=/tmp
fi
PKG=$TMP/package-gpm
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
tar xzvf $CWD/_gpm.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 "| gpm-0.97 |"
echo "+==========+"
cd $TMP
tar xzvf $CWD/gpm-0.97.tar.gz
cd gpm-0.97
make
cat gpm > $PKG/usr/bin/gpm
cat mev > $PKG/usr/bin/mev
cat gpm-root > $PKG/usr/bin/gpm-root
cat libgpm.a > $PKG/usr/lib/libgpm.a
man2gz gpm.1 $PKG/usr/man/preformat/cat1/gpm.1.gz $SRC/usr/man/man1/gpm.1
man2gz mev.1 $PKG/usr/man/preformat/cat1/mev.1.gz $SRC/usr/man/man1/mev.1
man2gz gpm-root.1 $PKG/usr/man/preformat/cat1/gpm-root.1.gz $SRC/usr/man/man1/gpm-root.1
cat doc/gpm.info | gzip -9c > $INFO/gpm.info.gz

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

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