dnl Copyright (C) 2005-2006 EDF
dnl
dnl This file is part of the Code_Saturne Preprocessor.  For license
dnl information, see the LICENSE file in the top level directory of the
dnl Code_Saturne Preprocessor source distribution.

# ECS_AC_TEST_METIS
#-----------------
# modifies or sets have_metis, METIS_CPPFLAGS, METIS_LDFLAGS, and METIS_LIBS
# depending on libraries found

AC_DEFUN([ECS_AC_TEST_METIS], [

have_metis=no

AC_ARG_ENABLE(METIS,
  [  --disable-metis          Do not use METIS when available],
  [
    case "${enableval}" in
      yes) metis=true ;;
      no)  metis=false ;;
      *)   AC_MSG_ERROR([bad value ${enableval} for --enable-metis]) ;;
    esac
  ],
  [ metis=true ]
)

AC_ARG_WITH(metis-prefix,
  [  --with-metis-prefix=DIR   METIS format support],[
])
AC_ARG_WITH(metis-exec-prefix,
  [  --with-metis-exec-prefix=DIR   METIS exec prefix]
)
AC_ARG_WITH(metis-includedir,
  [  --with-metis-includedir=DIR   METIS headers directory]
)
AC_ARG_WITH(metis-libdir,
  [  --with-metis-libdir=DIR   METIS library directory]
)

if test "x$metis" = "xtrue" ; then

  saved_CPPFLAGS="$CPPFLAGS"
  saved_LDFLAGS="$LDFLAGS"
  saved_LIBS="$LIBS"

  if test "x$with_metis_prefix" != "x" ; then
    METIS_CPPFLAGS="-I$with_metis_prefix/include"
  fi
  if test "x$with_metis_includedir" != "x" ; then
    METIS_CPPFLAGS="-I$with_metis_includedir"
  fi
  if test "x$with_metis_exec_prefix" != "x" ; then
    METIS_LDFLAGS="-L$with_metis_exec_prefix/lib"
  elif test "x$with_metis_prefix" != "x" ; then
    METIS_LDFLAGS="-L$with_metis_prefix/lib"
  fi
  if test "x$with_metis_libdir" != "x" ; then
    METIS_LDFLAGS="-L$with_metis_libdir"
  fi

  METIS_LIBS="-lmetis -lm"
  CPPFLAGS="${CPPFLAGS} ${METIS_CPPFLAGS}"
  LDFLAGS="${LDFLAGS} ${METIS_LDFLAGS}"
  LIBS="${LIBS} ${METIS_LIBS}"

  AC_CHECK_LIB(metis, METIS_PartGraphKway, 
               [ AC_DEFINE([HAVE_METIS], 1, [use METIS ])
                 have_metis=yes
               ], 
               [ AC_MSG_WARN([do not use METIS])
               ],
               )

  if test "x$have_metis" = "xno"; then
    METIS_CPPFLAGS=""
    METIS_LDFLAGS=""
    METIS_LIBS=""
  fi

fi

AM_CONDITIONAL(HAVE_METIS, test x$have_metis = xyes)

CPPFLAGS="$saved_CPPFLAGS"
LDFLAGS="$saved_LDFLAGS"
LIBS="$saved_LIBS"

unset saved_CPPFLAGS
unset saved_LDFLAGS
unset saved_LIBS

AC_SUBST(METIS_CPPFLAGS)
AC_SUBST(METIS_LDFLAGS)
AC_SUBST(METIS_LIBS)

])dnl



syntax highlighted by Code2HTML, v. 0.9.1