1 # Configure a more-standard replacement for <time.h>.
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2023 Free Software Foundation, Inc.
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.
11 # Written by Paul Eggert and Jim Meyering.
13 AC_DEFUN_ONCE([gl_TIME_H],
15 dnl Ensure to expand the default settings once only, before all statements
16 dnl that occur in other macros.
17 AC_REQUIRE([gl_TIME_H_DEFAULTS])
19 gl_NEXT_HEADERS([time.h])
20 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
22 dnl Check for declarations of anything we want to poison if the
23 dnl corresponding gnulib module is not in use.
24 gl_WARN_ON_USE_PREPARE([[
26 ]], [asctime_r ctime_r])
28 AC_REQUIRE([AC_C_RESTRICT])
30 AC_CACHE_CHECK([for TIME_UTC in <time.h>],
31 [gl_cv_time_h_has_TIME_UTC],
36 [[static int x = TIME_UTC; x++;]])],
37 [gl_cv_time_h_has_TIME_UTC=yes],
38 [gl_cv_time_h_has_TIME_UTC=no])])
39 if test $gl_cv_time_h_has_TIME_UTC = yes; then
40 TIME_H_DEFINES_TIME_UTC=1
42 TIME_H_DEFINES_TIME_UTC=0
44 AC_SUBST([TIME_H_DEFINES_TIME_UTC])
47 dnl Check whether 'struct timespec' is declared
48 dnl in time.h, sys/time.h, pthread.h, or unistd.h.
50 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
52 AC_CHECK_HEADERS_ONCE([sys/time.h])
53 AC_CACHE_CHECK([for struct timespec in <time.h>],
54 [gl_cv_sys_struct_timespec_in_time_h],
59 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
60 [gl_cv_sys_struct_timespec_in_time_h=yes],
61 [gl_cv_sys_struct_timespec_in_time_h=no])])
63 TIME_H_DEFINES_STRUCT_TIMESPEC=0
64 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
65 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
66 UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
67 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
68 TIME_H_DEFINES_STRUCT_TIMESPEC=1
70 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
71 [gl_cv_sys_struct_timespec_in_sys_time_h],
74 [[#include <sys/time.h>
76 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
77 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
78 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
79 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
80 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
82 AC_CACHE_CHECK([for struct timespec in <pthread.h>],
83 [gl_cv_sys_struct_timespec_in_pthread_h],
86 [[#include <pthread.h>
88 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
89 [gl_cv_sys_struct_timespec_in_pthread_h=yes],
90 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
91 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
92 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
94 AC_CACHE_CHECK([for struct timespec in <unistd.h>],
95 [gl_cv_sys_struct_timespec_in_unistd_h],
100 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
101 [gl_cv_sys_struct_timespec_in_unistd_h=yes],
102 [gl_cv_sys_struct_timespec_in_unistd_h=no])])
103 if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
104 UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
109 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
110 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
111 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
112 AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
115 # gl_TIME_MODULE_INDICATOR([modulename])
116 # sets the shell variable that indicates the presence of the given module
117 # to a C preprocessor expression that will evaluate to 1.
118 # This macro invocation must not occur in macros that are AC_REQUIREd.
119 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
121 dnl Ensure to expand the default settings once only.
122 gl_TIME_H_REQUIRE_DEFAULTS
123 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
124 dnl Define it also as a C macro, for the benefit of the unit tests.
125 gl_MODULE_INDICATOR_FOR_TESTS([$1])
128 # Initializes the default values for AC_SUBSTed shell variables.
129 # This macro must not be AC_REQUIREd. It must only be invoked, and only
130 # outside of macros or in macros that are not AC_REQUIREd.
131 AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
133 m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET])
146 dnl Support Microsoft deprecated alias function names by default.
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1])
149 m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS])
150 AC_REQUIRE([gl_TIME_H_DEFAULTS])
153 AC_DEFUN([gl_TIME_H_DEFAULTS],
155 dnl Assume proper GNU behavior unless another module says otherwise.
156 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
157 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
158 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
159 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
160 HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET])
161 HAVE_TIMESPEC_GETRES=1; AC_SUBST([HAVE_TIMESPEC_GETRES])
162 dnl Even GNU libc does not have timezone_t yet.
163 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
164 dnl If another module says to replace or to not replace, do that.
165 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
166 dnl this lets maintainers check for portability.
167 REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME])
168 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
169 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
170 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
171 REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME])
172 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
173 REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET])
175 dnl Hack so that the time module doesn't depend on the sys_time module.
176 dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
177 : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY])
178 dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
179 dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
180 dnl is no longer a big deal.
181 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
182 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])