#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/timeval              */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Mon Jul 10 13:53:17 2023 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check if timeval exists                                          */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cflags=

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

    --cflags=*|-cflags=*)
      cflags="`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 >/dev/null"

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

#*---------------------------------------------------------------------*/
#*    Test1                                                            */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <time.h>
#include <sys/time.h>
#include <ctype.h>

int main( int argc, char *argv[] ) {
   struct timeval tv;
   gettimeofday( &tv, 0 );
   return 0;
}
EOF

if eval "$BUILDSH $compile"; then
   echo "1"
else
   echo "0"
fi

\rm -f $file.*
\rm -f $aout
\rm -rf $aout*

exit 0
