time_h.m4 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Configure a more-standard replacement for <time.h>.
  2. # Copyright (C) 2000-2001, 2003-2007, 2009-2017 Free Software Foundation, Inc.
  3. # serial 9
  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([AC_C_RESTRICT])
  17. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  18. gl_NEXT_HEADERS([time.h])
  19. AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
  20. ])
  21. dnl Check whether 'struct timespec' is declared
  22. dnl in time.h, sys/time.h, pthread.h, or unistd.h.
  23. AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
  24. [
  25. AC_CHECK_HEADERS_ONCE([sys/time.h])
  26. AC_CACHE_CHECK([for struct timespec in <time.h>],
  27. [gl_cv_sys_struct_timespec_in_time_h],
  28. [AC_COMPILE_IFELSE(
  29. [AC_LANG_PROGRAM(
  30. [[#include <time.h>
  31. ]],
  32. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  33. [gl_cv_sys_struct_timespec_in_time_h=yes],
  34. [gl_cv_sys_struct_timespec_in_time_h=no])])
  35. TIME_H_DEFINES_STRUCT_TIMESPEC=0
  36. SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
  37. PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
  38. UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
  39. if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
  40. TIME_H_DEFINES_STRUCT_TIMESPEC=1
  41. else
  42. AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
  43. [gl_cv_sys_struct_timespec_in_sys_time_h],
  44. [AC_COMPILE_IFELSE(
  45. [AC_LANG_PROGRAM(
  46. [[#include <sys/time.h>
  47. ]],
  48. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  49. [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
  50. [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
  51. if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
  52. SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
  53. else
  54. AC_CACHE_CHECK([for struct timespec in <pthread.h>],
  55. [gl_cv_sys_struct_timespec_in_pthread_h],
  56. [AC_COMPILE_IFELSE(
  57. [AC_LANG_PROGRAM(
  58. [[#include <pthread.h>
  59. ]],
  60. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  61. [gl_cv_sys_struct_timespec_in_pthread_h=yes],
  62. [gl_cv_sys_struct_timespec_in_pthread_h=no])])
  63. if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
  64. PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
  65. else
  66. AC_CACHE_CHECK([for struct timespec in <unistd.h>],
  67. [gl_cv_sys_struct_timespec_in_unistd_h],
  68. [AC_COMPILE_IFELSE(
  69. [AC_LANG_PROGRAM(
  70. [[#include <unistd.h>
  71. ]],
  72. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  73. [gl_cv_sys_struct_timespec_in_unistd_h=yes],
  74. [gl_cv_sys_struct_timespec_in_unistd_h=no])])
  75. if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
  76. UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
  77. fi
  78. fi
  79. fi
  80. fi
  81. AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
  82. AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
  83. AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
  84. AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
  85. ])
  86. AC_DEFUN([gl_TIME_MODULE_INDICATOR],
  87. [
  88. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  89. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  90. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  91. dnl Define it also as a C macro, for the benefit of the unit tests.
  92. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  93. ])
  94. AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
  95. [
  96. GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
  97. GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
  98. GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
  99. GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
  100. GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
  101. GNULIB_TIME_RZ=0; AC_SUBST([GNULIB_TIME_RZ])
  102. dnl Assume proper GNU behavior unless another module says otherwise.
  103. HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
  104. HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
  105. HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
  106. HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
  107. dnl If another module says to replace or to not replace, do that.
  108. dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
  109. dnl this lets maintainers check for portability.
  110. REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
  111. REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
  112. REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
  113. REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
  114. dnl Hack so that the time module doesn't depend on the sys_time module.
  115. dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
  116. : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY])
  117. dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
  118. dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
  119. dnl is no longer a big deal.
  120. REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
  121. REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])
  122. ])