Debian Codegraph @

m4/time_h.m4

raw
1 # Configure a more-standard replacement for <time.h>.
2
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2024 Free Software Foundation, Inc.
4
5 # serial 24
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_ONCE([gl_TIME_H],
14 [
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])
18
19 gl_NEXT_HEADERS([time.h])
20 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
21
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([[
25 #include <time.h>
26 ]], [
27 asctime asctime_r ctime ctime_r gmtime_r localtime localtime_r mktime
28 nanosleep strftime strptime time timegm timespec_get timespec_getres tzset
29 ])
30
31 AC_REQUIRE([AC_C_RESTRICT])
32
33 AC_CACHE_CHECK([for TIME_UTC in <time.h>],
34 [gl_cv_time_h_has_TIME_UTC],
35 [AC_COMPILE_IFELSE(
36 [AC_LANG_PROGRAM(
37 [[#include <time.h>
38 ]],
39 [[static int x = TIME_UTC; x++;]])],
40 [gl_cv_time_h_has_TIME_UTC=yes],
41 [gl_cv_time_h_has_TIME_UTC=no])])
42 if test $gl_cv_time_h_has_TIME_UTC = yes; then
43 TIME_H_DEFINES_TIME_UTC=1
44 else
45 TIME_H_DEFINES_TIME_UTC=0
46 fi
47 AC_SUBST([TIME_H_DEFINES_TIME_UTC])
48 ])
49
50 dnl Check whether 'struct timespec' is declared
51 dnl in time.h, sys/time.h, pthread.h, or unistd.h.
52
53 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
54 [
55 AC_CHECK_HEADERS_ONCE([sys/time.h])
56 AC_CACHE_CHECK([for struct timespec in <time.h>],
57 [gl_cv_sys_struct_timespec_in_time_h],
58 [AC_COMPILE_IFELSE(
59 [AC_LANG_PROGRAM(
60 [[#include <time.h>
61 ]],
62 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
63 [gl_cv_sys_struct_timespec_in_time_h=yes],
64 [gl_cv_sys_struct_timespec_in_time_h=no])])
65
66 TIME_H_DEFINES_STRUCT_TIMESPEC=0
67 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
68 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
69 UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
70 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
71 TIME_H_DEFINES_STRUCT_TIMESPEC=1
72 else
73 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
74 [gl_cv_sys_struct_timespec_in_sys_time_h],
75 [AC_COMPILE_IFELSE(
76 [AC_LANG_PROGRAM(
77 [[#include <sys/time.h>
78 ]],
79 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
80 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
81 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
82 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
83 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
84 else
85 AC_CACHE_CHECK([for struct timespec in <pthread.h>],
86 [gl_cv_sys_struct_timespec_in_pthread_h],
87 [AC_COMPILE_IFELSE(
88 [AC_LANG_PROGRAM(
89 [[#include <pthread.h>
90 ]],
91 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
92 [gl_cv_sys_struct_timespec_in_pthread_h=yes],
93 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
94 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
95 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
96 else
97 AC_CACHE_CHECK([for struct timespec in <unistd.h>],
98 [gl_cv_sys_struct_timespec_in_unistd_h],
99 [AC_COMPILE_IFELSE(
100 [AC_LANG_PROGRAM(
101 [[#include <unistd.h>
102 ]],
103 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
104 [gl_cv_sys_struct_timespec_in_unistd_h=yes],
105 [gl_cv_sys_struct_timespec_in_unistd_h=no])])
106 if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
107 UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
108 fi
109 fi
110 fi
111 fi
112 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
113 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
114 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
115 AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
116 ])
117
118 # gl_TIME_MODULE_INDICATOR([modulename])
119 # sets the shell variable that indicates the presence of the given module
120 # to a C preprocessor expression that will evaluate to 1.
121 # This macro invocation must not occur in macros that are AC_REQUIREd.
122 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
123 [
124 dnl Ensure to expand the default settings once only.
125 gl_TIME_H_REQUIRE_DEFAULTS
126 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
127 dnl Define it also as a C macro, for the benefit of the unit tests.
128 gl_MODULE_INDICATOR_FOR_TESTS([$1])
129 ])
130
131 # Initializes the default values for AC_SUBSTed shell variables.
132 # This macro must not be AC_REQUIREd. It must only be invoked, and only
133 # outside of macros or in macros that are not AC_REQUIREd.
134 AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
135 [
136 m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
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 yet.
167 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
168 REPLACE_CTIME=0; AC_SUBST([REPLACE_CTIME])
169 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
170 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])
171 REPLACE_LOCALTIME_R=0; AC_SUBST([REPLACE_LOCALTIME_R])
172 REPLACE_MKTIME=0; AC_SUBST([REPLACE_MKTIME])
173 REPLACE_NANOSLEEP=0; AC_SUBST([REPLACE_NANOSLEEP])
174 REPLACE_STRFTIME=0; AC_SUBST([REPLACE_STRFTIME])
175 REPLACE_TIME=0; AC_SUBST([REPLACE_TIME])
176 REPLACE_TIMEGM=0; AC_SUBST([REPLACE_TIMEGM])
177 REPLACE_TIMESPEC_GET=0; AC_SUBST([REPLACE_TIMESPEC_GET])
178 REPLACE_TZSET=0; AC_SUBST([REPLACE_TZSET])
179 ])