1# Configure a more-standard replacement for <time.h>. 2 3# Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc. 4 5# serial 18 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 13AC_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 41dnl Check whether 'struct timespec' is declared 42dnl in time.h, sys/time.h, pthread.h, or unistd.h. 43 44AC_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. 113AC_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. 125AC_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_TIME_R]) 137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ]) 138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET]) 139 dnl Support Microsoft deprecated alias function names by default. 140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1]) 141 ]) 142 m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS]) 143 AC_REQUIRE([gl_TIME_H_DEFAULTS]) 144]) 145 146AC_DEFUN([gl_TIME_H_DEFAULTS], 147[ 148 dnl Assume proper GNU behavior unless another module says otherwise. 149 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) 150 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) 151 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) 152 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) 153 HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET]) 154 dnl Even GNU libc does not have timezone_t yet. 155 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T]) 156 dnl If another module says to replace or to not replace, do that. 157 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; 158 dnl this lets maintainers check for portability. 159 REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME]) 160 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) 161 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) 162 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) 163 REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME]) 164 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) 165 REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET]) 166 167 dnl Hack so that the time module doesn't depend on the sys_time module. 168 dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent. 169 : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY]) 170 dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME 171 dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier 172 dnl is no longer a big deal. 173 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME]) 174 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME]) 175]) 176