AC_ARG_WITH(mpi,
	[ --with-mpi[=DIR]           use LAM/MPI library in DIR],
	if test "$withval" = yes; then
        dnl handle UBUNTU systems
		yap_cv_mpi=yes
	elif test "$withval" = no; then
		yap_cv_mpi=no
	else
		yap_cv_mpi=$with_mpi
		LDFLAGS="$LDFLAGS -L${yap_cv_mpi}/lib"
		CPPFLAGS="$CPPFLAGS -I${yap_cv_mpi}/include"
	fi,
	[yap_cv_mpi=no])


AC_ARG_WITH(mpe,
	[ --with-mpe[=DIR]           use MPE library in DIR],
	if test "$withval" = yes; then
		yap_cv_mpe=yes
	elif test "$withval" = no; then
		yap_cv_mpe=no
	else
		yap_cv_mpe=$with_mpe
		LDFLAGS="$LDFLAGS -L${yap_cv_mpe}/lib"
		CPPFLAGS="$CPPFLAGS -I${yap_cv_mpe}/include"
	fi,
	[yap_cv_mpe=no])

if test "$CC" = icc
then
  MPI_CC="$CC"
  yap_cv_mpi=no
fi

dnl LAM/MPI interface

if test "$yap_cv_mpi" != "no" -a "$INSTALL_DLLS" != "no"; then
    if test "$yap_cv_mpi" = "yes"; then
      AC_PATH_PROG(MPI_CC,mpicc,"$CC",$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin)
    else
      AC_PATH_PROG(MPI_CC,mpicc,"$CC",$yap_cv_mpi/bin:$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin)
    fi
    MPILDF=`"$MPI_CC" --showme:link`
    MPICF=`"$MPI_CC" --showme:compile`
    MPILIBDIRS=`"$MPI_CC" --showme:libdirs`
    LIBS+=" $MPILDF"
    PKG_MPI="library/lammpi library/mpi"
    OLD_CC=${CC}
    CC=${MPI_CC}
    AC_CHECK_HEADERS(mpi.h)
     case "$target_os" in
     	  *linux*)
	      for dir in "$MPILIBDIRS"; do LIBS+=" -Wl,-rpath=$dir"; done
    ;;
     esac
    CC=${OLD_CC}
    if test "$yap_cv_mpe" != "no"
    then
     OLD_CC=${CC}
     CC=${MPI_CC}
     AC_CHECK_LIB(mpe,MPE_Init_log,
		[AC_DEFINE(HAVE_LIBMPE, 1, [MPI Debugging on])],
		[AC_DEFINE(HAVE_LIBMPE, 0, [MPI Debugging off])])
     if test "$ac_cv_lib_mpe_MPE_Init_log" = yes
     then
	LIBS="-lmpe"
	MPI_OBJS="$MPI_OBJS mpe.o"
     fi
     AC_CHECK_HEADERS(mpe.h)
     CC=${OLD_CC}
   fi
else
  PKG_MPI=""
  MPI_CC=${CC}
fi



AC_SUBST(PKG_MPI)
AC_SUBST(YAPMPILIB)
AC_SUBST(MPILDF)
AC_SUBST(MPICF)

mkdir -p  library/lammpi