#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/timegm               */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Tue Oct 20 11:24:30 2020 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Check if timegm 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 <ctype.h>
#include <sys/time.h>

int main( int argc, char *argv[] ) {
   time_t sec;
   struct tm tm = { tm_year: 2000 };

   sec = timegm( &tm );

   return sec <= 0;
}
EOF

if eval "$BUILDSH $compile"; then
   \rm -f $file.*
   if eval "$HOSTSH $aout" > /dev/null; then
      rm -f $aout
      echo "1";
      exit 0;
   fi
fi

#*---------------------------------------------------------------------*/
#*    default                                                          */
#*---------------------------------------------------------------------*/
\rm -f $file.*

echo "0"
exit 0;
