time_h.m4 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Configure a more-standard replacement for <time.h>.
  2. # Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
  3. # serial 6
  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 Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
  22. dnl in time.h, sys/time.h, or pthread.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. if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
  39. TIME_H_DEFINES_STRUCT_TIMESPEC=1
  40. else
  41. AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
  42. [gl_cv_sys_struct_timespec_in_sys_time_h],
  43. [AC_COMPILE_IFELSE(
  44. [AC_LANG_PROGRAM(
  45. [[#include <sys/time.h>
  46. ]],
  47. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  48. [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
  49. [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
  50. if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
  51. SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
  52. else
  53. AC_CACHE_CHECK([for struct timespec in <pthread.h>],
  54. [gl_cv_sys_struct_timespec_in_pthread_h],
  55. [AC_COMPILE_IFELSE(
  56. [AC_LANG_PROGRAM(
  57. [[#include <pthread.h>
  58. ]],
  59. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  60. [gl_cv_sys_struct_timespec_in_pthread_h=yes],
  61. [gl_cv_sys_struct_timespec_in_pthread_h=no])])
  62. if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
  63. PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
  64. fi
  65. fi
  66. fi
  67. AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
  68. AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
  69. AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
  70. ])
  71. AC_DEFUN([gl_TIME_MODULE_INDICATOR],
  72. [
  73. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  74. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  75. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  76. dnl Define it also as a C macro, for the benefit of the unit tests.
  77. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  78. ])
  79. AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
  80. [
  81. GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
  82. GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
  83. GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
  84. GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
  85. GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
  86. dnl Assume proper GNU behavior unless another module says otherwise.
  87. HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
  88. HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
  89. HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
  90. HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
  91. dnl If another module says to replace or to not replace, do that.
  92. dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
  93. dnl this lets maintainers check for portability.
  94. REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
  95. REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
  96. REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
  97. REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
  98. ])