#!/bin/sh
# Set initial variables:
set -e
V=0.15
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-emacspeak-dt
SRC=/devel/manpagesrc

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:
echo cd $PKG
     cd $PKG
echo tar -xzf $CWD/_emacspeak-dt.tar.gz
     tar -xzf $CWD/_emacspeak-dt.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 "| emacspeak-dt-$V |"
echo "+===================+"
echo cd $TMP
     cd $TMP
echo tar -xvzf $CWD/emacspeak-dt-$V.tar.gz
     tar -xzf $CWD/emacspeak-dt-$V.tar.gz
echo cd emacspeak-dt-$V
     cd emacspeak-dt-$V
echo ./configure --prefix=/usr
     ./configure --prefix=/usr
echo make
     make
echo make install prefix=$PKG/usr
     make install prefix=$PKG/usr \
	 bindir=$PKG/usr/lib/emacs/common/emacspeak/drivers
echo gzip -f $PKG/usr/man/man1/emacspeak-dt.1
     gzip -f $PKG/usr/man/man1/emacspeak-dt.1
echo install -d $PKG/usr/doc/emacspeak-dt
     install -d $PKG/usr/doc/emacspeak-dt
echo cp README COPYING $PKG/usr/doc/emacspeak-dt
     cp README COPYING $PKG/usr/doc/emacspeak-dt

# Build the package:
echo cd $PKG
     cd $PKG
echo chown root.root `find . -print`
     chown root.root `find . -print`
echo chown root.bin `find usr/lib/emacs/common/emacspeak/drivers -print`
     chown root.bin `find usr/lib/emacs/common/emacspeak/drivers -print`
echo tar -cvzf $TMP/emacspeak-dt.tgz .
     tar -cvzf $TMP/emacspeak-dt.tgz .

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