time_h.m4 6.6 KB

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