#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/gmp                         */
#*    -------------------------------------------------------------    */
#*    Author      :  Jose Romildo                                      */
#*    Creation    :  Sat Nov 11 13:27:23 1995                          */
#*    Last change :  Tue Mar 25 17:19:04 2008 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check for the host gmp library.                                  */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cc=gcc
cflags=
gmplib="-lgmp"
tmp=/tmp
user=bigloo
type=

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

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

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

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

    --tmp=*|-tmp=*)
      tmp="`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 $file.c -o $aout $gmplib >/dev/null 2> /dev/null"
run="$aout 2> /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);
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval $compile; then
   \rm -f $file.*
   result=`$run`
   rm -f $aout
   rm -f $aout*
   echo "$result"
else
   \rm -f $file.*
   echo "no"
   exit 1
fi
