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