dnl Copyright (C) 2005-2006 EDF
dnl
dnl This file is part of the FVM software package.  For license
dnl information, see the COPYING file in the top level directory of the
dnl FVM source distribution.

# FVM_AC_TEST_MED
#----------------
# modifies or sets have_med, MED_CPPFLAGS, MED_LDFLAGS, and MED_LIBS
# depending on libraries found

AC_DEFUN([FVM_AC_TEST_MED], [

AC_REQUIRE([FVM_AC_CONFIG_PUBL_INIT])dnl

have_med=no

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

AC_ARG_WITH(med-prefix,
  [  --with-med-prefix=DIR   MED format support],[
])

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

  if test "x$have_hdf" = "xno" ; then
    AC_MSG_ERROR([no hdf library found])
  fi

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

  MED_RPATH=
  MED_LIBS="-lmedC"

# We have to define the MED_ARCH macro for MED versions prior to 2.3.1.
# If we are unable to find a good value, we will have to give the
# correct value through CFLAGS_ADD or (better) use a more recent
# version of the MED library.

# 64 or 32 bit architecture ?
  ptrs_are_64bit=no
  ints_are_64bit=no

  AC_CHECK_SIZEOF(void *)
  if test "$ac_cv_sizeof_void_p" = "8" ; then
    ptrs_are_64bit=yes
  fi

  AC_CHECK_SIZEOF(int)
  if test "$ac_cv_sizeof_int" = "8" ; then
    ints_are_64bit=yes
  fi
  
  case $host_os in
    linux*)
      if test "x$ptrs_are_64bit" != "xyes" ; then
        MED_ARCH_NAME=PCLINUX
      else
        if test "x$ints_are_64bit" != "xyes" ; then
          MED_ARCH_NAME=PCLINUX64_32
	else
          MED_ARCH_NAME=PCLINUX64
	fi
      fi;
      MED_LIBS="-lmedC -lpthread";;
    osf*)
      if test "x$ints_are_64bit" != "xyes" ; then
        MED_ARCH_NAME=OSF1_32
      else
        MED_ARCH_NAME=OSF1
      fi;;
    hpux*)
      if test "x$ints_are_64bit" != "xyes" ; then
        MED_ARCH_NAME=HP9000
      else
        AC_MSG_WARN([no MED_ARCH value for HP-UX with 64-bit ints])
      fi;;
    solaris2.*)
      if test "x$ints_are_64bit" != "xyes" ; then
        MED_ARCH_NAME=SUN4SOL2
      else
        AC_MSG_WARN([no MED_ARCH value for Solaris with 64-bit ints])
      fi;;
    irix5.*|irix6.*)
      if test "x$ints_are_64bit" != "xyes" ; then
        MED_ARCH_NAME=IRIX64_32
      else
        MED_ARCH_NAME=IRIX64
      fi;;
    *) AC_MSG_WARN([no MED_ARCH value for this OS]) ;;
  esac

  if test "x$with_med_prefix" != "x" ; then
    MED_CPPFLAGS="-I$with_med_prefix/include -D$MED_ARCH_NAME"
    MED_LDFLAGS="-L$with_med_prefix/lib"
    MED_RPATH="-Wl,-rpath -Wl,${MED_LDFLAGS}"
  fi

  CPPFLAGS="${CPPFLAGS} ${MED_CPPFLAGS} ${HDF5_CPPFLAGS}"
  LDFLAGS="${LDFLAGS} ${MED_LDFLAGS} ${HDF5_LDFLAGS}"
  LIBS="${LIBS} ${MED_LIBS} ${HDF5_LIBS}"

  AC_CHECK_LIB(medC, MEDouvrir, 
               [ AC_DEFINE([HAVE_MED], 1, [MED file support])
                 have_med=yes
               ], 
               [ AC_MSG_WARN([no MED file support])
               ],
               )

  if test "x$have_med" = "xno"; then
    MED_CPPFLAGS=""
    MED_LDFLAGS=""
    MED_LIBS=""
  fi

fi

AM_CONDITIONAL(HAVE_MED, test x$have_med = xyes)

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

unset saved_CPPFLAGS
unset saved_LDFLAGS
unset saved_LIBS

AC_SUBST(MED_CPPFLAGS)
AC_SUBST(MED_LDFLAGS)
AC_SUBST(MED_LIBS)

])dnl



syntax highlighted by Code2HTML, v. 0.9.1