#
#   This file is part of the McStas neutron ray-trace simulation package
#   Copyright (C) 1997-2006, All rights reserved
#   Risoe National Laborartory, Roskilde, Denmark
#   Institut Laue Langevin, Grenoble, France
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
dnl Process this file with autoconf to produce a configure script.

AC_INIT(mcstas.h)

AC_PROG_CC
AC_PROG_INSTALL
CF_ANSI_CC_CHECK
MC_ANSI_MATH_PROTO
AC_CHECK_FUNCS(strcasecmp fdopen)
AC_PATH_PROGS(PERL,   [perl5 perl /usr/local/bin/perl], no)
AC_PATH_PROGS(SCILAB, [scilab runscilab /usr/local/bin/scilab /usr/lib/scilab/bin/scilab /lib/scilab/bin/scilab scilex], no)
AC_PATH_PROGS(MATLAB, [matlab /usr/local/bin/matlab], no)
AC_PATH_PROGS(PGPLOT, [pgxwin_server /usr/local/bin/pgxwin_server /usr/local/pgplot/pgxwin_server], no)
AC_PATH_PROGS(TCLTK,  [wish /usr/local/bin/wish tclsh], no)
AC_PATH_PROGS(SSH,    [ssh /usr/local/bin/ssh], no)
AC_PATH_PROGS(MPIRUN, [mpirun /usr/local/bin/mpirun], no)
AC_PATH_PROGS(MPICC,  [mpicc /usr/local/bin/mpicc], no)
AC_PATH_PROGS(BROWSER,[konqueror firefox mozilla-firefox mozilla netscape epiphany galeon start msie /Applications/Safari.app/Contents/MacOS/Safari /Applications/Firefox.app/Contents/MacOS/firefox], no)
AC_PATH_PROGS(EDITOR, [nedit kate gedit xemacs xedit vim notepad wordpad], no)
AC_PATH_PROGS(VRMLVIEW, [freewrl gtklookat qtlookat xmlookat maclookat fltklookat lookat])
AC_PATH_PROGS(WGET, [wget], no)
# Important here: gnome-terminal is broken:
#  Any commandline arguments after -e must contain escaped spaces.
# BUT: If escaped in the perl code, use of xterm/konsole is broken....
# Hence we allow only gnome-terminal.wrapper which is debian only
# :(
AC_PATH_PROGS(TERMINAL,   [xterm konsole gnome-terminal.wrapper], no)
AC_OUTPUT(Makefile lib/tools/perl/mcstas_config.perl)

if test "$PERL" = "no" ; then
  echo "WARNING: No Perl executable could be found !"
  echo "You will have to use"
  echo "   mcstas <file>.instr"
  echo "   $CC -o <file>.out <file>.instr -lm"
  echo "   <file>.out [simulation parameters]"
fi
if test "$TCLTK" = "no" ; then
  echo "WARNING: No Tcl/Tk installation could be found !"
  echo "You will not be able to use McGUI interface"
fi
if test "$BROWSER" = "no" ; then
  echo "WARNING: No HTML browser could be found !"
fi
if test "$SCILAB" = "no" ; then
  if test "$MATLAB" = "no" ; then
    if test "$PGPLOT" = "no" ; then
      if test "$VRMLVIEW" = "no" ; then
        echo "WARNING: No Plotter (Matlab, Scilab, PGPLOT, VRML) could be found !"
      fi
    fi
  fi
fi
echo ""
echo "To setup the plotting environment, execute either"
echo "  make config (automaticly selects plotter, "
echo "       prefers Scilab before Matlab before PGPLOT before VRML)"
echo "  make scilab (selects scilab)"
echo "  make matlab (selects matlab)"
echo "  make pgplot (selects pgplot)"
echo "  make vrml   (selects vrml)"
echo ""
echo "After plotter config, build and install McStas by executing"
echo "make; make install"
echo ""
echo "WARNING: McStas 1.9 requires Scilab <= 3.0"
echo ""
echo "If you experience crashes of mcgui when running in the Gnome"
echo "environment, please come back here and do a"
echo ""
echo "  make tk"
echo ""
echo " - will install our patched version of perl-tk from the net"