#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG1=$TMP/idraw
PKG2=$TMP/doc
PKG3=$TMP/iv_docs
PKG4=$TMP/iv_misc
PKG5=$TMP/iv_bin
PKG6=$TMP/iv_man
PKG7=$TMP/iv_libs
PKG8=$TMP/ivdevbin

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
for pkg in $PKG1 $PKG2 $PKG3 $PKG4 $PKG5 $PKG6 $PKG7 $PKG8 ; do
  if [ ! -d $pkg ]; then
    mkdir -p $pkg # place for the package to be built
  fi
done

# Explode the package framework:
#( cd $PKG1 ; explodepkg $CWD/_emacsbin.tar.gz )
#( cd $PKG2 ; explodepkg $CWD/_emacmisc.tar.gz )
#( cd $PKG3 ; explodepkg $CWD/_elispc.tar.gz )
#( cd $PKG4 ; explodepkg $CWD/_elisp1.tar.gz )
#( cd $PKG5 ; explodepkg $CWD/_elisp2.tar.gz )
#( cd $PKG6 ; explodepkg $CWD/_emac_nox.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 "| InterViews 3.1 |"
echo "+================+"
cd $TMP
mkdir interviews
cd interviews
tar xzvf $CWD/3.1.tar.gz
zcat $CWD/iv-3.1-g++2.6.3-diffs.gz | patch -E -p0
zcat $CWD/iv-3.1-slackware.diff.gz | patch
find . -name "*.orig" -print -exec rm {} \;
cd iv
export CPU=`make CPU`
nohup make World &
#make World 

# Build the packages:
#( cd PKG1 ; tar czvf $TMP/idraw.tgz . )
#( cd PKG2 ; tar czvf $TMP/doc.tgz . )
#( cd PKG3 ; tar czvf $TMP/iv_docs.tgz . )
#( cd PKG4 ; tar czvf $TMP/iv_misc.tgz . )
#( cd PKG5 ; tar czvf $TMP/iv_bin.tgz . )
#( cd PKG6 ; tar czvf $TMP/iv_man.tgz . )
#( cd PKG7 ; tar czvf $TMP/iv_libs.tgz . )
#( cd PKG8 ; tar czvf $TMP/ivdevbin.tgz . )

# Clean up the extra stuff:
#if [ "$1" = "--cleanup" ]; then
#  rm -rf $TMP/emacs-19.28
#  rm -rf $PKG1 $PKG2 $PKG3 $PKG4 $PKG5 $PKG6 $PKG7 $PKG8
#fi
