_gmp_list="gmp GMPLIBS GMPINCLUDE"
gmp=
if test -n "$with_gmp"; then
  with_gmp_lib="$with_gmp_lib $with_gmp/lib"
  with_gmp_include="$with_gmp_include $with_gmp/include"
fi
if test "$kernlvl1" = "gmp"; then
  gmp_add="$TOP/gmp-$osname-$arch $TOP/gmp"
  pth="$with_gmp_lib $gmp_add $libpth"
  lib=gmp; . ./locatelib
fi

if test -n "$gmp"; then
  pth="$with_gmp_include $basic_include_path"
  x=`./locate 'gmp.h' '' $pth`
  case $x in
   ?:/*|/*) gmp_include=`dirname $x`
     echo ..."Found gmp header in $gmp_include"
     ;;
    *) echo ..."But no header file has been found"
       gmp=;;
  esac
fi

if test -n "$gmp"; then
  GMPINCLUDE="-I$gmp_include"
  GMPLIBS="-L$gmp -lgmp"

  exe=$osname-$arch-rlv$$
  $CC $CFLAGS $extraflag $GMPINCLUDE -o $exe gmp_version.c $GMPLIBS 2> /dev/null
  if test -r $exe; then
    gmp_version=`env LD_LIBRARY_PATH="$LD_LIBRARY_PATH$dir_sep$gmp" $RUNTEST $exe`;
  fi
  if test "$gmp_version" = "unsupported"; then
    echo "### Your GMP library ABI is unsupported."
    gmp=
  fi
  if test -z "$gmp_version"; then
    $CC $CFLAGS $extraflag $GMPINCLUDE -o $exe ansi.c $GMPLIBS 2> /dev/null
    if test -r $exe; then
      echo "### Your version of GMP is too old for PARI. Please upgrade"
    else
      echo "### Your GMP library is incompatible with the compiler settings."
    fi
    gmp=
  fi
  rm -f $exe $exe$exe_suff
fi

if test -z "$gmp"; then
  echo "### Building without GNU MP support"
else
  if test "$fastread" = yes; then
    echo "Using GNU MP, version $gmp_version"
  else
    cat << EOM
==========================================================================
GNU MP library can be used as an alternate multiprecision kernel, which
is faster than PARI's native one as soon as integers larger than 10^100
are considered. Unfortunately, with GNU MP, libpari is binary incompatible
with the native one. Despite this, you should only answer 'no' to the
following question if you plan to use libpari (not only the gp shell)
and have stringent backward compatibility requirements.
EOM
    echo $n "Do you want to use GNU MP library instead of the native kernel? $c"
    if test "$with_gmp" = yes; then dflt=y; else dflt=n; fi
    rep='y n'; . ./myread
    case $ans in
      n) gmp=;;
    esac
  fi
fi

if test -n "$gmp"; then
  kernlvl1=gmp
else
  kernlvl1=none
  GMPINCLUDE=
  GMPLIBS=
fi
. get_pretty
