| 1 |
# Configure a more-standard replacement for <time.h>. |
| 2 |
|
| 3 |
# Copyright (C) 2000-2001, 2003-2007, 2009-2022 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
# serial 19 |
| 6 |
|
| 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. |
| 10 |
|
| 11 |
# Written by Paul Eggert and Jim Meyering. |
| 12 |
|
| 13 |
AC_DEFUN_ONCE([gl_TIME_H], |
| 14 |
[ |
| 15 |
dnl Ensure to expand the default settings once only, before all statements |
| 16 |
dnl that occur in other macros. |
| 17 |
AC_REQUIRE([gl_TIME_H_DEFAULTS]) |
| 18 |
|
| 19 |
gl_NEXT_HEADERS([time.h]) |
| 20 |
AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) |
| 21 |
|
| 22 |
AC_REQUIRE([AC_C_RESTRICT]) |
| 23 |
|
| 24 |
AC_CACHE_CHECK([for TIME_UTC in <time.h>], |
| 25 |
[gl_cv_time_h_has_TIME_UTC], |
| 26 |
[AC_COMPILE_IFELSE( |
| 27 |
[AC_LANG_PROGRAM( |
| 28 |
[[#include <time.h> |
| 29 |
]], |
| 30 |
[[static int x = TIME_UTC; x++;]])], |
| 31 |
[gl_cv_time_h_has_TIME_UTC=yes], |
| 32 |
[gl_cv_time_h_has_TIME_UTC=no])]) |
| 33 |
if test $gl_cv_time_h_has_TIME_UTC = yes; then |
| 34 |
TIME_H_DEFINES_TIME_UTC=1 |
| 35 |
else |
| 36 |
TIME_H_DEFINES_TIME_UTC=0 |
| 37 |
fi |
| 38 |
AC_SUBST([TIME_H_DEFINES_TIME_UTC]) |
| 39 |
]) |
| 40 |
|
| 41 |
dnl Check whether 'struct timespec' is declared |
| 42 |
dnl in time.h, sys/time.h, pthread.h, or unistd.h. |
| 43 |
|
| 44 |
AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], |
| 45 |
[ |
| 46 |
AC_CHECK_HEADERS_ONCE([sys/time.h]) |
| 47 |
AC_CACHE_CHECK([for struct timespec in <time.h>], |
| 48 |
[gl_cv_sys_struct_timespec_in_time_h], |
| 49 |
[AC_COMPILE_IFELSE( |
| 50 |
[AC_LANG_PROGRAM( |
| 51 |
[[#include <time.h> |
| 52 |
]], |
| 53 |
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])], |
| 54 |
[gl_cv_sys_struct_timespec_in_time_h=yes], |
| 55 |
[gl_cv_sys_struct_timespec_in_time_h=no])]) |
| 56 |
|
| 57 |
TIME_H_DEFINES_STRUCT_TIMESPEC=0 |
| 58 |
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 |
| 59 |
PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 |
| 60 |
UNISTD_H_DEFINES_STRUCT_TIMESPEC=0 |
| 61 |
if test $gl_cv_sys_struct_timespec_in_time_h = yes; then |
| 62 |
TIME_H_DEFINES_STRUCT_TIMESPEC=1 |
| 63 |
else |
| 64 |
AC_CACHE_CHECK([for struct timespec in <sys/time.h>], |
| 65 |
[gl_cv_sys_struct_timespec_in_sys_time_h], |
| 66 |
[AC_COMPILE_IFELSE( |
| 67 |
[AC_LANG_PROGRAM( |
| 68 |
[[#include <sys/time.h> |
| 69 |
]], |
| 70 |
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])], |
| 71 |
[gl_cv_sys_struct_timespec_in_sys_time_h=yes], |
| 72 |
[gl_cv_sys_struct_timespec_in_sys_time_h=no])]) |
| 73 |
if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then |
| 74 |
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 |
| 75 |
else |
| 76 |
AC_CACHE_CHECK([for struct timespec in <pthread.h>], |
| 77 |
[gl_cv_sys_struct_timespec_in_pthread_h], |
| 78 |
[AC_COMPILE_IFELSE( |
| 79 |
[AC_LANG_PROGRAM( |
| 80 |
[[#include <pthread.h> |
| 81 |
]], |
| 82 |
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])], |
| 83 |
[gl_cv_sys_struct_timespec_in_pthread_h=yes], |
| 84 |
[gl_cv_sys_struct_timespec_in_pthread_h=no])]) |
| 85 |
if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then |
| 86 |
PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 |
| 87 |
else |
| 88 |
AC_CACHE_CHECK([for struct timespec in <unistd.h>], |
| 89 |
[gl_cv_sys_struct_timespec_in_unistd_h], |
| 90 |
[AC_COMPILE_IFELSE( |
| 91 |
[AC_LANG_PROGRAM( |
| 92 |
[[#include <unistd.h> |
| 93 |
]], |
| 94 |
[[static struct timespec x; x.tv_sec = x.tv_nsec;]])], |
| 95 |
[gl_cv_sys_struct_timespec_in_unistd_h=yes], |
| 96 |
[gl_cv_sys_struct_timespec_in_unistd_h=no])]) |
| 97 |
if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then |
| 98 |
UNISTD_H_DEFINES_STRUCT_TIMESPEC=1 |
| 99 |
fi |
| 100 |
fi |
| 101 |
fi |
| 102 |
fi |
| 103 |
AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) |
| 104 |
AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) |
| 105 |
AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) |
| 106 |
AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC]) |
| 107 |
]) |
| 108 |
|
| 109 |
# gl_TIME_MODULE_INDICATOR([modulename]) |
| 110 |
# sets the shell variable that indicates the presence of the given module |
| 111 |
# to a C preprocessor expression that will evaluate to 1. |
| 112 |
# This macro invocation must not occur in macros that are AC_REQUIREd. |
| 113 |
AC_DEFUN([gl_TIME_MODULE_INDICATOR], |
| 114 |
[ |
| 115 |
dnl Ensure to expand the default settings once only. |
| 116 |
gl_TIME_H_REQUIRE_DEFAULTS |
| 117 |
gl_MODULE_INDICATOR_SET_VARIABLE([$1]) |
| 118 |
dnl Define it also as a C macro, for the benefit of the unit tests. |
| 119 |
gl_MODULE_INDICATOR_FOR_TESTS([$1]) |
| 120 |
]) |
| 121 |
|
| 122 |
# Initializes the default values for AC_SUBSTed shell variables. |
| 123 |
# This macro must not be AC_REQUIREd. It must only be invoked, and only |
| 124 |
# outside of macros or in macros that are not AC_REQUIREd. |
| 125 |
AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS], |
| 126 |
[ |
| 127 |
m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [ |
| 128 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME]) |
| 129 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME]) |
| 130 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME]) |
| 131 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP]) |
| 132 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME]) |
| 133 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME]) |
| 134 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM]) |
| 135 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET]) |
| 136 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES]) |
| 137 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R]) |
| 138 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ]) |
| 139 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET]) |
| 140 |
dnl Support Microsoft deprecated alias function names by default. |
| 141 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1]) |
| 142 |
]) |
| 143 |
m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS]) |
| 144 |
AC_REQUIRE([gl_TIME_H_DEFAULTS]) |
| 145 |
]) |
| 146 |
|
| 147 |
AC_DEFUN([gl_TIME_H_DEFAULTS], |
| 148 |
[ |
| 149 |
dnl Assume proper GNU behavior unless another module says otherwise. |
| 150 |
HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) |
| 151 |
HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) |
| 152 |
HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) |
| 153 |
HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) |
| 154 |
HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET]) |
| 155 |
HAVE_TIMESPEC_GETRES=1; AC_SUBST([HAVE_TIMESPEC_GETRES]) |
| 156 |
dnl Even GNU libc does not have timezone_t yet. |
| 157 |
HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T]) |
| 158 |
dnl If another module says to replace or to not replace, do that. |
| 159 |
dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; |
| 160 |
dnl this lets maintainers check for portability. |
| 161 |
REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME]) |
| 162 |
REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) |
| 163 |
REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) |
| 164 |
REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) |
| 165 |
REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME]) |
| 166 |
REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) |
| 167 |
REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET]) |
| 168 |
|
| 169 |
dnl Hack so that the time module doesn't depend on the sys_time module. |
| 170 |
dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent. |
| 171 |
: ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY]) |
| 172 |
dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME |
| 173 |
dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier |
| 174 |
dnl is no longer a big deal. |
| 175 |
REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME]) |
| 176 |
REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME]) |
| 177 |
]) |