Commit | Line | Data |
---|---|---|
09607c9e TT |
1 | # Configure a more-standard replacement for <time.h>. |
2 | ||
9c9d63b1 | 3 | # Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc. |
09607c9e | 4 | |
9c9d63b1 | 5 | # serial 15 |
09607c9e TT |
6 | |
7 | # This file is free software; the Free Software Foundation | |
8 | # gives unlimited permission to copy and/or distribute it, | |
9 | # with or without modifications, as long as this notice is preserved. | |
10 | ||
11 | # Written by Paul Eggert and Jim Meyering. | |
12 | ||
13 | AC_DEFUN([gl_HEADER_TIME_H], | |
14 | [ | |
15 | dnl Use AC_REQUIRE here, so that the default behavior below is expanded | |
16 | dnl once only, before all statements that occur in other macros. | |
17 | AC_REQUIRE([gl_HEADER_TIME_H_BODY]) | |
18 | ]) | |
19 | ||
20 | AC_DEFUN([gl_HEADER_TIME_H_BODY], | |
21 | [ | |
09607c9e | 22 | AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) |
698be2d8 | 23 | |
09607c9e TT |
24 | gl_NEXT_HEADERS([time.h]) |
25 | AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) | |
698be2d8 CB |
26 | |
27 | AC_REQUIRE([AC_C_RESTRICT]) | |
9c9d63b1 PM |
28 | |
29 | AC_CACHE_CHECK([for TIME_UTC in <time.h>], | |
30 | [gl_cv_time_h_has_TIME_UTC], | |
31 | [AC_COMPILE_IFELSE( | |
32 | [AC_LANG_PROGRAM( | |
33 | [[#include <time.h> | |
34 | ]], | |
35 | [[static int x = TIME_UTC; x++;]])], | |
36 | [gl_cv_time_h_has_TIME_UTC=yes], | |
37 | [gl_cv_time_h_has_TIME_UTC=no])]) | |
38 | if test $gl_cv_time_h_has_TIME_UTC = yes; then | |
39 | TIME_H_DEFINES_TIME_UTC=1 | |
40 | else | |
41 | TIME_H_DEFINES_TIME_UTC=0 | |
42 | fi | |
43 | AC_SUBST([TIME_H_DEFINES_TIME_UTC]) | |
09607c9e TT |
44 | ]) |
45 | ||
46 | dnl Check whether 'struct timespec' is declared | |
4a626d0a | 47 | dnl in time.h, sys/time.h, pthread.h, or unistd.h. |
09607c9e TT |
48 | |
49 | AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], | |
50 | [ | |
51 | AC_CHECK_HEADERS_ONCE([sys/time.h]) | |
52 | AC_CACHE_CHECK([for struct timespec in <time.h>], | |
53 | [gl_cv_sys_struct_timespec_in_time_h], | |
54 | [AC_COMPILE_IFELSE( | |
55 | [AC_LANG_PROGRAM( | |
56 | [[#include <time.h> | |
57 | ]], | |
58 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
59 | [gl_cv_sys_struct_timespec_in_time_h=yes], | |
60 | [gl_cv_sys_struct_timespec_in_time_h=no])]) | |
61 | ||
62 | TIME_H_DEFINES_STRUCT_TIMESPEC=0 | |
63 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 | |
64 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 | |
4a626d0a | 65 | UNISTD_H_DEFINES_STRUCT_TIMESPEC=0 |
09607c9e TT |
66 | if test $gl_cv_sys_struct_timespec_in_time_h = yes; then |
67 | TIME_H_DEFINES_STRUCT_TIMESPEC=1 | |
68 | else | |
69 | AC_CACHE_CHECK([for struct timespec in <sys/time.h>], | |
70 | [gl_cv_sys_struct_timespec_in_sys_time_h], | |
71 | [AC_COMPILE_IFELSE( | |
72 | [AC_LANG_PROGRAM( | |
73 | [[#include <sys/time.h> | |
74 | ]], | |
75 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
76 | [gl_cv_sys_struct_timespec_in_sys_time_h=yes], | |
77 | [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) | |
78 | if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then | |
79 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 | |
80 | else | |
81 | AC_CACHE_CHECK([for struct timespec in <pthread.h>], | |
82 | [gl_cv_sys_struct_timespec_in_pthread_h], | |
83 | [AC_COMPILE_IFELSE( | |
84 | [AC_LANG_PROGRAM( | |
85 | [[#include <pthread.h> | |
86 | ]], | |
87 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
88 | [gl_cv_sys_struct_timespec_in_pthread_h=yes], | |
89 | [gl_cv_sys_struct_timespec_in_pthread_h=no])]) | |
90 | if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then | |
91 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 | |
4a626d0a PA |
92 | else |
93 | AC_CACHE_CHECK([for struct timespec in <unistd.h>], | |
94 | [gl_cv_sys_struct_timespec_in_unistd_h], | |
95 | [AC_COMPILE_IFELSE( | |
96 | [AC_LANG_PROGRAM( | |
97 | [[#include <unistd.h> | |
98 | ]], | |
99 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
100 | [gl_cv_sys_struct_timespec_in_unistd_h=yes], | |
101 | [gl_cv_sys_struct_timespec_in_unistd_h=no])]) | |
102 | if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then | |
103 | UNISTD_H_DEFINES_STRUCT_TIMESPEC=1 | |
104 | fi | |
09607c9e TT |
105 | fi |
106 | fi | |
107 | fi | |
108 | AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) | |
109 | AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) | |
110 | AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) | |
4a626d0a | 111 | AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC]) |
09607c9e TT |
112 | ]) |
113 | ||
114 | AC_DEFUN([gl_TIME_MODULE_INDICATOR], | |
115 | [ | |
116 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
117 | AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) | |
118 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | |
119 | dnl Define it also as a C macro, for the benefit of the unit tests. | |
120 | gl_MODULE_INDICATOR_FOR_TESTS([$1]) | |
121 | ]) | |
122 | ||
123 | AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], | |
124 | [ | |
c0c3707f | 125 | GNULIB_CTIME=0; AC_SUBST([GNULIB_CTIME]) |
09607c9e | 126 | GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) |
c0c3707f | 127 | GNULIB_LOCALTIME=0; AC_SUBST([GNULIB_LOCALTIME]) |
09607c9e | 128 | GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) |
c0c3707f | 129 | GNULIB_STRFTIME=0; AC_SUBST([GNULIB_STRFTIME]) |
09607c9e TT |
130 | GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) |
131 | GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) | |
9c9d63b1 | 132 | GNULIB_TIMESPEC_GET=0; AC_SUBST([GNULIB_TIMESPEC_GET]) |
09607c9e | 133 | GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) |
4a626d0a | 134 | GNULIB_TIME_RZ=0; AC_SUBST([GNULIB_TIME_RZ]) |
c0c3707f | 135 | GNULIB_TZSET=0; AC_SUBST([GNULIB_TZSET]) |
9c9d63b1 PM |
136 | dnl Support Microsoft deprecated alias function names by default. |
137 | GNULIB_MDA_TZSET=1; AC_SUBST([GNULIB_MDA_TZSET]) | |
09607c9e TT |
138 | dnl Assume proper GNU behavior unless another module says otherwise. |
139 | HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) | |
140 | HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) | |
141 | HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) | |
142 | HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) | |
9c9d63b1 | 143 | HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET]) |
c0c3707f CB |
144 | dnl Even GNU libc does not have timezone_t yet. |
145 | HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T]) | |
09607c9e TT |
146 | dnl If another module says to replace or to not replace, do that. |
147 | dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; | |
148 | dnl this lets maintainers check for portability. | |
c0c3707f | 149 | REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME]) |
09607c9e TT |
150 | REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) |
151 | REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) | |
152 | REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) | |
c0c3707f | 153 | REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME]) |
09607c9e | 154 | REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) |
c0c3707f | 155 | REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET]) |
4a626d0a PA |
156 | |
157 | dnl Hack so that the time module doesn't depend on the sys_time module. | |
158 | dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent. | |
159 | : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY]) | |
160 | dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME | |
161 | dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier | |
162 | dnl is no longer a big deal. | |
163 | REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME]) | |
164 | REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME]) | |
09607c9e | 165 | ]) |