#!/bin/sh
cerror="0"
ccerror="0"
lderror="0"
errors="0"
missing="No"
if [ -f "makeC.log" ]
then
  cerror="`grep -c '\\.c.*[1-9][0-9]*:' makeC.log`"
else
  missing=$missing"-C"
fi
if [ -f "makeC++.log" ]
then
  ccerror="`grep -c '\\.[cC].*[1-9][0-9]*:' makeC++.log`"
else
  missing=$missing"-C++"
fi
if [ -f "makeld.log" ]
then
  lderror="`egrep -c 'ld:|fail' makeld.log`"
else
  missing=$missing"-ld"
fi
echo "#C: $cerror, C++: $ccerror, ld: $lderror, missing: $missing" >> config.log
echo
rm -f .errors
errors="`expr $cerror + $ccerror + $lderror`"
success="Y"
if [ "`echo make*.log`" != "make*.log" ]
then
  if [ "$errors" = "0" ]
  then
    if [ -f makeld.log -a -x mathpad ]
    then
      echo
    else
      echo "Sorry, something went wrong. Maybe the disk is full, you don't"
      echo "have a C++ compiler or the compiler generates strange error"
      echo "messages. If you have solved the problem, you can try again."
      echo
      echo "errors" >> .errors
      success="N"
    fi
  else
    if [ -x mathpad ]
    then
      echo "There were some warnings. MathSpad can run."
      echo "Warnings: C   code  $cerror"
      echo "          C++ code  $ccerror"
      echo "          Linking   $lderror"
      echo
      echo "warnings" >> .errors
    else
      echo "There where some problems. MathSpad will not work."
      echo "Errors:   C   code  $cerror"
      echo "          C++ code  $ccerror"
      echo "          Linking   $lderror"
      echo
      echo "Sorry that it doesn't work on your site. If you can solve"
      echo "the problems yourself, would you be so kind as to mail your"
      echo "solution to mathpad@win.tue.nl, so we can adjust the"
      echo "program and the installation script. If you can't solve"
      echo "the problems, you can mail the *.log files and somebody"
      echo "will try to help you as soon as possible."
      echo
      echo "errors" >> .errors
      success="N"
    fi
  fi
  if [ "$success" = "Y" ]
  then
    echo "The installation is complete.  We recommend that you try running"
    echo "MathSpad to see that all is well.  When you are confident that is"
    echo "the case execute CleanUp in order to remove various unwanted files."
    echo "(If you execute CleanUp now and have to recompile the system later"
    echo "you may need to unpack the distribution once more.)"
  fi
fi
