sys_time_h.m4 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Configure a replacement for <sys/time.h>.
  2. # serial 7
  3. # Copyright (C) 2007, 2009-2012 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. dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
  25. dnl only. So include that header in the list.
  26. gl_PREREQ_SYS_H_WINSOCK2
  27. AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
  28. [AC_COMPILE_IFELSE(
  29. [AC_LANG_PROGRAM(
  30. [[#if HAVE_SYS_TIME_H
  31. #include <sys/time.h>
  32. #endif
  33. #include <time.h>
  34. #if HAVE_WINSOCK2_H
  35. # include <winsock2.h>
  36. #endif
  37. ]],
  38. [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
  39. [gl_cv_sys_struct_timeval=yes],
  40. [gl_cv_sys_struct_timeval=no])])
  41. if test $gl_cv_sys_struct_timeval != yes; then
  42. HAVE_STRUCT_TIMEVAL=0
  43. fi
  44. dnl Check for declarations of anything we want to poison if the
  45. dnl corresponding gnulib module is not in use.
  46. gl_WARN_ON_USE_PREPARE([[
  47. #if HAVE_SYS_TIME_H
  48. # include <sys/time.h>
  49. #endif
  50. #include <time.h>
  51. ]], [gettimeofday])
  52. ])
  53. AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
  54. [
  55. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  56. AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
  57. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  58. dnl Define it also as a C macro, for the benefit of the unit tests.
  59. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  60. ])
  61. AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
  62. [
  63. GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY])
  64. dnl Assume POSIX behavior unless another module says otherwise.
  65. HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY])
  66. HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
  67. HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
  68. REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
  69. ])