#!/bin/sh
# Shell script for building and installing Epoch.
# This is an alternative to `make install'.
set -x

EPOCH=/usr/local/epoch
BIN=/usr/local/bin

/bin/sed "s;/usr/local/epoch;$EPOCH;g" < src/paths.h-dist > src/paths.h
/bin/sed "s;/usr/local/epoch;$EPOCH;g" < ascii/paths.h-dist > ascii/paths.h

(cd etc; make) || exit 1
(cd src; make) || exit 1
(cd ascii; make) || exit 1	# may need to do "make LN=cp" here

# The double quotes prevent an error from sh on Suns
# when the directory does not exist yet.
if [ `pwd` != "`(cd $EPOCH; pwd)`" ]
then
  mv `pwd` $EPOCH
  if [ $? != '0' ]
  then
    mkdir $EPOCH
    echo mv `pwd` to $EPOCH failed--using tar to copy.
    tar cf - . | (cd $EPOCH; umask 0; tar xf -)
    if [ $? != '0' ]
    then
      echo tar-copying `pwd` to $EPOCH failed.
      exit 1
    fi
  fi
fi

cp $EPOCH/etc/[ce]tags $BIN
cp $EPOCH/etc/emacsclient $BIN
mv $EPOCH/src/epoch $BIN/epoch
rm $EPOCH/src/temacs

