?RCS: $Id: i_time.U,v 3.0 1993/08/18 12:08:45 ram Exp $
?RCS:
?RCS: Copyright (c) 1991-1993, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 3.0.
?RCS:
?RCS: $Log: i_time.U,v $
?RCS: Revision 3.0  1993/08/18  12:08:45  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?X:
?X: This unit finds which "time" include to use. If 'timezone' is used by the
?X: program, we also try to find which header should be included. Eventually,
?X: we look for <sys/select.h> if I_SYSSELECT is used, to get struct timeval.
?X:
?MAKE:i_time i_systime i_systimek timeincl d_tm_tm_zone d_tm_tm_gmtoff: \
	Compile cat \
	contains rm_try echo n c +i_sysselct Findhdr Hasfield i_stdlib
?MAKE:	-pick add $@ %<
?S:i_time:
?S:	This variable unconditionally defines I_TIME, which indicates
?S:	to the C program that it should include <time.h>.
?S:.
?S:i_systime:
?S:	This variable conditionally defines I_SYS_TIME, which indicates
?S:	to the C program that it should include <sys/time.h>.
?S:.
?S:i_systimek:
?S:	This variable conditionally defines I_SYS_TIME_KERNEL, which
?S:	indicates to the C program that it should include <sys/time.h>
?S:	with KERNEL defined.
?S:.
?S:timeincl:
?S:	This variable holds the full path of the included time header(s).
?S:.
?S:d_tm_tm_zone:
?S:	This variable conditionally defines HAS_TM_TM_ZONE, which indicates
?S:	to the C program that the struct tm has the tm_zone field.
?S:.
?S:d_tm_tm_gmtoff:
?S:	This variable conditionally defines HAS_TM_TM_GMTOFF, which indicates
?S:	to the C program that the struct tm has the tm_gmtoff field.
?S:.
?C:I_TIME (USE_TIME_H):
?C:	This symbol is always defined, and indicates to the C program that
?C:	it should include <time.h>.
?C:.
?C:I_SYS_TIME (I_SYSTIME USE_SYS_TIME_H NO_TIME_WITH_SYS_TIME):
?C:	This symbol, if defined, indicates to the C program that it should
?C:	include <sys/time.h>.
?C:.
?C:I_SYS_TIME_KERNEL (I_SYSTIMEKERNEL):
?C:	This symbol, if defined, indicates to the C program that it should
?C:	include <sys/time.h> with KERNEL defined.
?C:.
?C:HAS_TM_TM_ZONE:
?C:	This symbol, if defined, indicates to the C program that
?C:	the struct tm has a tm_zone field.
?C:.
?C:HAS_TM_TM_GMTOFF:
?C:	This symbol, if defined, indicates to the C program that
?C:	the struct tm has a tm_gmtoff field.
?C:.
?H:#$i_time I_TIME		/**/
?H:#$i_systime I_SYS_TIME		/**/
?H:#$i_systimek I_SYS_TIME_KERNEL		/**/
?H:#$d_tm_tm_zone HAS_TM_TM_ZONE		/**/
?H:#$d_tm_tm_gmtoff HAS_TM_TM_GMTOFF		/**/
?H:.
?W::timezone
?T:xselect flags sysselect s_timeval s_timezone
?LINT:change i_sysselct
?LINT:set d_tm_tm_zone
?LINT:set d_tm_tm_gmtoff
: see if we should include sys/time.h
echo " "
i_time='define'
if test "X$timeincl" = X; then
	echo "Testing to see if we should include <sys/time.h>." >&4
	$echo $n "I'm now running the test program...$c"
	$cat >try.c <<EOCP
#include <sys/types.h>
#include <time.h>
#ifdef I_SYSTIME
#ifdef SYSTIMEKERNEL
#define KERNEL
#endif
#include <sys/time.h>
#endif
#ifdef I_SYSSELECT
#include <sys/select.h>
#endif
#$i_stdlib I_STDLIB
#ifdef I_STDLIB
#include <stdlib.h>
#endif
int main()
{
	struct tm foo;
#ifdef S_TIMEVAL
	struct timeval bar;
#endif
#ifdef S_TIMEZONE
	struct timezone tzp;
#endif
	if (foo.tm_sec == foo.tm_sec)
		exit(0);
#ifdef S_TIMEVAL
	if (bar.tv_sec == bar.tv_sec)
		exit(0);
#endif
	exit(1);
}
EOCP
	flags=''
@if I_SYSSELECT
	if $contains 'timeval.*{' `./findhdr sys/select.h` >/dev/null 2>&1; then
		xselect='-DI_SYSSELECT'
	else
		xselect=''
	fi
@end
@if timezone
	for s_timezone in '-DS_TIMEZONE' ''; do
@else
	s_timezone=''
@end
?X: Every package is given a try with 'struct timeval'
@if I_SYSSELECT
	for sysselect in $xselect ''; do
@else
	sysselect=''
@end
	for s_timeval in '-DS_TIMEVAL' ''; do
	for i_systimek in '' '-DSYSTIMEKERNEL'; do
	for i_systime in '-DI_SYSTIME' ''; do
		case "$flags" in
		'') $echo $n ".$c"
			set try $i_systime $i_systimek $sysselect $s_timeval $s_timezone
			if eval $compile; then
				set X $i_systime $i_systimek $sysselect $s_timeval
				shift
				flags="$*"
				echo " "
				$echo $n "Succeeded with $flags$c"
			fi
			;;
		esac
	done
	done
	done
@if I_SYSSELECT
	done
@end
@if timezone
	done
@end
	timeincl=''
	echo " "
	case "$flags" in
	*SYSTIMEKERNEL*) i_systimek="$define"
		timeincl=`./findhdr sys/time.h`
		echo "We'll include <sys/time.h> with KERNEL defined." >&4;;
	*) i_systimek="$undef";;
	esac
	case "$flags" in
	*I_SYSTIME*) i_systime="$define"
		timeincl=`./findhdr sys/time.h`" $timeincl"
		echo "We'll include <sys/time.h>." >&4;;
	*) i_systime="$undef";;
	esac
@if I_SYSSELECT
	case "$flags" in
	*I_SYSSELECT*) i_sysselct="$define"
		timeincl=`./findhdr sys/select.h`" $timeincl"
		echo "We'll also include <sys/select.h> to get struct timeval." >&4;;
	*)	case "$i_sysselct" in
		'') i_sysselct="$undef";;
		esac
	esac
@end
	$rm_try
fi
: see if struct tm knows about tm_zone
case "$i_systime$i_time" in
*$define*)
        echo " "
        echo "Checking to see if your struct tm has tm_zone field..." >&4
        set d_tm_tm_zone tm tm_zone $i_systime sys/time.h $i_time time.h
        eval $hasfield
        ;;
*)      val="$undef"
        set d_tm_tm_zone
        eval $setvar
        ;;
esac
case "$d_tm_tm_zone" in
"$define")      echo "Yes, it does."   ;;
*)              echo "No, it doesn't." ;;
esac
: see if struct tm knows about tm_gmtoff
case "$i_systime$i_time" in
*$define*)
        echo " "
        echo "Checking to see if your struct tm has tm_gmtoff field..." >&4
        set d_tm_tm_gmtoff tm tm_gmtoff $i_systime sys/time.h $i_time time.h
        eval $hasfield
        ;;
*)      val="$undef"
        set d_tm_tm_gmtoff
        eval $setvar
        ;;
esac
case "$d_tm_tm_gmtoff" in
"$define")      echo "Yes, it does."   ;;
*)              echo "No, it doesn't." ;;
esac

