New upstream version 1.9
[debian/gzip] / m4 / year2038.m4
1 # year2038.m4 serial 3
2 dnl Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl Attempt to ensure that 'time_t' is a 64-bit type
8 dnl and that the functions time(), stat(), etc. return 64-bit times.
9
10 AC_DEFUN([gl_YEAR2038_EARLY],
11 [
12   AC_REQUIRE([AC_CANONICAL_HOST])
13   case "$host_os" in
14     mingw*)
15       AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
16         [For 64-bit time_t on 32-bit mingw.])
17       ;;
18   esac
19 ])
20
21 AC_DEFUN([gl_YEAR2038],
22 [
23   dnl On many systems, time_t is already a 64-bit type.
24   dnl On those systems where time_t is still 32-bit, it requires kernel
25   dnl and libc support to make it 64-bit. For glibc on Linux/x86, this
26   dnl is work in progress; see
27   dnl <https://sourceware.org/glibc/wiki/Y2038ProofnessDesign>.
28   dnl
29   dnl On native Windows, the system include files define types __time32_t
30   dnl and __time64_t. By default, time_t is an alias of
31   dnl   - __time32_t on 32-bit mingw,
32   dnl   - __time64_t on 64-bit mingw and on MSVC (since MSVC 8).
33   dnl But when compiling with -D__MINGW_USE_VC2005_COMPAT, time_t is an
34   dnl alias of __time64_t.
35   dnl And when compiling with -D_USE_32BIT_TIME_T, time_t is an alias of
36   dnl __time32_t.
37   AC_CACHE_CHECK([for 64-bit time_t], [gl_cv_type_time_t_64],
38     [AC_COMPILE_IFELSE(
39        [AC_LANG_PROGRAM(
40           [[#include <time.h>
41             int verify_time_t_size[sizeof (time_t) >= 8 ? 1 : -1];
42           ]],
43           [[]])],
44        [gl_cv_type_time_t_64=yes], [gl_cv_type_time_t_64=no])
45     ])
46   if test $gl_cv_type_time_t_64 = no; then
47     AC_COMPILE_IFELSE(
48       [AC_LANG_SOURCE(
49          [[#ifdef _USE_32BIT_TIME_T
50              int ok;
51            #else
52              error fail
53            #endif
54          ]])],
55       [AC_MSG_FAILURE([This package requires a 64-bit 'time_t' type. Remove _USE_32BIT_TIME_T from the compiler flags.])],
56       [# If TIME_T_32_BIT_OK is "no" (the default) and not cross-compiling
57        # and 'touch' works with a large timestamp, then evidently 64-bit time_t
58        # is desired and supported, so fail and ask the builder to fix the
59        # problem.  Otherwise, just warn the builder.
60        if test "${TIME_T_32_BIT_OK-no}" = no \
61           && test $cross_compiling = no \
62           && TZ=UTC0 touch -t 210602070628.16 conftest.time 2>/dev/null; then
63          rm -f conftest.time
64          AC_MSG_FAILURE([This package requires a 64-bit 'time_t' type, which your system appears to support. You might try configuring with 'CPPFLAGS="-m64" LDFLAGS="-m64"'. To build with a 32-bit time_t anyway (not recommended), configure with 'TIME_T_32_BIT_OK=yes'.])
65        else
66          AC_MSG_WARN([This package requires a 64-bit 'time_t' type if there is any way to access timestamps outside the year range 1901-2038 on your platform. Perhaps you should configure with 'CPPFLAGS="-m64" LDFLAGS="-m64"'?])
67        fi
68       ])
69   fi
70 ])