#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/gmp                  */
#*    -------------------------------------------------------------    */
#*    Author      :  Jose Romildo                                      */
#*    Creation    :  Sat Nov 11 13:27:23 1995                          */
#*    Last change :  Mon Jul 10 14:00:39 2023 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check for the host gmp library.                                  */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cflags=
gmplib="-lgmp"
type=

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --cflags=*|-cflags=*)
      cflags="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --lib=*|-lib=*)
      gmplib="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --type=*|-type=*)
      type="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$TMP/actest.$USER
aout=$TMP/Xactest$USER

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compile="$CC $cflags $gmplib $file.c -o $aout $gmplib >/dev/null"

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if( test -f $file.c ); then
   rm -f $file.c || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <gmp.h>
#include <stdio.h>

int main() {
   mpz_t n;
   mpz_init_set_str(n, "123456", 0);
   mpz_clear(n);
   printf("%s\n", gmp_version);
   return 0;
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval "$BUILDSH $compile"; then
   eval "$HOSTSH $aout"
   ret_code=$?
   \rm -f $file.*
   rm -f $aout
   rm -rf $aout*
   exit $ret_code
else
   \rm -f $file.*
   echo "no"
fi
exit 0
