]> git.ipfire.org Git - thirdparty/util-linux.git/blob - m4/year2038.m4
libsmartcols: (filter) use variable argument lists for yyerror()
[thirdparty/util-linux.git] / m4 / year2038.m4
1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Macros that test for specific, unclassified, features.
3 #
4 # Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software
5 # Foundation, Inc.
6
7 # This file is part of Autoconf. This program is free
8 # software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # Under Section 7 of GPL version 3, you are granted additional
19 # permissions described in the Autoconf Configure Script Exception,
20 # version 3.0, as published by the Free Software Foundation.
21 #
22 # You should have received a copy of the GNU General Public License
23 # and a copy of the Autoconf Configure Script Exception along with
24 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
25 # respectively. If not, see <https://www.gnu.org/licenses/>.
26
27 # Written by David MacKenzie, with help from
28 # François Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
29 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
30 # _AC_SYS_YEAR2038_TEST_CODE
31 # --------------------------
32 # C code used to probe for time_t that can represent time points more
33 # than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
34 # these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
35 # hence the name.
36
37 AC_DEFUN([_AC_SYS_YEAR2038_TEST_CODE],
38 [[
39 #include <time.h>
40 /* Check that time_t can represent 2**32 - 1 correctly. */
41 #define LARGE_TIME_T \\
42 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))
43 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535
44 && LARGE_TIME_T % 65537 == 0)
45 ? 1 : -1];
46 ]])
47
48 # _AC_SYS_YEAR2038_OPTIONS
49 # ------------------------
50 # List of known ways to enable support for large time_t. If you change
51 # this list you probably also need to change the AS_CASE at the end of
52 # _AC_SYS_YEAR2038_PROBE.
53 m4_define([_AC_SYS_YEAR2038_OPTIONS], m4_normalize(
54 ["none needed"] dnl 64-bit and newer 32-bit Unix
55 ["-D_TIME_BITS=64"] dnl glibc 2.34 with some 32-bit ABIs
56 ["-D__MINGW_USE_VC2005_COMPAT"] dnl 32-bit MinGW
57 ["-U_USE_32_BIT_TIME_T -D__MINGW_USE_VC2005_COMPAT"]
58 dnl 32-bit MinGW (misconfiguration)
59 ))
60
61 # _AC_SYS_YEAR2038_PROBE
62 # ----------------------
63 # Subroutine of AC_SYS_YEAR2038. Probe for time_t that can represent
64 # time points more than 2**31 - 1 seconds after the epoch (dates after
65 # 2038-01-18, see above) and set the cache variable ac_cv_sys_year2038_opts
66 # to one of the values in the _AC_SYS_YEAR2038_OPTIONS list, or to
67 # "support not detected" if none of them worked. Then, set compilation
68 # options and #defines as necessary to enable large time_t support.
69 #
70 # Note that we do not test whether mktime, localtime, etc. handle
71 # large values of time_t correctly, as that would require use of
72 # AC_TRY_RUN. Note also that some systems only support large time_t
73 # together with large off_t.
74 #
75 # If you change this macro you may also need to change
76 # _AC_SYS_YEAR2038_OPTIONS.
77 AC_DEFUN([_AC_SYS_YEAR2038_PROBE],
78 [AC_CACHE_CHECK([for $CC option for timestamps after 2038],
79 [ac_cv_sys_year2038_opts],
80 [ac_save_CPPFLAGS="$CPPFLAGS"
81 ac_opt_found=no
82 for ac_opt in _AC_SYS_YEAR2038_OPTIONS; do
83 AS_IF([test x"$ac_opt" != x"none needed"],
84 [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
85 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_YEAR2038_TEST_CODE])],
86 [ac_cv_sys_year2038_opts="$ac_opt"
87 ac_opt_found=yes])
88 test $ac_opt_found = no || break
89 done
90 CPPFLAGS="$ac_save_CPPFLAGS"
91 test $ac_opt_found = yes || ac_cv_sys_year2038_opts="support not detected"])
92
93 ac_have_year2038=yes
94 AS_CASE([$ac_cv_sys_year2038_opts],
95 ["none needed"], [],
96 ["support not detected"],
97 [ac_have_year2038=no],
98
99 ["-D_TIME_BITS=64"],
100 [AC_DEFINE([_TIME_BITS], [64],
101 [Number of bits in time_t, on hosts where this is settable.])],
102
103 ["-D__MINGW_USE_VC2005_COMPAT"],
104 [AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
105 [Define to 1 on platforms where this makes time_t a 64-bit type.])],
106
107 ["-U_USE_32_BIT_TIME_T"*],
108 [AC_MSG_FAILURE(m4_text_wrap(
109 [the 'time_t' type is currently forced to be 32-bit.
110 It will stop working after mid-January 2038.
111 Remove _USE_32BIT_TIME_T from the compiler flags.],
112 [], [], [55]))],
113
114 [AC_MSG_ERROR(
115 [internal error: bad value for \$ac_cv_sys_year2038_opts])])
116 ])
117
118 # _AC_SYS_YEAR2038_ENABLE
119 # -----------------------
120 # Depending on which of the YEAR2038 macros was used, add either an
121 # --enable-year2038 or a --disable-year2038 to
122 # the configure script. This is expanded very late and
123 # therefore there cannot be any code in the AC_ARG_ENABLE. The
124 # default value for 'enable_year2038' is emitted unconditionally
125 # because the generated code always looks at this variable.
126 m4_define([_AC_SYS_YEAR2038_ENABLE],
127 [m4_divert_text([DEFAULTS],
128 m4_provide_if([AC_SYS_YEAR2038],
129 [enable_year2038=yes],
130 [enable_year2038=no]))]dnl
131 [AC_ARG_ENABLE([year2038],
132 m4_provide_if([AC_SYS_YEAR2038],
133 [AS_HELP_STRING([--disable-year2038],
134 [don't support timestamps after 2038])],
135 [AS_HELP_STRING([--enable-year2038],
136 [support timestamps after 2038])]))])
137
138 # AC_SYS_YEAR2038
139 # ---------------
140 # Attempt to detect and activate support for large time_t.
141 # On systems where time_t is not always 64 bits, this probe can be
142 # skipped by passing the --disable-year2038 option to configure.
143 AC_DEFUN([AC_SYS_YEAR2038],
144 [AC_REQUIRE([AC_SYS_LARGEFILE])dnl
145 AS_IF([test "$enable_year2038,$ac_have_year2038,$cross_compiling" = yes,no,no],
146 [# If we're not cross compiling and 'touch' works with a large
147 # timestamp, then we can presume the system supports wider time_t
148 # *somehow* and we just weren't able to detect it. One common
149 # case that we deliberately *don't* probe for is a system that
150 # supports both 32- and 64-bit ABIs but only the 64-bit ABI offers
151 # wide time_t. (It would be inappropriate for us to override an
152 # intentional use of -m32.) Error out, demanding use of
153 # --disable-year2038 if this is intentional.
154 AS_IF([TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null],
155 [AS_CASE([`TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null`],
156 [*'Feb 7 2106'* | *'Feb 7 17:10'*],
157 [AC_MSG_FAILURE(m4_text_wrap(
158 [this system appears to support timestamps after mid-January 2038,
159 but no mechanism for enabling wide 'time_t' was detected.
160 Did you mean to build a 64-bit binary? (E.g., 'CC="${CC} -m64"'.)
161 To proceed with 32-bit time_t, configure with '--disable-year2038'.],
162 [], [], [55]))])])])])
163
164 # AC_SYS_YEAR2038_RECOMMENDED
165 # ---------------------------
166 # Same as AC_SYS_YEAR2038, but recommend support for large time_t.
167 # If we cannot find any way to make time_t capable of representing
168 # values larger than 2**31 - 1, error out unless --disable-year2038 is given.
169 AC_DEFUN([AC_SYS_YEAR2038_RECOMMENDED],
170 [AC_REQUIRE([AC_SYS_YEAR2038])dnl
171 AS_IF([test "$enable_year2038,$ac_have_year2038" = yes,no],
172 [AC_MSG_FAILURE(m4_text_wrap(
173 [could not enable timestamps after mid-January 2038.
174 This package recommends support for these later timestamps.
175 However, to proceed with signed 32-bit time_t even though it
176 will fail then, configure with '--disable-year2038'.],
177 [], [], [55]))])])
178
179 AC_DEFUN([UL_YEAR2038_INIT],[
180 AS_IF([test "$enable_year2038" != no],
181 [_AC_SYS_YEAR2038_PROBE])
182 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])])