@c Same as @dvar{ARG, DEFAULT-VAR}, but with @var instead of @samp
@c around DEFAULT-VAR.
@macro dvarv{varname, default}
-@r{[}@var{\varname\} = @var{\default\}@r{]}@c
+@r{[}@var{\varname\} = @var{\default\}@r{]}
@end macro
@c Handling the indexes with Texinfo yields several different problems.
@code{ac_cv_func_vfork} variables.
@end defmac
+@anchor{AC_FUNC_FSEEKO}
@defmac AC_FUNC_FSEEKO
@acindex{FUNC_FSEEKO}
@cvindex _LARGEFILE_SOURCE
@c @fuindex ftello
@prindex @code{ftello}
@c @caindex sys_largefile_source
-If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
-Define @code{_LARGEFILE_SOURCE} if necessary to make the prototype
-visible on some systems (e.g., glibc 2.2). Otherwise linkage problems
-may occur when compiling with @code{AC_SYS_LARGEFILE} on
-largefile-sensitive systems where @code{off_t} does not default to a
-64bit entity. All systems with @code{fseeko} also supply @code{ftello}.
+If the @code{fseeko} and @code{ftello} functions are available, define
+@code{HAVE_FSEEKO}. Define @code{_LARGEFILE_SOURCE} if necessary to
+make the prototype visible.
+
+Configure scripts that use @code{AC_FUNC_FSEEKO} should normally also
+use @code{AC_SYS_LARGEFILE} to ensure that @code{off_t} can represent
+all supported file sizes. @xref{AC_SYS_LARGEFILE}.
The Gnulib module @code{fseeko} invokes @code{AC_FUNC_FSEEKO}
and also contains workarounds for other portability problems of
if the system supports @samp{#!}, @samp{no} if not.
@end defmac
+@anchor{AC_SYS_LARGEFILE}
@defmac AC_SYS_LARGEFILE
@acindex{SYS_LARGEFILE}
@cvindex _FILE_OFFSET_BITS
-@cvindex _LARGE_FILES
-@cvindex _TIME_BITS
@ovindex CC
@cindex Large file support
@cindex LFS
-Arrange for 64-bit file offsets, known as
-@uref{http://@/www.unix.org/@/version2/@/whatsnew/@/lfs20mar.html,
-large-file support}, along with other large attributes.
-On some hosts, one must use special compiler options
-to build programs that can access files with large sizes inode
-numbers, timestamps, or other attributes. Append any such
-options to the output variable @code{CC}. Define
-@code{_FILE_OFFSET_BITS}, @code{_LARGE_FILES}, and @code{_TIME_BITS}
-if necessary.
+If the default @code{off_t} type is a 32-bit integer, and therefore
+cannot be used to work with files larger than 4 gigabytes, arrange to
+make a larger @code{off_t} available, if the system supports this.
+Several other types related to the sizes of files and file systems will
+also be enlarged: @code{ino_t}, @code{blkcnt_t}, @code{fsblkcnt_t},
+@code{fsfilcnt_t}, and possibly @code{dev_t}.
+
+If a large @code{off_t} is available (whether or not any arrangements
+were necessary), the shell variable @code{ac_have_largefile} will be set
+to @samp{yes}; if not, it will be set to @samp{no}.
+
+Preprocessor macros will be defined if necessary to make a larger
+@code{off_t} available. (For example, on many systems the macro
+@code{_FILE_OFFSET_BITS} will be defined.) Some of these macros only
+work if they are defined before the first system header is included;
+therefore, when using this macro in concert with
+@code{AC_CONFIG_HEADERS}, make sure that @file{config.h} is included
+before any system headers.
+
+On a few older systems, the output variable @code{CC} will also be
+changed to add special compiler options that are needed to enable large
+@code{off_t}.
Large-file support can be disabled by configuring with the
-@option{--disable-largefile} option. If you disable large-file
-support, your program may have trouble accessing arbitrary files, such
-as files that might be found in an adversary's directory.
-
-If you use this macro, check that your program works even when the types
-@code{blkcnt_t}, @code{dev_t}, @code{ino_t}, @code{off_t}, and @code{time_t}
-are wider than @code{long int}, since this is common when
-large-file support is enabled. For example, it is not correct to print
-an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
-(long int) X)}. Also, when using this macro in concert with
-@code{AC_CONFIG_HEADERS}, be sure that @file{config.h} is included
-before any system header.
+@option{--disable-largefile} option. Note that this has no effect on
+systems where @code{off_t} is 64 bits or larger by default. Disabling
+large-file support can have surprising effects, such as causing
+functions like @code{readdir} and @code{stat} to fail on small files
+(because their @emph{inode numbers} are unrepresentable).
-The LFS introduced the @code{fseeko} and @code{ftello} functions to
-replace their C counterparts @code{fseek} and @code{ftell} that do not
-use @code{off_t}. Take care to use @code{AC_FUNC_FSEEKO} to make their
-prototypes available when using them and large-file support is
-enabled.
+Regardless of whether you use this macro, portable programs should not
+assume that any of the types listed above fit into a @code{long int}.
+For example, it is not correct to print an arbitrary @code{off_t} value
+@code{X} with @code{printf ("%ld", (long int) X)}.
+
+Note that the standard C library functions @code{fseek} and @code{ftell}
+do not use @code{off_t}. If you need to use either of these functions,
+you should use @code{AC_FUNC_FSEEKO} as well as @code{AC_SYS_LARGEFILE},
+and then use their Posix replacements @code{fseeko} and @code{ftello},
+which @emph{do} use @code{off_t}, when available. @xref{AC_FUNC_FSEEKO}.
+
+As of Autoconf 2.72, @code{AC_SYS_LARGEFILE} also @emph{optionally}
+arranges to enlarge @code{time_t}. This is to make it easier to build
+programs that support timestamps after 2038; many configure scripts will
+not need to be modified, only regenerated with newer Autoconf. When
+@code{AC_SYS_LARGEFILE} is used, and @code{AC_SYS_YEAR2038} is
+@emph{not} used, @code{time_t} will normally be left at the system's
+default size, but you can request it be enlarged by configuring with the
+@option{--enable-year2038} option. (When @code{AC_SYS_YEAR2038} is also
+used, @code{time_t} is enlarged if possible. @xref{AC_SYS_YEAR2038}.)
+@end defmac
+
+@defmac AC_SYS_LARGEFILE_REQUIRED
+@acindex{SYS_LARGEFILE_REQUIRED}
+This macro has the same effect as @code{AC_SYS_LARGEFILE},
+but also declares that the program being configured
+@emph{requires} support for large files.
+If a large @code{off_t} is unavailable,
+@command{configure} will error out.
+The @option{--disable-largefile} option will not be available.
@end defmac
+
@anchor{AC_SYS_LONG_FILE_NAMES}
@defmac AC_SYS_LONG_FILE_NAMES
@acindex{SYS_LONG_FILE_NAMES}
@samp{yes}. If not, set the variable to @samp{no}.
@end defmac
+@anchor{AC_SYS_YEAR2038}
@defmac AC_SYS_YEAR2038
@acindex{SYS_YEAR2038}
@cvindex _TIME_BITS
-@ovindex CC
@cindex Year 2038
-If the default @code{time_t} type is a signed 32-bit integer that stops
-working in the year 2038, then arrange to use a wider @code{time_t} if
-possible and report a fatal error otherwise. Define @code{_TIME_BITS}
-if necessary.
-
-Wider-time support can be disabled by configuring with the
-@option{--disable-year2038} option.
+If the default @code{time_t} type is a signed 32-bit integer,
+and therefore (assuming the usual Unix epoch) cannot represent
+timestamps after mid-January of 2038, arrange to make a larger
+@code{time_t} available, if the system supports this.
+
+If a large @code{time_t} is available (whether or not any arrangements
+were necessary), the shell variable @code{ac_have_year2038} will be set
+to @samp{yes}; if not, it will be set to @samp{no}.
+
+Preprocessor macros will be defined if necessary to make a larger
+@code{time_t} available. (For example, on some systems the macro
+@code{_TIME_BITS} will be defined.) Some of these macros only work if
+they are defined before the first system header is included; therefore,
+when using this macro in concert with @code{AC_CONFIG_HEADERS}, make
+sure that @file{config.h} is included before any system headers.
+
+Support for timestamps after 2038 can be disabled by configuring with
+the @option{--disable-year2038} option. Note that this has no effect on
+systems where @code{time_t} is 64 bits or larger by default.
+If this option is @emph{not} given, and @command{configure} fails to
+find a way to enable a large @code{time_t}, but inspection of the
+system suggests that this feature is available @emph{somehow}, it will
+error out.
Regardless of whether you use this macro, portable programs should not
assume that @code{time_t} fits into @code{long int}. For example, it is
not correct to print an arbitrary @code{time_t} value @code{X} with
-@code{printf ("%ld", (long int) X)}. Also, when using this macro in
-concert with @code{AC_CONFIG_HEADERS}, be sure that @file{config.h} is
-included before any system header.
-
-@code{AC_SYS_LARGFILE} also widens @code{time_t} if possible,
-as this is needed for programs that access files with large timestamps,
-However, @code{AC_SYS_LARGEFILE} merely warns if @code{time_t} is too
-narrow and cannot be widened, rather than reporting a fatal error as
-@code{AC_SYS_YEAR2038} does. This is for portability to older
-platforms that will become obsolete in the year 2038.
+@code{printf ("%ld", (long int) X)}.
+
+@strong{Caution:} If you are developing a shared library, and
+@code{time_t} appears anywhere in your library's public interface, use
+of this macro may break binary compatibility with older executables.
+@end defmac
+
+@defmac AC_SYS_YEAR2038_REQUIRED
+@acindex{SYS_YEAR2038_REQUIRED}
+This macro has the same effect as @code{AC_SYS_YEAR2038},
+but also declares that the program being configured
+@emph{requires} support for timestamps after mid-January of 2038.
+If a large @code{time_t} is unavailable,
+@command{configure} will @emph{unconditionally} error out
+(unlike the behavior of @code{AC_SYS_YEAR2038}).
+The @option{--disable-year2038} option will not be available.
+
+@strong{Caution:} If you are developing a shared library, and
+@code{time_t} appears anywhere in your library's public interface, use
+of this macro may break binary compatibility with older executables.
@end defmac
@node C and Posix Variants
with arguments. Remove this warning when you adjust your code.])
-# _AC_SYS_YEAR2038_TEST_INCLUDES
-# ------------------------------
-AC_DEFUN([_AC_SYS_YEAR2038_TEST_INCLUDES],
+# _AC_SYS_YEAR2038_TEST_CODE
+# --------------------------
+# C code used to probe for time_t that can represent time points more
+# than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
+# these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
+# hence the name.
+AC_DEFUN([_AC_SYS_YEAR2038_TEST_CODE],
[[
#include <time.h>
/* Check that time_t can represent 2**32 - 1 correctly. */
? 1 : -1];
]])
-# _AC_SYS_YEAR2038(REQUIRE-YEAR2038-SAFE)
-# ---------------------------------------
-AC_DEFUN([_AC_SYS_YEAR2038],
-[
- AC_ARG_ENABLE([year2038],
- [ --disable-year2038 omit support for timestamps past the year 2038])
- AS_IF([test "$enable_year2038" != no],
- [
- dnl On many systems, time_t is already a 64-bit type.
- dnl On those systems where time_t is still 32-bit, it requires kernel
- dnl and libc support to make it 64-bit. For glibc 2.34 and later on Linux,
- dnl defining _TIME_BITS=64 and _FILE_OFFSET_BITS=64 is needed on x86 and ARM.
- dnl
- dnl On native Windows, the system include files define types __time32_t
- dnl and __time64_t. By default, time_t is an alias of
- dnl - __time32_t on 32-bit mingw,
- dnl - __time64_t on 64-bit mingw and on MSVC (since MSVC 8).
- dnl But when compiling with -D__MINGW_USE_VC2005_COMPAT, time_t is an
- dnl alias of __time64_t.
- dnl And when compiling with -D_USE_32BIT_TIME_T, time_t is an alias of
- dnl __time32_t.
- AC_CACHE_CHECK([for time_t past the year 2038], [ac_cv_type_time_t_y2038],
- [AC_COMPILE_IFELSE(
- [AC_LANG_SOURCE([_AC_SYS_YEAR2038_TEST_INCLUDES])],
- [ac_cv_type_time_t_y2038=yes], [ac_cv_type_time_t_y2038=no])
- ])
- if test "$ac_cv_type_time_t_y2038" = no; then
- AC_CACHE_CHECK([for 64-bit time_t with _TIME_BITS=64],
- [ac_cv_type_time_t_bits_macro],
- [AC_COMPILE_IFELSE(
- [AC_LANG_SOURCE([[#define _TIME_BITS 64
- #define _FILE_OFFSET_BITS 64
- ]_AC_SYS_YEAR2038_TEST_INCLUDES])],
- [ac_cv_type_time_t_bits_macro=yes],
- [ac_cv_type_time_t_bits_macro=no])
- ])
- if test "$ac_cv_type_time_t_bits_macro" = yes; then
- AC_DEFINE([_TIME_BITS], [64],
- [Number of bits in a timestamp, on hosts where this is settable.])
- dnl AC_SYS_LARGFILE also defines this; it's OK if we do too.
- AC_DEFINE([_FILE_OFFSET_BITS], [64],
- [Number of bits in a file offset, on hosts where this is settable.])
- ac_cv_type_time_t_y2038=yes
- fi
- fi
- if test $ac_cv_type_time_t_y2038 = no; then
- AC_COMPILE_IFELSE(
- [AC_LANG_SOURCE(
- [[#ifdef _USE_32BIT_TIME_T
- int ok;
- #else
- error fail
- #endif
- ]])],
- [AC_MSG_FAILURE(
- [The 'time_t' type stops working after January 2038.
- Remove _USE_32BIT_TIME_T from the compiler flags.])],
- [# If not cross-compiling and $1 says we should check,
- # and 'touch' works with a large timestamp, then evidently wider time_t
- # is desired and supported, so fail and ask the builder to fix the
- # problem. Otherwise, just warn the builder.
- m4_ifval([$1],
- [if test $cross_compiling = no \
- && TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null; then
- case `TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null` in
- *'Feb 7 2106'* | *'Feb 7 17:10'*)
- AC_MSG_FAILURE(
- [The 'time_t' type stops working after January 2038,
- and your system appears to support a wider 'time_t'.
- Try configuring with 'CC="${CC} -m64"'.
- To build with a 32-bit time_t anyway (not recommended),
- configure with '--disable-year2038'.]);;
- esac
- rm -f conftest.time
- fi])
- if test "$ac_warned_about_y2038" != yes; then
- AC_MSG_WARN(
- [The 'time_t' type stops working after January 2038,
- and this package needs a wider 'time_t' type
- if there is any way to access timestamps after that.
- Configure with 'CC="${CC} -m64"' perhaps?])
- ac_warned_about_y2038=yes
- fi
- ])
- fi])
+# _AC_SYS_YEAR2038_OPTIONS
+# ------------------------
+# List of known ways to enable support for large time_t. If you change
+# this list you probably also need to change the AS_CASE at the end of
+# _AC_SYS_YEAR2038_PROBE.
+m4_define([_AC_SYS_YEAR2038_OPTIONS], m4_normalize(
+ ["none needed"] dnl 64-bit and newer 32-bit Unix
+ ["-D_TIME_BITS=64"] dnl glibc 2.34 with some 32-bit ABIs
+ ["-D__MINGW_USE_VC2005_COMPAT"] dnl 32-bit MinGW
+ ["-U_USE_32_BIT_TIME_T -D__MINGW_USE_VC2005_COMPAT"]
+ dnl 32-bit MinGW (misconfiguration)
+))
+
+# _AC_SYS_YEAR2038_PROBE([IF-NOT-DETECTED])
+# -----------------------------------------
+# Subroutine of AC_SYS_YEAR2038. Probe for time_t that can represent
+# time points more than 2**31 - 1 seconds after the epoch (dates after
+# 2038-01-18, see above) and set the cache variable ac_cv_sys_year2038_opts
+# to one of the values in the _AC_SYS_YEAR2038_OPTIONS list, or to
+# "support not detected" if none of them worked. Then, set compilation
+# options and #defines as necessary to enable large time_t support.
+#
+# Note that we do not test whether mktime, localtime, etc. handle
+# large values of time_t correctly, as that would require use of
+# AC_TRY_RUN. Note also that some systems only support large time_t
+# together with large off_t.
+#
+# If support is not detected, the behavior depends on which of the
+# top-level AC_SYS_YEAR2038 macros was used (see below).
+#
+# If you change this macro you may also need to change
+# _AC_SYS_YEAR2038_OPTIONS.
+AC_DEFUN([_AC_SYS_YEAR2038_PROBE],
+[AC_CACHE_CHECK([for $CC option to enable timestamps after Jan 2038],
+ [ac_cv_sys_year2038_opts],
+ [ac_save_CPPFLAGS="$CPPFLAGS"
+ ac_opt_found=no
+ for ac_opt in _AC_SYS_YEAR2038_OPTIONS; do
+ AS_IF([test x"$ac_opt" != x"none needed"],
+ [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_YEAR2038_TEST_CODE])],
+ [ac_cv_sys_year2038_opts="$ac_opt"
+ ac_opt_found=yes])
+ test $ac_opt_found = no || break
+ done
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ test $ac_opt_found = yes || ac_cv_sys_year2038_opts="support not detected"])
+
+ac_have_year2038=yes
+AS_CASE([$ac_cv_sys_year2038_opts],
+ ["none needed"], [],
+ ["support not detected"],
+ [ac_have_year2038=no
+ AS_CASE([$enable_year2038],
+ [required],
+ [AC_MSG_FAILURE([support for timestamps after Jan 2038 is required])],
+ [yes],
+ [# If we're not cross compiling and 'touch' works with a large
+ # timestamp, then we can presume the system supports wider time_t
+ # *somehow* and we just weren't able to detect it. One common
+ # case that we deliberately *don't* probe for is a system that
+ # supports both 32- and 64-bit ABIs but only the 64-bit ABI offers
+ # wide time_t. (It would be inappropriate for us to override an
+ # intentional use of -m32.) Error out, demanding use of
+ # --disable-year2038 if this is intentional.
+ AS_IF([test $cross_compiling = no],
+ [AS_IF([TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null],
+ [AS_CASE([`TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null`],
+ [*'Feb 7 2106'* | *'Feb 7 17:10'*],
+ [AC_MSG_FAILURE(m4_text_wrap(
+ [this system appears to support timestamps after January 2038,
+ but no mechanism for enabling wide 'time_t' was detected.
+ Did you mean to build a 64-bit binary? (e.g. 'CC="${CC} -m64"'.)
+ To proceed with 32-bit time_t, configure with '--disable-year2038'.],
+ [], [], [55]))])])])])],
+
+ ["-D_TIME_BITS=64"],
+ [AC_DEFINE([_TIME_BITS], [64],
+ [Number of bits in time_t, on hosts where this is settable.])],
+
+ ["-D__MINGW_USE_VC2005_COMPAT=1"],
+ [AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
+ [Define to 1 on platforms where this makes time_t a 64-bit type.])],
+
+ ["-U_USE_32_BIT_TIME_T"*],
+ [AC_MSG_FAILURE(m4_text_wrap(
+ [the 'time_t' type is currently forced to be 32-bit.
+ It will stop working after January 2038.
+ Remove _USE_32BIT_TIME_T from the compiler flags.],
+ [], [], [55]))],
+
+ [AC_MSG_ERROR(
+ [internal error: bad value for \$ac_cv_sys_year2038_opts])])
])
+# _AC_SYS_YEAR2038_ENABLE
+# -----------------------
+# Subroutine of AC_SYS_YEAR2038 and _AC_SYS_YEAR2038_OPT_IN.
+# Depending on which of the YEAR2038 macros was used, add either an
+# --enable-year2038, or a --disable-year2038, or no option at all to
+# the configure script. Note that this is expanded very late and
+# therefore there cannot be any code in the AC_ARG_ENABLE. The
+# default value for `enable_year2038` is emitted unconditionally
+# because the generated code always looks at this variable.
+m4_define([_AC_SYS_YEAR2038_ENABLE],
+[m4_divert_text([DEFAULTS],
+ m4_provide_if([AC_SYS_YEAR2038_REQUIRED],
+ [enable_year2038=required],
+ m4_provide_if([AC_SYS_YEAR2038],
+ [enable_year2038=yes],
+ [enable_year2038=no])))]dnl
+[m4_provide_if([AC_SYS_YEAR2038_REQUIRED], [],
+[AC_ARG_ENABLE([year2038],
+ m4_provide_if([AC_SYS_YEAR2038],
+ [AS_HELP_STRING([--disable-year2038],
+ [omit support for dates after Jan 2038])],
+ [AS_HELP_STRING([--enable-year2038],
+ [include support for dates after Jan 2038])]))])])
+
+# _AC_SYS_YEAR2038_OPT_IN
+# -----------------------
+# If the --enable-year2038 option is given to configure, attempt to
+# detect and activate support for large time_t on 32-bit systems.
+# This macro is automatically invoked by AC_SYS_LARGEFILE when large
+# *file* support is detected. It does not AC_REQUIRE AC_SYS_LARGEFILE
+# to avoid a dependency loop, and is therefore unsafe to expose as a
+# documented macro.
+AC_DEFUN([_AC_SYS_YEAR2038_OPT_IN],
+[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
+ AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
+ AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
+])])
+
+# AC_SYS_YEAR2038
+# ---------------
+# Attempt to detect and activate support for large time_t.
+# On systems where time_t is not always 64 bits, this probe can be
+# skipped by passing the --disable-year2038 option to configure.
AC_DEFUN([AC_SYS_YEAR2038],
-[
- _$0([require-year2038-safe])
-])
-
-
-# _AC_SYS_LARGEFILE_TEST_INCLUDES
-# -------------------------------
-m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
+[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [],
+ [AC_REQUIRE([AC_SYS_LARGEFILE])])]dnl
+[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
+ AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
+ AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
+])])
+
+# AC_SYS_YEAR2038_REQUIRED
+# ------------------------
+# Same as AC_SYS_YEAR2038, but declares that this program *requires*
+# support for large time_t. If we cannot find any way to make time_t
+# capable of representing values larger than 2**31 - 1, configure will
+# error out. Furthermore, no --enable-year2038 nor --disable-year2038
+# option will be available.
+AC_DEFUN([AC_SYS_YEAR2038_REQUIRED],
+[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [],
+ [AC_REQUIRE([AC_SYS_LARGEFILE])])]dnl
+[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
+ _AC_SYS_YEAR2038_PROBE
+ AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
+])])
+
+# _AC_SYS_LARGEFILE_TEST_CODE
+# ---------------------------
+# C code used to probe for large file support.
+m4_define([_AC_SYS_LARGEFILE_TEST_CODE],
[@%:@include <sys/types.h>
/* Check that off_t can represent 2**63 - 1 correctly.
We can't simply define LARGE_OFF_T to be 9223372036854775807,
? 1 : -1]];[]dnl
])
+# _AC_SYS_LARGEFILE_OPTIONS
+# -------------------------
+# List of known ways to enable support for large files. If you change
+# this list you probably also need to change the AS_CASE at the end of
+# _AC_SYS_LARGEFILE_PROBE.
+m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize(
+ ["none needed"] dnl Most current systems
+ ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec
+ ["-D_LARGE_FILES=1"] dnl AIX (which versions?)
+ ["-n32"] dnl Irix 6.2 w/ SGI compiler
+))
+
+# _AC_SYS_LARGEFILE_PROBE
+# -----------------------
+# Subroutine of AC_SYS_LARGEFILE. Probe for large file support and set
+# the cache variable ac_cv_sys_largefile_opts to one of the values in
+# the _AC_SYS_LARGEFILE_OPTIONS list, or to "support not detected" if
+# none of the options in that list worked. Then, set compilation
+# options and #defines as necessary to enable large file support.
+#
+# If large file support is not detected, the behavior depends on which of
+# the top-level AC_SYS_LARGEFILE macros was used (see below).
+#
+# If you change this macro you may also need to change
+# _AC_SYS_LARGEFILE_OPTIONS.
+AC_DEFUN([_AC_SYS_LARGEFILE_PROBE],
+[AC_CACHE_CHECK([for $CC option to enable large file support],
+ [ac_cv_sys_largefile_opts],
+ [ac_save_CC="$CC"
+ ac_opt_found=no
+ for ac_opt in _AC_SYS_LARGEFILE_OPTIONS; do
+ AS_IF([test x"$ac_opt" != x"none needed"],
+ [CC="$ac_save_CC $ac_opt"])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_CODE])],
+ [ac_cv_sys_largefile_opts="$ac_opt"
+ ac_opt_found=yes])
+ test $ac_opt_found = no || break
+ done
+ CC="$ac_save_CC"
+ test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected"])
+
+ac_have_largefile=yes
+AS_CASE([$ac_cv_sys_largefile_opts],
+ ["none needed"], [],
+ ["support not detected"],
+ [ac_have_largefile=no
+ AS_IF([test $enable_largefile = required],
+ [AC_MSG_FAILURE([support for large files is required])])],
+
+ ["-D_FILE_OFFSET_BITS=64"],
+ [AC_DEFINE([_FILE_OFFSET_BITS], [64],
+ [Number of bits in a file offset, on hosts where this is settable.])],
+
+ ["-D_LARGE_FILES=1"],
+ [AC_DEFINE([_LARGE_FILES], [1],
+ [Define to 1 on platforms where this makes off_t a 64-bit type.])],
+
+ ["-n32"],
+ [CC="$CC -n32"],
+
+ [AC_MSG_ERROR(
+ [internal error: bad value for \$ac_cv_sys_largefile_opts])])
+
+_AC_SYS_YEAR2038_OPT_IN
+])
-# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
-# CACHE-VAR,
-# DESCRIPTION,
-# PROLOGUE, [FUNCTION-BODY])
-# --------------------------------------------------------
-m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
-[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
-[while :; do
- m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
- [AC_LANG_PROGRAM([$5], [$6])],
- [$3=no; break])
- m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
- [AC_LANG_PROGRAM([#undef $1
-#define $1 $2
-$5], [$6])],
- [$3=$2; break])
- $3=unknown
- break
-done])
-case $$3 in #(
- no | unknown) ;;
- *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
-esac
-rm -rf conftest*[]dnl
-])# _AC_SYS_LARGEFILE_MACRO_VALUE
-
+# _AC_SYS_LARGEFILE_ENABLE
+# ------------------------
+# Subroutine of AC_SYS_LARGEFILE. If AC_SYS_LARGEFILE_REQUIRED was
+# not used at any point in this configure script, add a
+# --disable-largefile option to the configure script. Note that this
+# is expanded very late and therefore there cannot be any code in the
+# AC_ARG_ENABLE. The default value for `enable_largefile` is emitted
+# unconditionally because the generated shell code always looks at
+# this variable.
+m4_define([_AC_SYS_LARGEFILE_ENABLE],
+[m4_divert_text([DEFAULTS],
+ m4_provide_if([AC_SYS_LARGEFILE_REQUIRED],
+ [enable_largefile=required],
+ [enable_largefile=yes]))]dnl
+[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [],
+[AC_ARG_ENABLE([largefile],
+ [AS_HELP_STRING([--disable-largefile], [omit support for large files])])])])
# AC_SYS_LARGEFILE
# ----------------
# Additionally, on Linux file systems with 64-bit inodes a file that happens
# to have a 64-bit inode number cannot be accessed by 32-bit applications on
# Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
+# This macro allows configuration to continue if the system doesn't support
+# large files; see also AC_SYS_LARGEFILE_REQUIRED.
AC_DEFUN([AC_SYS_LARGEFILE],
-[AC_ARG_ENABLE(largefile,
- [ --disable-largefile omit support for large files])
-AS_IF([test "$enable_largefile" != no],
- [AC_CACHE_CHECK([for special C compiler options needed for large files],
- ac_cv_sys_largefile_CC,
- [ac_cv_sys_largefile_CC=no
- if test "$GCC" != yes; then
- ac_save_CC=$CC
- while :; do
- # IRIX 6.2 and later do not support large files by default,
- # so use the C compiler's -n32 option if that helps.
- AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
- AC_COMPILE_IFELSE([], [break])
- CC="$CC -n32"
- AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
- break
- done
- CC=$ac_save_CC
- rm -f conftest.$ac_ext
- fi])
- if test "$ac_cv_sys_largefile_CC" != no; then
- CC=$CC$ac_cv_sys_largefile_CC
- fi
-
- _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
- ac_cv_sys_file_offset_bits,
- [Number of bits in a file offset, on hosts where this is settable.],
- [_AC_SYS_LARGEFILE_TEST_INCLUDES])
- AS_CASE([$ac_cv_sys_file_offset_bits],
- [unknown],
- [_AC_SYS_LARGEFILE_MACRO_VALUE([_LARGE_FILES], [1],
- [ac_cv_sys_large_files],
- [Define for large files, on AIX-style hosts.],
- [_AC_SYS_LARGEFILE_TEST_INCLUDES])],
- [64],
- [_AC_SYS_YEAR2038()])])
-
- AH_VERBATIM([__MINGW_USE_VC2005_COMPAT],
-[#if !defined __MINGW_USE_VC2005_COMPAT && defined __MINGW32__
-# define __MINGW_USE_VC2005_COMPAT 1 /* For 64-bit time_t. */
-#endif])
-])# AC_SYS_LARGEFILE
-
+[m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl
+ AS_IF([test "$enable_largefile" != no], [_AC_SYS_LARGEFILE_PROBE])
+ AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE])
+])])
+
+# AC_SYS_LARGEFILE_REQUIRED
+# -------------------------
+# Same as AC_SYS_LARGEFILE, but declares that this program *requires*
+# support for large files. If we cannot find a combination of compiler
+# options and #defines that makes `off_t` capable of representing 2**63 - 1,
+# `configure` will error out. Furthermore, `configure` will not offer a
+# --disable-largefile command line option.
+# If both AC_SYS_LARGEFILE and AC_SYS_LARGEFILE_REQUIRED are used in the
+# same configure script -- in either order -- AC_SYS_LARGEFILE_REQUIRED wins.
+AC_DEFUN([AC_SYS_LARGEFILE_REQUIRED],
+[m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl
+ _AC_SYS_LARGEFILE_PROBE
+ AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE])
+])])
# AC_SYS_LONG_FILE_NAMES
# ----------------------