Debian Codegraph @

m4/largefile.m4

raw
1 # Enable large files on systems where this is not the default.
2 # Enable support for files on Linux file systems with 64-bit inode numbers.
3
4 # Copyright 1992-1996, 1998-2024 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
8
9 # The following macro works around a problem in Autoconf's AC_FUNC_FSEEKO:
10 # It does not set _LARGEFILE_SOURCE=1 on HP-UX/ia64 32-bit, although this
11 # setting of _LARGEFILE_SOURCE is needed so that <stdio.h> declares fseeko
12 # and ftello in C++ mode as well.
13 # This problem occurs in Autoconf 2.71 and earlier, which lack AC_SYS_YEAR2038.
14 AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
15 m4_ifndef([AC_SYS_YEAR2038], [[
16 AC_REQUIRE([AC_CANONICAL_HOST])
17 AC_FUNC_FSEEKO
18 case "$host_os" in
19 hpux*)
20 AC_DEFINE([_LARGEFILE_SOURCE], [1],
21 [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
22 ;;
23 esac
24 ]])
25 )
26
27 m4_ifndef([AC_SYS_YEAR2038_RECOMMENDED], [
28 # Support AC_SYS_YEAR2038_RECOMMENDED and related macros, even if
29 # Autoconf 2.71 or earlier. This code is taken from Autoconf master.
30
31 # _AC_SYS_YEAR2038_TEST_CODE
32 # --------------------------
33 # C code used to probe for time_t that can represent time points more
34 # than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
35 # these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
36 # hence the name.
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_SYS_LARGEFILE_TEST_CODE
180 # ---------------------------
181 # C code used to probe for large file support.
182 m4_define([_AC_SYS_LARGEFILE_TEST_CODE],
183 [@%:@include <sys/types.h>
184 @%:@ifndef FTYPE
185 @%:@ define FTYPE off_t
186 @%:@endif
187 /* Check that FTYPE can represent 2**63 - 1 correctly.
188 We can't simply define LARGE_FTYPE to be 9223372036854775807,
189 since some C++ compilers masquerading as C compilers
190 incorrectly reject 9223372036854775807. */
191 @%:@define LARGE_FTYPE (((FTYPE) 1 << 31 << 31) - 1 + ((FTYPE) 1 << 31 << 31))
192 int FTYPE_is_large[[(LARGE_FTYPE % 2147483629 == 721
193 && LARGE_FTYPE % 2147483647 == 1)
194 ? 1 : -1]];[]dnl
195 ])
196 # Defined by Autoconf 2.71 and circa 2022 Gnulib unwisely depended on it.
197 m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], [_AC_SYS_LARGEFILE_TEST_CODE])
198
199 # _AC_SYS_LARGEFILE_OPTIONS
200 # -------------------------
201 # List of known ways to enable support for large files. If you change
202 # this list you probably also need to change the AS_CASE at the end of
203 # _AC_SYS_LARGEFILE_PROBE.
204 m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize(
205 ["none needed"] dnl Most current systems
206 ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec
207 ["-D_LARGE_FILES=1"] dnl 32-bit AIX 4.2.1+, 32-bit z/OS
208 ["-n32"] dnl 32-bit IRIX 6, SGI cc (obsolete)
209 ))
210
211 # _AC_SYS_LARGEFILE_PROBE
212 # -----------------------
213 # Subroutine of AC_SYS_LARGEFILE. Probe for large file support and set
214 # the cache variable ac_cv_sys_largefile_opts to one of the values in
215 # the _AC_SYS_LARGEFILE_OPTIONS list, or to "support not detected" if
216 # none of the options in that list worked. Then, set compilation
217 # options and #defines as necessary to enable large file support.
218 #
219 # If large file support is not detected, the behavior depends on which of
220 # the top-level AC_SYS_LARGEFILE macros was used (see below).
221 #
222 # If you change this macro you may also need to change
223 # _AC_SYS_LARGEFILE_OPTIONS.
224 AC_DEFUN([_AC_SYS_LARGEFILE_PROBE],
225 [AC_CACHE_CHECK([for $CC option to enable large file support],
226 [ac_cv_sys_largefile_opts],
227 [ac_save_CC="$CC"
228 ac_opt_found=no
229 for ac_opt in _AC_SYS_LARGEFILE_OPTIONS; do
230 AS_IF([test x"$ac_opt" != x"none needed"],
231 [CC="$ac_save_CC $ac_opt"])
232 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_CODE])],
233 [AS_IF([test x"$ac_opt" = x"none needed"],
234 [# GNU/Linux s390x and alpha need _FILE_OFFSET_BITS=64 for wide ino_t.
235 CC="$CC -DFTYPE=ino_t"
236 AC_COMPILE_IFELSE([], [],
237 [CC="$CC -D_FILE_OFFSET_BITS=64"
238 AC_COMPILE_IFELSE([], [ac_opt='-D_FILE_OFFSET_BITS=64'])])])
239 ac_cv_sys_largefile_opts=$ac_opt
240 ac_opt_found=yes])
241 test $ac_opt_found = no || break
242 done
243 CC="$ac_save_CC"
244 dnl Gnulib implements large file support for native Windows, based on the
245 dnl variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE.
246 m4_ifdef([gl_LARGEFILE], [
247 AC_REQUIRE([AC_CANONICAL_HOST])
248 if test $ac_opt_found != yes; then
249 AS_CASE([$host_os],
250 [mingw* | windows*],
251 [ac_cv_sys_largefile_opts="supported through gnulib"
252 ac_opt_found=yes]
253 )
254 fi
255 ])
256 test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected"])
257
258 ac_have_largefile=yes
259 AS_CASE([$ac_cv_sys_largefile_opts],
260 ["none needed"], [],
261 ["supported through gnulib"], [],
262 ["support not detected"],
263 [ac_have_largefile=no],
264
265 ["-D_FILE_OFFSET_BITS=64"],
266 [AC_DEFINE([_FILE_OFFSET_BITS], [64],
267 [Number of bits in a file offset, on hosts where this is settable.])],
268
269 ["-D_LARGE_FILES=1"],
270 [AC_DEFINE([_LARGE_FILES], [1],
271 [Define to 1 on platforms where this makes off_t a 64-bit type.])],
272
273 ["-n32"],
274 [CC="$CC -n32"],
275
276 [AC_MSG_ERROR(
277 [internal error: bad value for \$ac_cv_sys_largefile_opts])])
278
279 AS_IF([test "$enable_year2038" != no],
280 [_AC_SYS_YEAR2038_PROBE])
281 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])])
282
283 # AC_SYS_LARGEFILE
284 # ----------------
285 # By default, many hosts won't let programs access large files;
286 # one must use special compiler options to get large-file access to work.
287 # For more details about this brain damage please see:
288 # http://www.unix.org/version2/whatsnew/lfs20mar.html
289 # Additionally, on Linux file systems with 64-bit inodes a file that happens
290 # to have a 64-bit inode number cannot be accessed by 32-bit applications on
291 # Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
292 AC_DEFUN([AC_SYS_LARGEFILE],
293 [AC_ARG_ENABLE([largefile],
294 [AS_HELP_STRING([--disable-largefile],
295 [omit support for large files])])dnl
296 AS_IF([test "$enable_largefile,$enable_year2038" != no,no],
297 [_AC_SYS_LARGEFILE_PROBE])])
298 ])# m4_ifndef AC_SYS_YEAR2038_RECOMMENDED
299
300 # Enable large files on systems where this is implemented by Gnulib, not by the
301 # system headers.
302 # Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
303 # overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
304 AC_DEFUN([gl_LARGEFILE],
305 [
306 AC_REQUIRE([AC_CANONICAL_HOST])
307 case "$host_os" in
308 mingw* | windows*)
309 dnl Native Windows.
310 dnl mingw64 defines off_t to a 64-bit type already, if
311 dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
312 AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
313 [AC_COMPILE_IFELSE(
314 [AC_LANG_PROGRAM(
315 [[#include <sys/types.h>
316 int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
317 ]],
318 [[]])],
319 [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
320 ])
321 if test $gl_cv_type_off_t_64 = no; then
322 WINDOWS_64_BIT_OFF_T=1
323 else
324 WINDOWS_64_BIT_OFF_T=0
325 fi
326 dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
327 dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
328 dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
329 AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
330 [AC_COMPILE_IFELSE(
331 [AC_LANG_PROGRAM(
332 [[#include <sys/types.h>
333 struct stat buf;
334 int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
335 ]],
336 [[]])],
337 [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
338 ])
339 if test $gl_cv_member_st_size_64 = no; then
340 WINDOWS_64_BIT_ST_SIZE=1
341 else
342 WINDOWS_64_BIT_ST_SIZE=0
343 fi
344 ;;
345 *)
346 dnl Nothing to do on gnulib's side.
347 dnl A 64-bit off_t is
348 dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
349 dnl OSF/1, Cygwin,
350 dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
351 dnl glibc, HP-UX, Solaris,
352 dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
353 dnl - impossible to achieve on Minix 3.1.8.
354 WINDOWS_64_BIT_OFF_T=0
355 WINDOWS_64_BIT_ST_SIZE=0
356 ;;
357 esac
358 ])