#!/bin/sh
#
# The default C and C++ compilers to look for. The last one that is available,
# will be used. So, a better compiler should be added at the end.
#
default_c_compiler="cc acc gcc"
default_CC_compiler="xlC CC g++"
#
# gcc is usually also a C++ compiler.
#
# some echo commands don't recognize \c and use the -n option
#
PWD="`pwd`"
if [ -f config.h ]
then
  config="1"
  mplibdir="`grep MATHPADHOME config.h | sed -e 's/.*\"\(.*\)\"/\1/g'`"
  delbssw="`grep DEL_BACK_SWITCH config.h | sed -e 's/.*\([01]\)/\1/g'`"
else
  config="0"
  if [ "x$MATHPADHOME" = "x" ]
  then
    mplibdir="`dirname $PWD`/lib"
  else
    mplibdir="$MATHPADHOME"
  fi
  delbssw="0"
fi
ecc="echo"
ecs="\c"
if [ "`(echo 'test\c';echo 'test') | wc | awk '{print $1}'`" != "1" ]
then
  ecc="echo -n"
  ecs=""
fi
if [ "x$path" = "x" ]
then
  path="`echo $PATH | sed -e 's/:/ /g'`"
fi
#/usr/ccs/bin contains some programming utilities on solaris
path=". $path /usr/ccs/bin"
if [ -f config.log ]
then
  lastpath="`grep 'LASTPATH=' config.log | sed -e 's/#LASTPATH=//g'`"
  mv config.log config.bak
else
  lastpath="$path"
fi
if [ -f config.h ]
then
  config="1"
  mplibdir="`grep MATHPADHOME config.h | sed -e 's/.*\"\(.*\)\"/\1/g'`"
  delbssw="`grep DEL_BACK_SWITCH config.h | sed -e 's/.*\([01]\)/\1/g'`"
else
  config="0"
  if [ "x$MATHPADHOME" = "x" ]
  then
    mplibdir="`dirname $PWD`/lib"
  else
    mplibdir="$MATHPADHOME"
  fi
  delbssw="0"
fi
echo "## Version: 0.60" > config.log
echo "## Uname : `uname -a`" >> config.log
echo "## Date  : `date`" >> config.log
echo "#LASTPATH=$path" >> config.log
echo "MATHPADHOME=$mplibdir" >> config.log
echo "DEL_BACK_SWITCH=$delbssw" >> config.log
#
# maybe the options should be parsed to pass them to the compilers.
#
mkdir testcomp
if [ "x$CC" != "x" ]
then
  ccom="$CC"
  echo "Using specified C compiler $ccom ."
else
  ccom=""
  $ecc "Searching for a C compiler ..."$ecs
  searchstr="$default_c_compiler"
  foundstr=""
  for file in $searchstr
  do
    whicharg="$file"
    whichfnd="F"
    for dir in $path
    do
      if [ -x $dir/$whicharg ]
      then
        whichfnd="T"
        whicharg="$dir/$whicharg"
        break
      fi
    done
    if [ "$whichfnd" = "T" ]
    then
      foundstr="$foundstr $whicharg"
    fi
  done
  echo "##Available C compiler:" >> config.log
  if [ "x$foundstr" = "x" ]
  then
    echo "##NONE" >> config.log
    echo "?!?";echo
    echo "Your C compiler doesn't have one of the usual names ($searchstr)."
    $ecc "Searching for possible replacements (using the man pages) ..."$ecs
    searchstr="`man -k compiler 2> /dev/null | grep ' C ' | \
		sed -e 's/,/ /g' -e 's/(/ /g' | awk '{print $1}' | sort -u`"
    foundstr=""
    for file in $searchstr
    do
      whicharg="$file"
      whichfnd="F"
      for dir in $path
      do
        if [ -x $dir/$whicharg ]
        then
          whichfnd="T"
          whicharg="$dir/$whicharg"
          break
        fi
      done
      if [ "$whichfnd" = "T" ]
      then
        foundstr="$foundstr $whicharg"
      fi
    done
    echo " done."
    if [ "x$foundstr" = "x" ]
    then
      echo
      echo "Still nothing found."
      echo "##ABSOLUTELY NONE" >> config.log
    else
      echo
      echo "Possible C compilers:$foundstr"
      $ecc 'Testing these "compilers" ...'$ecs
      echo "##MAYBE $foundstr" >> config.log
      cd testcomp
      echo "#include <stdio.h>
            main(){dummypf("'"Compiler"'");}
            dummypf(c) char *c;{printf(c);}" > comptest.c
      searchstr="$foundstr"
      foundstr=""
      nrfound="0"
      for ccomd in $searchstr
      do
        rm -f comptest
        $ccomd -Dcomptest -o comptest comptest.c 2> /dev/null > /dev/null &
        waitproc="$!"
        (sleep 60; if [ "`ps | awk '{print $1}' | grep $!`" = "$!" ]; then
	    kill -9 $!;echo "#Killed" >> ../config.log; fi)&
        wait $waitproc
        $ecc " ..."$ecs
        if [ -x comptest ] && [ "`./comptest`" = "Compiler" ]
        then
          foundstr="$foundstr $ccomd"
          nrfound="`expr $nrfound + 1`"
          ccom="$ccomd"
          echo "##C: $ccomd" >> ../config.log
        fi
      done
      cd ..
      echo " done."
      if [ "x$foundstr" = "x" ]
      then
        echo "Sorry, they don't pass the test. It seems like you don't"
        echo "have any compilers or I'm looking for the wrong thing."
        if [ "$path" = "$lastpath" ]
        then
          echo "It may be possible to resolve the problem by extending your"
          echo "path variable and trying again.  If you are not an expert in"
	  echo "these matters consult your system manager."
        else
          echo "Your path still doesn't contain any compiler. Maybe you"
          echo "really do need to consult your system manager."
        fi
        echo "##SORRY. NO C COMPILER." >> config.log
      else
        if [ "$nrfound" = "1" ]
        then
          echo "I found one compiler ($foundstr)."
          echo "I have never worked with this one, so don't expect too much."
        else
          echo "I found several compilers ($foundstr)."
          echo "I have never worked with these, so don't expect too much."
          echo "I will use $ccom. If you want a different one,"
          echo "you have to change this script or the file Makefile ."
        fi
      fi
    fi
  else
    for ccomd in $foundstr
    do
      echo "##C: $ccomd" >> config.log
      ccom="$ccomd"
    done
    echo " ok."
#  echo "Available C compilers are$foundstr."
    echo "Using $ccom."
  fi
fi
echo "##Using C: $ccom" >> config.log
if [ "x$ccom" = "x" ]
then
  echo "##Using default: cc" >> config.log
  echo "I hope cc is somehow available."
  ccom="cc"
fi
if [ "`basename $ccom`" = "gcc" ]
then
 echo "## Version: `gcc -v 2>&1 | grep version`" >> config.log
fi
echo "CC=$ccom" >> config.log
if [ "x$CXX" != "x" ]
then
  cccom="$CXX"
  echo "Using specified C++ compiler: $cccom ."
else
  $ecc "Searching for a C++ compiler ..."$ecs
  cccom=""
  searchstr="$default_CC_compiler"
  foundstr=""
  for file in $searchstr
  do
    whicharg="$file"
    whichfnd="F"
    for dir in $path
    do
      if [ -x $dir/$whicharg ]
      then
        whichfnd="T"
        whicharg="$dir/$whicharg"
        break
      fi
    done
    if [ "$whichfnd" = "T" ]
    then
      foundstr="$foundstr $whicharg"
    fi
  done
  echo "##Available C++ compiler:" >> config.log
  if [ "x$foundstr" = "x" ]
  then
    echo "##NONE" >> config.log
    echo "?!?";echo
    echo "Your C++ compiler doesn't have one of the usual names ($searchstr)."
    $ecc "Searching for possible replacements (using the man pages) ..."$ecs
    searchstr="`(man -k compiler;man -k translator) 2> /dev/null | grep 'C++' |
  	     sed -e 's/,//g' | awk '{print $1}' | sort -u`"
    foundstr=""
    for file in $searchstr
    do
      whicharg="$file"
      whichfnd="F"
      for dir in $path
      do
        if [ -x $dir/$whicharg ]
        then
          whichfnd="T"
          whicharg="$dir/$whicharg"
          break
        fi
      done
      if [ "$whichfnd" = "T" ]
      then
        foundstr="$foundstr $whicharg"
      fi
    done
    echo " done."
    if [ "x$foundstr" = "x" ]
    then
      echo
      echo "Still nothing found."
      echo "##ABSOLUTELY NONE" >> config.log
    else
      echo
      echo "Possible C++ compilers:$foundstr"
      $ecc 'Testing these "compilers" ...'$ecs
      echo "##MAYBE $foundstr" >> config.log
      cd testcomp
      echo 'extern "C" {
            #include <stdio.h>
            }
            class dummy {
              public:
              void test(int &i) { i=i+1; }
            };
            dummy t1;
            int main(int,char **)
            {
               int i=0; t1.test(i);
               printf("%s", (i?"C++":"C"));
            }' > comptest.C
      searchstr="$foundstr"
      foundstr=""
      nrfound="0"
      for ccomd in $searchstr
      do
        rm -f comptest
        $ccomd -Dcomptest -o comptest comptest.C 2> /dev/null > /dev/null &
        waitproc="$!"
        (sleep 90; if [ "`ps | awk '{print $1}' | grep $!`" = "$!" ]; then
	      kill -9 $!;echo "#Killed" >> ../config.log; fi)&
        wait $waitproc
        $ecc " ..."$ecs
        if [ -x comptest ] && [ "`./comptest`" = "C++" ]
        then
          foundstr="$foundstr $ccomd"
          nrfound="`expr $nrfound + 1`"
          cccom="$ccomd"
          echo "##C++: $ccomd" >> ../config.log
        fi
      done
      cd ..
      echo " done."
      if [ "x$foundstr" = "x" ]
      then
        echo "Sorry, they don't pass the test. It seems like you don't"
        echo "have any C++ compilers or I'm looking for the wrong thing."
        if [ "$path" = "$lastpath" ]
        then
          echo "It may be possible to resolve the problem by extending your"
	  echo "path variable and trying again.  If you are not an expert in"
	  echo "these matters consult your system manager."
        else
          echo "Your path still doesn't contain any compiler. Maybe you"
          echo "really do need to consult your system manager."
        fi
        echo "##SORRY. NO C++ COMPILER." >> config.log
      else
        if [ "$nrfound" = "1" ]
        then
          echo "I found one C++ compiler ($foundstr)."
          echo "I have never worked with this one, so don't expect too much."
        else
          echo "I found several C++ compilers ($foundstr)."
          echo "I have never worked with these, so don't expect too much."
          echo "I will use $cccom. If you want a different one,"
          echo "you have to change this script or the file config.log ."
        fi
      fi
    fi
  else
    for ccomd in $foundstr
    do
      echo "##C++: $ccomd" >> config.log
      cccom="$ccomd"
    done
    echo " ok."
#  echo "Available C++ compilers are$foundstr."
    echo "Using $cccom."
  fi
fi
echo "##Using C++: $cccom" >> config.log
if [ "$cccom" = "" ]
then
  echo "##Using default: CC" >> config.log
  echo "I hope CC is somehow available."
  cccom="CC"
fi
if [ "`basename $cccom`" = "g++" ]
then
 echo "## Version: `g++ -v 2>&1 | grep version`" >> config.log
fi
echo "CXX=$cccom" >> config.log

#Checking for possible options that need to be added.
defineopt="$DEFINES"
includeopt="$INCLUDE"
#
# The LD_LIBRARY_PATH adds directories to the ld-path at compile time
# but does not insert them in the final object. Users need to
# set LD_LIBRARY_PATH to the same value in order to run the program.
# This construction will add the LD_LIBRARY_PATH to the load options,
# so the path WILL appear in the final object.
# (This works on SunOs 4.1.3.)
#
ldopt="$LDLIBS"
for name in `echo $LD_LIBRARY_PATH | tr ':' ' '`
do
ldopt="$ldopt -L$name"
done
x11add=""
puntdir=""
passnr="1"
missed="0"
missedfile=""
incpath="`echo $path | sed 's#bin#include#g'`"
until [ "$missed" != "0" ]
do
  $ecc "Testing existence of include files "$ecs
  case $passnr in
  1) $ecc "(first  pass) ... "$ecs ;;
  2) $ecc "(second pass) ... "$ecs ;;
  3) $ecc "(final  pass) ... "$ecs ;;
  *) echo "doesn't make sense on this system."; break ;;
  esac
  echo "##Include file: pass $passnr" >> config.log
  passnr="`expr $passnr + 1`"
  if $ccom $defineopt $includeopt -E test.c 2>test.err 1>/dev/null
  then
    errorsc=""
  else
    errorsc="`grep '\.h' test.err | \
	    sed -e 's#^..*[^a-zX1/]\([a-zX1/]*\.h\).*#\1#g' | \
            grep -v '^/' | awk '{ printf \" \"$1 }'`"
  fi
  rm -f test.err
  if [ "$errorsc" != "" ]
  then
    missed="0"
    missedfile=""
    echo " error."
    echo "Missing $errorsc."
    echo "##Missing $errorsc." >> config.log
    echo "Trying to find them ..."
    for file in $errorsc
    do
      if [ "`dirname $file`" = "X11" ]
      then
# All include files are located in the same directory. Once you have
# found the first one, you have found them all.
        if [ "$x11add" = "" ]
        then
# Filter path in order to find an X11 directory (usually /usr/X11/bin)
          for dir in $incpath /usr/include /usr/include/X* \
		/usr/include/X*/include /usr/X*/include /usr/openwin/include \
		/usr/motif/include
          do
	    if [ -d "$dir" ]
            then
              echo "#Directory: $dir" >> config.log
              if [ -f "$dir/$file" -a "$x11add" = "" ]
              then
                x11add="T"
                echo "X11 include files found in $dir ."
                echo "## X11 include files in $dir" >> config.log
	        includeopt="$includeopt -I$dir"
		break
              fi
            fi 
          done
          if [ "$x11add" = "" ]
          then
            echo "Unable to find X11 include files."
            echo "## No X11 include files found." >> config.sys
            x11add="F"
          fi
        fi
        if [ "$x11add" = "F" ]
        then
          missed="`expr "$missed" + 1`"
          missedfile="$missedfile $file"
        fi
      else
#
# A "standard" file is missing. Try to find it, make a link in the
# current directory and add -I. to includeopt. Adding the directory
# where the file was found will not work.
#
        foundstr=""
	bname="`basename $file`"
	if [ -f $file ]
        then
	  echo "Found $file in a previous run."
          echo "## File: $file" >> config.log
          if [ "$puntadd" = "" ]
          then
            includeopt="$includeopt -I."
            puntadd="T"
          fi
          break
	fi          
        for dir in /usr/include /usr/include/sys /usr/include/*[a-zA-Z0-9]? \
		$incpath
        do
	  if [ -f "$dir/$file" ]
	  then
            fname="$dir/$file"
          elif [ -f "$dir/$bname" ]
          then
            fname="$dir/$bname"
          else
            fname=""
          fi
          if [ "$fname" != "" ]
          then
            echo "Found $file as $fname ."
            echo "##File: $fname" >> config.log
            if [ ! -d "`dirname $file`" ]
            then
              mkdir -p "`dirname $file`"
            fi
            ln -s $fname $file
            foundstr="T"
            if [ "$puntadd" = "" ]
            then
               includeopt="$includeopt -I."
               puntadd="T"
            fi
            break
          fi
        done
        if [ "$foundstr" = "" ]
        then
           missed="`expr $missed + 1`"
           missedfile="$missedfile $file"
        fi
      fi
    done
    if [ "$missed" = "0" ]
    then
      echo "##All found." >> config.log
    fi
  else
    echo "ok."
    break
  fi
done
if [ "$missed" != "0" ]
then
  if [ "$missed" = "1" ]
  then
    echo "Unable to find the include file$missedfile."
  else
    echo "Unable to find several include files: $missedfile"
  fi
  echo "##NOT FOUND $missedfile" >> config.log
  echo "Compilation will probably fail."
fi
#
# On some DEC systems the Xlib.h include file is corrupt.
#
cd testcomp
$ecc "Checking Xlib.h ..."$ecs
(echo "#include <X11/Xlib.h>";echo "int test() { return 0; }") > comptest.c
errorsc="`$ccom $includeopt -c comptest.c 2>&1 | grep -c -i error`"
if [ "$errorsc" != "0" ]
then
  echo " error."
  echo "## Xlib.h test failed." >> ../config.log
  defineopt="$defineopt -DNeedFunctionPrototypes=0"
  errorsc="`$ccom $includeopt $defineopt -c comptest.c 2>&1 | grep -c -i error`"
  echo "Adding -DNeedFunctionPrototypes=0"
  if [ "$errorsrc" = "0" ]
  then
    echo "##Define -DNeedFunctionPrototypes=0 is needed." >> ../config.log
  fi
else
  echo " ok."
fi
$ecc "Checking X11 library ..."$ecs
echo "int main(c,v) int c; char **v;{ return 0; }" > comptest.c
errorsc="`$ccom -o comptest comptest.c $ldopt -lX11  2>&1 | grep -c X11`"
if [ "$errorsc" = "1" ]
then
  echo " error."
  echo "## X11 library test failed." >> ../config.log
  $ecc "Searching for X11 link library..."$ecs
  libpath="`echo $path | sed 's#bin#lib#g'`"
  ldadded=""
  for dir in $libpath /usr/lib /usr/X*/lib /usr/lib/X* /usr/openwin/lib \
      /usr/motif/lib
  do
    if [ -d "$dir" ]
    then
      errorsc="`$ccom -o comptest comptest.c $ldopt -L$dir -lX11 2>&1 | grep -c lX11`"
      if [ "$errorsc" = "0" ]
      then
        if [ "$ldadded" = "" ]
        then
          ldadded="-L$dir"
          echo "##LIBRARY: $dir" >> ../config.log
          break
        fi
      fi
    fi
  done
  if [ "$ldadded" = "" ]
  then
    echo " error."
    echo "Unable to find X11 library."
  else
    echo " ok."
    echo "Adding option $ldadded"
    ldopt="$ldopt $ldadded "
  fi
else
  echo " ok."
fi
ldopt="${ldopt} -lX11"
ccext="cc"
#Some people don't install the g++ library, so -lg++ (-lstdc++) will not work.
errorsc="0"
if [ "`basename $cccom`" = "g++" ]
then
  if [ -f "../libg++.a" ]
  then
    ldopt="-L. $ldopt"
  else
    $ecc "Checking g++ library ..."$ecs
    echo "int main(int c, char **v) { return 0; }" > comptest.$ccext
    errorsc="`$cccom -o comptest comptest.$ccext -L.. 2>&1 | grep -c ++`"
    if [ "$errorsrc" > "0" ]
    then
      echo " error.";
      errorsc="1";
    else
      echo " ok.";
    fi
  fi
fi
if [ "$errorsc" = "1" ]
then
  echo "Error: g++ library missing."
  echo "##g++ library missing" >> ../config.log
# create a dummy library. This is very system dependent
#
# a library should contain at least one object file, so create an
# object file with a dummy function. ld might complain that
# this library didn't solve anything, but compilation will be possible.
#
  echo 'int mpdfwsnbu() { return 0; }' > comptest.c
  $ccom -c comptest.c
  ar cr ../libg++.a comptest.o 2>/dev/null 1>/dev/null
  ranlib ../libg++.a 2>/dev/null 1>/dev/null
  ln -s libg++.a ../libstdc++.a
  if [ -f "../libg++.a" ]
  then
    if $cccom -L.. -o comptest comptest.$ccext 2>/dev/null 1>/dev/null
    then
      echo "Created dummy library libg++.a ."
      echo "##Made libg++.a and libstdc++.a" >> ../config.log
    else
      echo "Unable to create a dummy library for libg++.a."
      echo "##Failed on libg++.a." >> ../config.log
    fi
  fi
  if [ -f "../libg++.a" ]
  then
    ldopt="-L. $ldopt"
    errorsc="0"
  else
    foundstr="`$cccom -v 2>&1 | grep specs | sed -e 's/.* \(\/.*\)\/specs/\1/g'`"
    if [ -f "$foundstr/libg++.a" ]
    then
      foundstr="$foundstr/libg++.a"
    elif [ -f "$foundstr/libgcc.a" ]
    then
      foundstr="$foundstr/libgcc.a"
    else
      foundstr=""
    fi
    if [ "$foundstr" != "" ]
    then
      echo "##gcc library found $foundstr" >> ../config.log
      ldopt="-L. $ldopt"
      ln -s $foundstr ../libg++.a
      ln -s $foundstr ../libstdc++.a
    fi
    errorsc="`$cccom -o comptest comptest.$ccext -L.. 2>&1 | grep -c lg++`"
  fi
  if [ "$errorsc" = "0" ]
  then
    echo "Please report to your system manager that the g++ libraries are"
    echo "not correctly installed.  MathSpad doesn't use special functions"
    echo "from these libraries. To be able to complete the installation"
    echo "two dummy libraries are created. Compilation will probably work."
  fi
fi
if [ "$errorsc" != "0" ]
then
  echo "The g++ libraries are not correctly installed and compilation will"
  echo "probably fail.  A possible solution would be to create the missing"
  echo "libraries with the commands"
  echo "      ar cr src/libg++.a src/debug.o"
  echo "      ar cr src/libstdc++.a src/debug.o"
  echo "but 'ar' is not available (or works different)."
  echo "Ask your system manager for help or use a different compiler by"
  echo "specifing is on the command line like './Install CC=cc CXX=c++'"
  echo "Compilation will probably fail."
fi
# check extension.
echo "int main(int c, char **v) { return 0; }" > comptest.cc
rm -f comptest
$cccom -o comptest comptest.cc -L.. 2>/dev/null > /dev/null
if [ -x comptest ]
then
  ccext="cc"
else
  ccext="C"
  for file in editor editwindow mark marker mathpad node select
  do
    rm -f ../$file".C"
    ln -s $file".cc" ../$file".C"
  done 
fi
echo "##C++ Extension: $ccext" >> ../config.log
#Check for a socket library: the X11 library depends on it.
#
if [ "`echo /usr/lib/libsocket.*`" != "/usr/lib/libsocket.*" ]
then
  $ecc "Checking socket library ..."$ecs
  echo "##Socket library exists." >> ../config.log
  echo "int main(int c, char **v) { return 0; }" > comptest.$ccext
  errorsc="`$cccom -o comptest comptest.$ccext -L.. $ldopt 2>&1 | grep -c socket`"
  errorsc2="`$cccom -o comptest comptest.$ccext -L.. $ldopt -lsocket 2>&1 | grep -c socket`"
  echo " ok."
  if [ "$errorsc" != "0" -a "$errorsc2" = "0" ]
  then
    ldopt="$ldopt -lsocket"
    echo "Adding option -lsocket"
    echo "##Added -lsocket" >> ../config.log
  fi
fi
# test prototypes
$ecc "Checking prototyping ..."$ecs
rm -f c*
echo "extern int testing(int t1, char *t2, void *t3);
      int testing(int t1, char *t2, void *t3)
      { return !t1 || t2 || t3; }
      int main(int argc, char **argv) { return testing(1,0,0);}" > comptest.c
$ccom -o comptest comptest.c 2> /dev/null > /dev/null
unpr=""
if [ -x comptest ] && ./comptest
then
  echo " ok."
  echo "##Prototypes possible" >> ../config.log
  cd ..
else
  echo " error."
  echo "Your compiler can not handle prototypes."
  $ecc "Checking for unproto ..."$ecs
  cd ..
  unpr=""
  for dir in $path
  do
    if [ -x $dir/unproto ]
    then
      unpr="$dir/unproto"
      break
    fi
  done
  if [ "$unpr" = "" ]
  then
    cd unproto5
    echo " not found."
    $ecc "Building unproto ..."$ecs
    echo "##Prototypes not possible" >> ../config.log
# The HP compiler is not able to compile unproto and needs the -Aa option
# (according to William Feehery)
    if [ "`uname -s`" = "HP-UX" ]
    then
      make -k SYSOPT="-Aa" 2> /dev/null > /dev/null
    else
      make -k 2> /dev/null > /dev/null
    fi
    if [ -x unproto ]
    then
      echo " ok."
      mv unproto ..
      unpr="./unproto"
      make clean 2> /dev/null > /dev/null
    else
      echo " failed."
      echo "Sorry, your compiler has problems with prototypes, unproto is"
      echo "not available on your system and unproto is not successfully"
      echo "compiled. Compilation of MathSpad will fail."
    fi
    cd ..
  else
    echo " found ($unpr)."
    echo "##Unproto found: $unpr" >> ../config.log
  fi
fi
rm -rf testcomp
echo "INCLUDE=$includeopt" >> config.log
echo "DEFINES=$defineopt" >> config.log
echo "LDLIBS=$ldopt" >> config.log
echo "UNPROTO=$unpr" >> config.log
if [ -f "Makefile" ]
then
  mv Makefile Makefile.bak
fi
grep -v '^#' config.log > Makefile
if [ "$unpr" != "" ]
then
   cat Makefile.unp | sed 's#\.cc#\.'$ccext'#g' >> Makefile
else
   cat Makefile.pro | sed 's#\.cc#\.'$ccext'#g' >> Makefile
fi
#<make>
#cat mathpad.man | sed -e 's#MATHPADLIBDIRECTORY#'$mplibdir'#g' > mathpad.1
echo
echo "The makefile is ready. I hope it works."
echo
exit

