#
#   This file is part of the McStas neutron ray-trace simulation package
#   Copyright (C) 1997-2008, 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; version 2 of the License.
#
#   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(McXtrace, 1.1, mcxtrace-support@mcxtrace.org)
AC_REVISION($Revision: 1.1$)
AC_COPYRIGHT([Copyright (C) Copyright, All rights reserved
Risoe National Laborartory, Roskilde, Denmark
Institut Laue Langevin, Grenoble, France
This software is covered by the GNU LESSER GENERAL PUBLIC LICENSE
see file COPYING for further information])

AC_PREFIX_DEFAULT(/usr/local)
test "x$prefix" = xNONE && prefix=$ac_default_prefix

AC_ARG_WITH([cc], AC_HELP_STRING([--with-cc=c compiler], [Specify name of C compiler]),
        [with_cc=$withval], [with_cc=yes])
if test x"$with_cc" != x"no" ; then
        if test x"$with_cc" != x"yes" ; then CC="$with_cc"; fi
        AC_PROG_CC
else
        AC_MSG_ERROR([You need a C compiler to compile this package])
fi
CF_ANSI_CC_CHECK

AC_PATH_PROGS(PERL,   [perl perl5], no, /usr/bin:/usr/local/bin:$PATH)
AC_PATH_PROGS(SCILAB, [scilab runscilab scilex], no, /usr/local/bin:/usr/lib/scilab/bin:/lib/scilab/bin:$PATH)
AC_PATH_PROGS(MATLAB, [matlab], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(GNUPLOT,[gnuplot /usr/local/bin/gnuplot], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(PGPLOT, [pgxwin_server], no, /usr/local/bin:/usr/local/pgplot:$PATH)
AC_PATH_PROGS(TCLTK,  [wish tclsh], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(SSH,    [ssh plink], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(SCP,    [scp pscp], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(MPIRUN, [mpirun], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(MPICC,  [mpicc hcc mpxlc_r mpxlc mpcc cmpicc], no, /usr/local/bin:$PATH)
AC_PATH_PROGS(BROWSER,[gnome-open firefox mozilla-firefox mozilla konqueror epiphany galeon netscape Safari], no,  /Applications/Safari.app/Contents/MacOS:/Applications/Firefox.app/Contents/MacOS:/usr/local/bin:$PATH)
AC_PATH_PROGS(EDITOR, [gedit nedit kate xemacs gnome-open xedit vim notepad wordpad], no)
AC_PATH_PROGS(AT,  [at], no)
AC_PATH_PROGS(HDFVIEW,  [hdfview], no, /usr/local/bin:/usr/local/hdfview:$PATH)
# 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)

# handle PIC options
AC_ARG_WITH([pic],
  [AS_HELP_STRING([--with-pic],
     [enable support for PIC libraries (required to compile PGPLOT on some systems)])],
  [USE_PIC=$withval],
  [USE_PIC=no])
AC_SUBST(USE_PIC)

# check for MPI
if test "$MPICC" != "no"; then
  AC_CHECK_HEADER(mpi.h, , [ echo "WARNING: $MPICC may fail to compile without mpi.h" ] )
fi

# check for NeXus libraries
AC_ARG_WITH([nexus],
  [AS_HELP_STRING([--with-nexus],
     [enable support for NeXus/HDF libraries])])
if test "${with_nexus+set}" = set; then
  AC_SUBST([HAVE_NEXUS], ["-DUSE_NEXUS -lNeXus"])
  AC_DEFINE([HAVE_NEXUS], ["-DUSE_NEXUS -lNeXus"])
else
  AC_SUBST([HAVE_NEXUS], [])
  AC_DEFINE([HAVE_NEXUS], [])
fi

AC_OUTPUT($prefix/lib/mcxtrace/tools/perl/mccode_config.perl)

chmod a+w $prefix/lib/mcxtrace/tools/perl/mccode_config.perl

echo "McXtrace has been reconfigured in $prefix/lib/mcstas/tools/perl/mccode_config.perl"

