This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
e96e32c6be5f9a97fb45bb2da5a4afef63b1dbd2
[metaconfig.git] / U / compline / i_time.U
1 ?RCS: $Id: i_time.U,v 3.0 1993/08/18 12:08:45 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?RCS: $Log: i_time.U,v $
12 ?RCS: Revision 3.0  1993/08/18  12:08:45  ram
13 ?RCS: Baseline for dist 3.0 netwide release.
14 ?RCS:
15 ?X:
16 ?X: This unit finds which "time" include to use. If 'timezone' is used by the
17 ?X: program, we also try to find which header should be included. Eventually,
18 ?X: we look for <sys/select.h> if I_SYSSELECT is used, to get struct timeval.
19 ?X:
20 ?MAKE:i_time i_systime i_systimek timeincl d_tm_tm_zone d_tm_tm_gmtoff: \
21         Compile cat \
22         contains rm_try echo n c +i_sysselct Findhdr Hasfield i_stdlib
23 ?MAKE:  -pick add $@ %<
24 ?S:i_time:
25 ?S:     This variable conditionally defines I_TIME, which indicates
26 ?S:     to the C program that it should include <time.h>.
27 ?S:.
28 ?S:i_systime:
29 ?S:     This variable conditionally defines I_SYS_TIME, which indicates
30 ?S:     to the C program that it should include <sys/time.h>.
31 ?S:.
32 ?S:i_systimek:
33 ?S:     This variable conditionally defines I_SYS_TIME_KERNEL, which
34 ?S:     indicates to the C program that it should include <sys/time.h>
35 ?S:     with KERNEL defined.
36 ?S:.
37 ?S:timeincl:
38 ?S:     This variable holds the full path of the included time header(s).
39 ?S:.
40 ?S:d_tm_tm_zone:
41 ?S:     This variable conditionally defines HAS_TM_TM_ZONE, which indicates
42 ?S:     indicates to the C program that the struct tm has the tm_zone field.
43 ?S:.
44 ?S:d_tm_tm_gmtoff:
45 ?S:     This variable conditionally defines HAS_TM_TM_GMTOFF, which indicates
46 ?S:     indicates to the C program that the struct tm has the tm_gmtoff field.
47 ?S:.
48 ?C:I_TIME (USE_TIME_H):
49 ?C:     This symbol, if defined, indicates to the C program that it should
50 ?C:     include <time.h>.
51 ?C:.
52 ?C:I_SYS_TIME (I_SYSTIME USE_SYS_TIME_H NO_TIME_WITH_SYS_TIME):
53 ?C:     This symbol, if defined, indicates to the C program that it should
54 ?C:     include <sys/time.h>.
55 ?C:.
56 ?C:I_SYS_TIME_KERNEL (I_SYSTIMEKERNEL):
57 ?C:     This symbol, if defined, indicates to the C program that it should
58 ?C:     include <sys/time.h> with KERNEL defined.
59 ?C:.
60 ?C:HAS_TM_TM_ZONE:
61 ?C:     This symbol, if defined, indicates to the C program that
62 ?C:     the struct tm has a tm_zone field.
63 ?C:.
64 ?C:HAS_TM_TM_GMTOFF:
65 ?C:     This symbol, if defined, indicates to the C program that
66 ?C:     the struct tm has a tm_gmtoff field.
67 ?C:.
68 ?H:#$i_time I_TIME              /**/
69 ?H:#$i_systime I_SYS_TIME               /**/
70 ?H:#$i_systimek I_SYS_TIME_KERNEL               /**/
71 ?H:#$d_tm_tm_zone HAS_TM_TM_ZONE                /**/
72 ?H:#$d_tm_tm_gmtoff HAS_TM_TM_GMTOFF            /**/
73 ?H:.
74 ?W::timezone
75 ?T:xselect flags sysselect s_timeval s_timezone
76 ?LINT:change i_sysselct
77 ?LINT:set d_tm_tm_zone
78 ?LINT:set d_tm_tm_gmtoff
79 : see if we should include time.h, sys/time.h, or both
80 echo " "
81 if test "X$timeincl" = X; then
82         echo "Testing to see if we should include <time.h>, <sys/time.h> or both." >&4
83         $echo $n "I'm now running the test program...$c"
84         $cat >try.c <<EOCP
85 #include <sys/types.h>
86 #ifdef I_TIME
87 #include <time.h>
88 #endif
89 #ifdef I_SYSTIME
90 #ifdef SYSTIMEKERNEL
91 #define KERNEL
92 #endif
93 #include <sys/time.h>
94 #endif
95 #ifdef I_SYSSELECT
96 #include <sys/select.h>
97 #endif
98 #$i_stdlib I_STDLIB
99 #ifdef I_STDLIB
100 #include <stdlib.h>
101 #endif
102 int main()
103 {
104         struct tm foo;
105 #ifdef S_TIMEVAL
106         struct timeval bar;
107 #endif
108 #ifdef S_TIMEZONE
109         struct timezone tzp;
110 #endif
111         if (foo.tm_sec == foo.tm_sec)
112                 exit(0);
113 #ifdef S_TIMEVAL
114         if (bar.tv_sec == bar.tv_sec)
115                 exit(0);
116 #endif
117         exit(1);
118 }
119 EOCP
120         flags=''
121 @if I_SYSSELECT
122         if $contains 'timeval.*{' `./findhdr sys/select.h` >/dev/null 2>&1; then
123                 xselect='-DI_SYSSELECT'
124         else
125                 xselect=''
126         fi
127 @end
128 @if timezone
129         for s_timezone in '-DS_TIMEZONE' ''; do
130 @else
131         s_timezone=''
132 @end
133 ?X: Every package is given a try with 'struct timeval'
134 @if I_SYSSELECT
135         for sysselect in $xselect ''; do
136 @else
137         sysselect=''
138 @end
139         for s_timeval in '-DS_TIMEVAL' ''; do
140         for i_systimek in '' '-DSYSTIMEKERNEL'; do
141         for i_time in '' '-DI_TIME'; do
142         for i_systime in '-DI_SYSTIME' ''; do
143                 case "$flags" in
144                 '') $echo $n ".$c"
145                         set try $i_time $i_systime $i_systimek $sysselect $s_timeval $s_timezone
146                         if eval $compile; then
147                                 set X $i_time $i_systime $i_systimek $sysselect $s_timeval
148                                 shift
149                                 flags="$*"
150                                 echo " "
151                                 $echo $n "Succeeded with $flags$c"
152                         fi
153                         ;;
154                 esac
155         done
156         done
157         done
158         done
159 @if I_SYSSELECT
160         done
161 @end
162 @if timezone
163         done
164 @end
165         timeincl=''
166         echo " "
167         case "$flags" in
168         *SYSTIMEKERNEL*) i_systimek="$define"
169                 timeincl=`./findhdr sys/time.h`
170                 echo "We'll include <sys/time.h> with KERNEL defined." >&4;;
171         *) i_systimek="$undef";;
172         esac
173         case "$flags" in
174         *I_TIME*) i_time="$define"
175                 timeincl=`./findhdr time.h`" $timeincl"
176                 echo "We'll include <time.h>." >&4;;
177         *) i_time="$undef";;
178         esac
179         case "$flags" in
180         *I_SYSTIME*) i_systime="$define"
181                 timeincl=`./findhdr sys/time.h`" $timeincl"
182                 echo "We'll include <sys/time.h>." >&4;;
183         *) i_systime="$undef";;
184         esac
185 @if I_SYSSELECT
186         case "$flags" in
187         *I_SYSSELECT*) i_sysselct="$define"
188                 timeincl=`./findhdr sys/select.h`" $timeincl"
189                 echo "We'll also include <sys/select.h> to get struct timeval." >&4;;
190         *)      case "$i_sysselct" in
191                 '') i_sysselct="$undef";;
192                 esac
193         esac
194 @end
195         $rm_try
196 fi
197 : see if struct tm knows about tm_zone
198 case "$i_systime$i_time" in
199 *$define*)
200         echo " "
201         echo "Checking to see if your struct tm has tm_zone field..." >&4
202         set d_tm_tm_zone tm tm_zone $i_systime sys/time.h $i_time time.h
203         eval $hasfield
204         ;;
205 *)      val="$undef"
206         set d_tm_tm_zone
207         eval $setvar
208         ;;
209 esac
210 case "$d_tm_tm_zone" in
211 "$define")      echo "Yes, it does."   ;;
212 *)              echo "No, it doesn't." ;;
213 esac
214 : see if struct tm knows about tm_gmtoff
215 case "$i_systime$i_time" in
216 *$define*)
217         echo " "
218         echo "Checking to see if your struct tm has tm_gmtoff field..." >&4
219         set d_tm_tm_gmtoff tm tm_gmtoff $i_systime sys/time.h $i_time time.h
220         eval $hasfield
221         ;;
222 *)      val="$undef"
223         set d_tm_tm_gmtoff
224         eval $setvar
225         ;;
226 esac
227 case "$d_tm_tm_gmtoff" in
228 "$define")      echo "Yes, it does."   ;;
229 *)              echo "No, it doesn't." ;;
230 esac
231