sys_time_h.m4 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Configure a replacement for <sys/time.h>.
  2. # serial 6
  3. # Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
  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 Martin Lambers.
  8. AC_DEFUN([gl_HEADER_SYS_TIME_H],
  9. [
  10. dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
  11. dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
  12. dnl statements that occur in other macros.
  13. AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
  14. ])
  15. AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
  16. [
  17. AC_REQUIRE([AC_C_RESTRICT])
  18. AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
  19. AC_CHECK_HEADERS_ONCE([sys/time.h])
  20. gl_CHECK_NEXT_HEADERS([sys/time.h])
  21. if test $ac_cv_header_sys_time_h != yes; then
  22. HAVE_SYS_TIME_H=0
  23. fi
  24. AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
  25. [AC_COMPILE_IFELSE(
  26. [AC_LANG_PROGRAM(
  27. [[#if HAVE_SYS_TIME_H
  28. #include <sys/time.h>
  29. #endif
  30. #include <time.h>
  31. ]],
  32. [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
  33. [gl_cv_sys_struct_timeval=yes],
  34. [gl_cv_sys_struct_timeval=no])])
  35. if test $gl_cv_sys_struct_timeval != yes; then
  36. HAVE_STRUCT_TIMEVAL=0
  37. fi
  38. dnl Check for declarations of anything we want to poison if the
  39. dnl corresponding gnulib module is not in use.
  40. gl_WARN_ON_USE_PREPARE([[
  41. #if HAVE_SYS_TIME_H
  42. # include <sys/time.h>
  43. #endif
  44. #include <time.h>
  45. ]], [gettimeofday])
  46. ])
  47. AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
  48. [
  49. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  50. AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
  51. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  52. dnl Define it also as a C macro, for the benefit of the unit tests.
  53. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  54. ])
  55. AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
  56. [
  57. GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY])
  58. dnl Assume POSIX behavior unless another module says otherwise.
  59. HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY])
  60. HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
  61. HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
  62. REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
  63. ])