Debian Codegraph @

tools/gnulib/m4/time_h.m4

raw
1 # time_h.m4
2 # serial 27
3 dnl Copyright (C) 2000-2001, 2003-2007, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 # Configure a more-standard replacement for <time.h>.
9
10 # Written by Paul Eggert and Jim Meyering.
11
12 AC_DEFUN_ONCE([gl_TIME_H],
13 [
14 dnl Ensure to expand the default settings once only, before all statements
15 dnl that occur in other macros.
16 AC_REQUIRE([gl_TIME_H_DEFAULTS])
17
18 gl_NEXT_HEADERS([time.h])
19 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
20
21 dnl Check for declarations of anything we want to poison if the
22 dnl corresponding gnulib module is not in use.
23 gl_WARN_ON_USE_PREPARE([[
24 #include <time.h>
25 ]], [
26 asctime asctime_r ctime ctime_r gmtime_r localtime localtime_r mktime
27 nanosleep strftime strptime time timegm timespec_get timespec_getres tzset
28 ])
29
30 AC_REQUIRE([AC_C_RESTRICT])
31
32 AC_CACHE_CHECK([for TIME_UTC in <time.h>],
33 [gl_cv_time_h_has_TIME_UTC],
34 [AC_COMPILE_IFELSE(
35 [AC_LANG_PROGRAM(
36 [[#include <time.h>
37 ]],
38 [[static int x = TIME_UTC; x++;]])],
39 [gl_cv_time_h_has_TIME_UTC=yes],
40 [gl_cv_time_h_has_TIME_UTC=no])])
41 if test $gl_cv_time_h_has_TIME_UTC = yes; then
42 TIME_H_DEFINES_TIME_UTC=1
43 else
44 TIME_H_DEFINES_TIME_UTC=0
45 fi
46 AC_SUBST([TIME_H_DEFINES_TIME_UTC])
47 ])
48
49 dnl Check whether 'struct timespec' is declared
50 dnl in time.h, sys/time.h, pthread.h, or unistd.h.
51
52 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
53 [
54 AC_CHECK_HEADERS_ONCE([sys/time.h])
55 AC_CACHE_CHECK([for struct timespec in <time.h>],
56 [gl_cv_sys_struct_timespec_in_time_h],
57 [AC_COMPILE_IFELSE(
58 [AC_LANG_PROGRAM(
59 [[#include <time.h>
60 ]],
61 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
62 [gl_cv_sys_struct_timespec_in_time_h=yes],
63 [gl_cv_sys_struct_timespec_in_time_h=no])])
64
65 TIME_H_DEFINES_STRUCT_TIMESPEC=0
66 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
67 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
68 UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
69 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
70 TIME_H_DEFINES_STRUCT_TIMESPEC=1
71 else
72 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
73 [gl_cv_sys_struct_timespec_in_sys_time_h],
74 [AC_COMPILE_IFELSE(
75 [AC_LANG_PROGRAM(
76 [[#include <sys/time.h>
77 ]],
78 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
79 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
80 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
81 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
82 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
83 else
84 AC_CACHE_CHECK([for struct timespec in <pthread.h>],
85 [gl_cv_sys_struct_timespec_in_pthread_h],
86 [AC_COMPILE_IFELSE(
87 [AC_LANG_PROGRAM(
88 [[#include <pthread.h>
89 ]],
90 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
91 [gl_cv_sys_struct_timespec_in_pthread_h=yes],
92 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
93 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
94 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
95 else
96 AC_CACHE_CHECK([for struct timespec in <unistd.h>],
97 [gl_cv_sys_struct_timespec_in_unistd_h],
98 [AC_COMPILE_IFELSE(
99 [AC_LANG_PROGRAM(
100 [[#include <unistd.h>
101 ]],
102 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
103 [gl_cv_sys_struct_timespec_in_unistd_h=yes],
104 [gl_cv_sys_struct_timespec_in_unistd_h=no])])
105 if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
106 UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
107 fi
108 fi
109 fi
110 fi
111 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
112 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
113 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
114 AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
115 ])
116
117 # gl_TIME_MODULE_INDICATOR([modulename])
118 # sets the shell variable that indicates the presence of the given module
119 # to a C preprocessor expression that will evaluate to 1.
120 # This macro invocation must not occur in macros that are AC_REQUIREd.
121 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
122 [
123 dnl Ensure to expand the default settings once only.
124 gl_TIME_H_REQUIRE_DEFAULTS
125 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
126 dnl Define it also as a C macro, for the benefit of the unit tests.
127 gl_MODULE_INDICATOR_FOR_TESTS([$1])
128 ])
129
130 # Initializes the default values for AC_SUBSTed shell variables.
131 # This macro must not be AC_REQUIREd. It must only be invoked, and only
132 # outside of macros or in macros that are not AC_REQUIREd.
133 AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
134 [
135 m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZNAME])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET])
150 dnl Support Microsoft deprecated alias function names by default.
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1])
152 ])
153 m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS])
154 AC_REQUIRE([gl_TIME_H_DEFAULTS])
155 ])
156
157 AC_DEFUN([gl_TIME_H_DEFAULTS],
158 [
159 dnl Assume proper GNU behavior unless another module says otherwise.
160 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
161 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
162 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
163 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
164 HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET])
165 HAVE_TIMESPEC_GETRES=1; AC_SUBST([HAVE_TIMESPEC_GETRES])
166 dnl Even GNU libc does not have timezone_t and tzalloc() yet.
167 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
168 HAVE_TZALLOC=0; AC_SUBST([HAVE_TZALLOC])
169 REPLACE_CTIME=0; AC_SUBST([REPLACE_CTIME])
170 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
171 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])
172 REPLACE_LOCALTIME_R=0; AC_SUBST([REPLACE_LOCALTIME_R])
173 REPLACE_LOCALTIME_RZ=0; AC_SUBST([REPLACE_LOCALTIME_RZ])
174 REPLACE_MKTIME=0; AC_SUBST([REPLACE_MKTIME])
175 REPLACE_MKTIME_Z=0; AC_SUBST([REPLACE_MKTIME_Z])
176 REPLACE_NANOSLEEP=0; AC_SUBST([REPLACE_NANOSLEEP])
177 REPLACE_STRFTIME=0; AC_SUBST([REPLACE_STRFTIME])
178 REPLACE_TIME=0; AC_SUBST([REPLACE_TIME])
179 REPLACE_TIMEGM=0; AC_SUBST([REPLACE_TIMEGM])
180 REPLACE_TIMESPEC_GET=0; AC_SUBST([REPLACE_TIMESPEC_GET])
181 REPLACE_TIMESPEC_GETRES=0; AC_SUBST([REPLACE_TIMESPEC_GETRES])
182 REPLACE_TZSET=0; AC_SUBST([REPLACE_TZSET])
183 ])