time_h.m4 7.3 KB

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