librt_timers.m4 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # HW_HEADER_TIME_H
  2. # ------------------
  3. # Define HAVE_TIME_H to 1 if <time.h> is available.
  4. AC_DEFUN([HW_HEADER_TIME_H],
  5. [
  6. AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used.
  7. AC_CHECK_HEADERS_ONCE([time.h])
  8. ])# HW_HEADER_TIME_H
  9. # HW_LIBRT_TIMERS
  10. # -----------------
  11. # Set $hw_cv_librt_timers and $hw_cv_librt_timers_posix to "yes" or "no",
  12. # respectively. If the timer_create() function is available and
  13. # POSIX compliant, then the system's timer_create(), timer_settime(),
  14. # and timer_delete() functions are used. Otherwise, make sure
  15. # the replacement functions will be built.
  16. #
  17. # In the case where we are cross compiling, the POSIX detection of
  18. # the timer_create() function is skipped, and instead the usual check
  19. # for the existence of all the timer_* functions is done using
  20. # AC_REPLACE_FUNCS.
  21. #
  22. # If enable_timer_replacement=true, the replacements is forced to be built.
  23. AC_DEFUN([HW_LIBRT_TIMERS],
  24. [
  25. AC_PREREQ([2.60])dnl 2.59 should work if some AC_TYPE_* macros are replaced.
  26. AC_REQUIRE([HW_HEADER_TIME_H])dnl Our check evaluates HAVE_TIME_H.
  27. if test "xtrue" != x"$enable_timer_replacement"; then
  28. AC_CHECK_FUNC([timer_create],
  29. [hw_cv_librt_timers=yes],
  30. [hw_cv_librt_timers=no])
  31. AS_IF([test "$hw_cv_librt_timers" = yes],
  32. [AC_CACHE_CHECK([if timer_create is supported on the system],
  33. [hw_cv_librt_timers_posix],
  34. [AC_RUN_IFELSE(
  35. [AC_LANG_PROGRAM(
  36. [[#if HAVE_TIME_H
  37. #include <time.h>
  38. #endif
  39. #include <errno.h>
  40. static int test_timer_create()
  41. {
  42. timer_t timerid;
  43. if(timer_create(CLOCK_REALTIME, NULL, &timerid) != 0)
  44. {
  45. /*
  46. On this system, although the function is available,
  47. no meaningful implementation is provided.
  48. */
  49. if(errno == ENOSYS)
  50. {
  51. return 1;
  52. }
  53. }
  54. return 0;
  55. }]],
  56. [[return test_timer_create();]])],
  57. [hw_cv_librt_timers_posix=yes],
  58. [hw_cv_librt_timers_posix=no],
  59. [hw_cv_librt_timers_posix=autodetect])])],
  60. [hw_cv_librt_timers_posix=no])
  61. else
  62. hw_cv_librt_timers_posix=no
  63. fi
  64. # If the system does not have a POSIX timer_create(), then use
  65. # Check's reimplementation of the timer_* calls
  66. AS_IF([test "$hw_cv_librt_timers_posix" = no],
  67. [_HW_LIBRT_TIMERS_REPLACE])
  68. # If we are cross compiling, do the normal check for the
  69. # timer_* calls.
  70. AS_IF([test "$hw_cv_librt_timers_posix" = autodetect],
  71. [AC_REPLACE_FUNCS([timer_create timer_settime timer_delete])
  72. AC_CHECK_DECLS([timer_create, timer_settime, timer_delete])])
  73. ])# HW_LIBRT_TIMERS
  74. # _HW_LIBRT_TIMERS_REPLACE
  75. # ------------------------
  76. # Arrange for building timer_create.c, timer_settime.c, and
  77. # timer_delete.c.
  78. AC_DEFUN([_HW_LIBRT_TIMERS_REPLACE],
  79. [
  80. AS_IF([test "x$_hw_cv_librt_timers_replace_done" != xyes],
  81. [AC_LIBOBJ([timer_create])
  82. AC_LIBOBJ([timer_settime])
  83. AC_LIBOBJ([timer_delete])
  84. _hw_cv_librt_timers_replace_done=yes])
  85. ])# _HW_LIBRT_TIMERS_REPLACE