#!/bin/sh
#
# This script will just compile the sources and convert the fonts.
# These scripts and MathSpad are tested under
#
#  SunOS 4.1.3
#  SunOS 5.1  (Solaris i86pc)
#  SunOS 5.4  (Solaris 2.4)
#  Irix 5.1
#  Linux
#
if [ -w /usr/local ]
then
   prefix="/usr/local"
else
   prefix="`pwd`"
fi
opt_prev=
makearg=
for opt_arg
do
  if test -n "$opt_prev"; then
    eval "$opt_prev=\$opt_arg"
    opt_prev=
    continue
  fi
  case "$opt_arg" in
  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
    opt_prev=prefix ;;
  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
    prefix="`echo "$opt_arg" | sed 's/[-a-z]*=//`" ;;
  [A-Z]*=*)
    makearg="$makearg $opt_arg" ;;
  /*)
    prefix=$opt_arg ;;
  -*)
    echo "Unknow option: $opt_arg" ;;
  esac
done
MATHPADHOME=$prefix/lib/mathpad
PREFIX=$prefix
export PREFIX MATHPADHOME
echo "This install script will build MathSpad and install it in the directory"
echo
echo "       $prefix"
echo
echo "The three subdirectories bin, man/man1 and lib/mathpad are used for"
echo "installing the binary code, the manual page and the system files."
echo
echo "If you want to use a different directory, say my.directory, you need"
echo "to restart this script with the command"
echo
echo "     Install my.directory"
echo
cat Makefile | sed -e 's#PREFIX=.*#PREFIX='$prefix'#g' > Makefile.new
rm -f Makefile.bak
mv Makefile Makefile.bak
mv Makefile.new Makefile
rm -f src/*.log src/config.h src/mathpad.1 src/mathpad
make -k $makearg config
make -k all | grep -v '^make'
make -k check | grep -v '^make'
if [ -f src/.errors ] && [ "`grep -c Errors src/.errors`" = "1" ]
then
  echo "Not installing anything."
else
  echo "Installing program."
  make -k install | grep -v '^make'
fi
#
# Send a message to Eindhoven.
#
./SendMessage
