#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/strtoull             */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Mon Jul 10 13:57:21 2023 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Detect if current C complier support long long abs.              */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
tmp=/tmp
longlong=
strtoull=strtoull

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

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

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

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

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

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

#*---------------------------------------------------------------------*/
#*    Default setting                                                  */
#*---------------------------------------------------------------------*/
if [ "$longlong " = " " ]; then
  longlong="long long"
fi

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

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

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

int main( int argc, char *argv[] ) {
EOF
echo "   return (strtoull( \"123\", 0, 10 ) == 123);" >> $file.c
echo "}" >> $file.c

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval "$BUILDSH $compile"; then
   \rm -f $file.*
   rm -f $aout
   rm -rf $aout*
   echo "$strtoull"
else
   \rm -f $file.*
   echo ""
fi
