time_h.m4 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Configure a more-standard replacement for <time.h>.
  2. # Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc.
  3. # This file is free software; the Free Software Foundation
  4. # gives unlimited permission to copy and/or distribute it,
  5. # with or without modifications, as long as this notice is preserved.
  6. # Written by Paul Eggert and Jim Meyering.
  7. AC_DEFUN([gl_HEADER_TIME_H],
  8. [
  9. dnl Use AC_REQUIRE here, so that the default behavior below is expanded
  10. dnl once only, before all statements that occur in other macros.
  11. AC_REQUIRE([gl_HEADER_TIME_H_BODY])
  12. ])
  13. AC_DEFUN([gl_HEADER_TIME_H_BODY],
  14. [
  15. AC_REQUIRE([AC_C_RESTRICT])
  16. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  17. gl_CHECK_NEXT_HEADERS([time.h])
  18. AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
  19. ])
  20. dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
  21. dnl in time.h or sys/time.h.
  22. AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
  23. [
  24. AC_CHECK_HEADERS_ONCE([sys/time.h])
  25. AC_CACHE_CHECK([for struct timespec in <time.h>],
  26. [gl_cv_sys_struct_timespec_in_time_h],
  27. [AC_COMPILE_IFELSE(
  28. [AC_LANG_PROGRAM(
  29. [[#include <time.h>
  30. ]],
  31. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  32. [gl_cv_sys_struct_timespec_in_time_h=yes],
  33. [gl_cv_sys_struct_timespec_in_time_h=no])])
  34. TIME_H_DEFINES_STRUCT_TIMESPEC=0
  35. SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
  36. if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
  37. TIME_H_DEFINES_STRUCT_TIMESPEC=1
  38. else
  39. AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
  40. [gl_cv_sys_struct_timespec_in_sys_time_h],
  41. [AC_COMPILE_IFELSE(
  42. [AC_LANG_PROGRAM(
  43. [[#include <sys/time.h>
  44. ]],
  45. [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
  46. [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
  47. [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
  48. if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
  49. SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
  50. fi
  51. fi
  52. AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
  53. AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
  54. ])
  55. AC_DEFUN([gl_TIME_MODULE_INDICATOR],
  56. [
  57. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  58. AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
  59. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  60. dnl Define it also as a C macro, for the benefit of the unit tests.
  61. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  62. ])
  63. AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
  64. [
  65. GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
  66. GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
  67. GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
  68. GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
  69. GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
  70. dnl Assume proper GNU behavior unless another module says otherwise.
  71. HAVE_LOCALTIME_R=1; AC_SUBST([HAVE_LOCALTIME_R])
  72. HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
  73. HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
  74. HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
  75. dnl If another module says to replace or to not replace, do that.
  76. dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
  77. dnl this lets maintainers check for portability.
  78. REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
  79. REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
  80. REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
  81. REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
  82. ])