; * lisp/ldefs-boot.el: Update.
[emacs.git] / m4 / time_h.m4
blob1e2990fc187caf3ac1ce38e0bbf36ddc29e98562
1 # Configure a more-standard replacement for <time.h>.
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2019 Free Software
4 # Foundation, Inc.
6 # serial 11
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 # Written by Paul Eggert and Jim Meyering.
14 AC_DEFUN([gl_HEADER_TIME_H],
16   dnl Use AC_REQUIRE here, so that the default behavior below is expanded
17   dnl once only, before all statements that occur in other macros.
18   AC_REQUIRE([gl_HEADER_TIME_H_BODY])
21 AC_DEFUN([gl_HEADER_TIME_H_BODY],
23   AC_REQUIRE([AC_C_RESTRICT])
24   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
25   gl_NEXT_HEADERS([time.h])
26   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
29 dnl Check whether 'struct timespec' is declared
30 dnl in time.h, sys/time.h, pthread.h, or unistd.h.
32 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
34   AC_CHECK_HEADERS_ONCE([sys/time.h])
35   AC_CACHE_CHECK([for struct timespec in <time.h>],
36     [gl_cv_sys_struct_timespec_in_time_h],
37     [AC_COMPILE_IFELSE(
38        [AC_LANG_PROGRAM(
39           [[#include <time.h>
40           ]],
41           [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
42        [gl_cv_sys_struct_timespec_in_time_h=yes],
43        [gl_cv_sys_struct_timespec_in_time_h=no])])
45   TIME_H_DEFINES_STRUCT_TIMESPEC=0
46   SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
47   PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
48   UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
49   if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
50     TIME_H_DEFINES_STRUCT_TIMESPEC=1
51   else
52     AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
53       [gl_cv_sys_struct_timespec_in_sys_time_h],
54       [AC_COMPILE_IFELSE(
55          [AC_LANG_PROGRAM(
56             [[#include <sys/time.h>
57             ]],
58             [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
59          [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
60          [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
61     if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
62       SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
63     else
64       AC_CACHE_CHECK([for struct timespec in <pthread.h>],
65         [gl_cv_sys_struct_timespec_in_pthread_h],
66         [AC_COMPILE_IFELSE(
67            [AC_LANG_PROGRAM(
68               [[#include <pthread.h>
69               ]],
70               [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
71            [gl_cv_sys_struct_timespec_in_pthread_h=yes],
72            [gl_cv_sys_struct_timespec_in_pthread_h=no])])
73       if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
74         PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
75       else
76         AC_CACHE_CHECK([for struct timespec in <unistd.h>],
77           [gl_cv_sys_struct_timespec_in_unistd_h],
78           [AC_COMPILE_IFELSE(
79              [AC_LANG_PROGRAM(
80                 [[#include <unistd.h>
81                 ]],
82                 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
83              [gl_cv_sys_struct_timespec_in_unistd_h=yes],
84              [gl_cv_sys_struct_timespec_in_unistd_h=no])])
85         if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
86           UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
87         fi
88       fi
89     fi
90   fi
91   AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
92   AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
93   AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
94   AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
97 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
99   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
100   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
101   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
102   dnl Define it also as a C macro, for the benefit of the unit tests.
103   gl_MODULE_INDICATOR_FOR_TESTS([$1])
106 AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
108   GNULIB_CTIME=0;                        AC_SUBST([GNULIB_CTIME])
109   GNULIB_MKTIME=0;                       AC_SUBST([GNULIB_MKTIME])
110   GNULIB_LOCALTIME=0;                    AC_SUBST([GNULIB_LOCALTIME])
111   GNULIB_NANOSLEEP=0;                    AC_SUBST([GNULIB_NANOSLEEP])
112   GNULIB_STRFTIME=0;                     AC_SUBST([GNULIB_STRFTIME])
113   GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
114   GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
115   GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
116   GNULIB_TIME_RZ=0;                      AC_SUBST([GNULIB_TIME_RZ])
117   GNULIB_TZSET=0;                        AC_SUBST([GNULIB_TZSET])
118   dnl Assume proper GNU behavior unless another module says otherwise.
119   HAVE_DECL_LOCALTIME_R=1;               AC_SUBST([HAVE_DECL_LOCALTIME_R])
120   HAVE_NANOSLEEP=1;                      AC_SUBST([HAVE_NANOSLEEP])
121   HAVE_STRPTIME=1;                       AC_SUBST([HAVE_STRPTIME])
122   HAVE_TIMEGM=1;                         AC_SUBST([HAVE_TIMEGM])
123   HAVE_TZSET=1;                          AC_SUBST([HAVE_TZSET])
124   dnl Even GNU libc does not have timezone_t yet.
125   HAVE_TIMEZONE_T=0;                     AC_SUBST([HAVE_TIMEZONE_T])
126   dnl If another module says to replace or to not replace, do that.
127   dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
128   dnl this lets maintainers check for portability.
129   REPLACE_CTIME=GNULIB_PORTCHECK;        AC_SUBST([REPLACE_CTIME])
130   REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
131   REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
132   REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
133   REPLACE_STRFTIME=GNULIB_PORTCHECK;     AC_SUBST([REPLACE_STRFTIME])
134   REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
135   REPLACE_TZSET=GNULIB_PORTCHECK;        AC_SUBST([REPLACE_TZSET])
137   dnl Hack so that the time module doesn't depend on the sys_time module.
138   dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
139   : ${GNULIB_GETTIMEOFDAY=0};            AC_SUBST([GNULIB_GETTIMEOFDAY])
140   dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
141   dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
142   dnl is no longer a big deal.
143   REPLACE_GMTIME=0;                      AC_SUBST([REPLACE_GMTIME])
144   REPLACE_LOCALTIME=0;                   AC_SUBST([REPLACE_LOCALTIME])