Debian Codegraph @

m4/time_h.m4

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