ax_libevent.m4 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # https://github.com/BrianAker/ddm4
  2. # ===========================================================================
  3. #
  4. # SYNOPSIS
  5. #
  6. # AX_LIBEVENT([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  7. # AX_LIBEVENT2()
  8. # AX_LIBEVENT2_EVHTTP()
  9. # AX_LIBEVENT2_PTHREADS()
  10. #
  11. # DESCRIPTION
  12. #
  13. # libevent library
  14. #
  15. # LICENSE
  16. #
  17. # Copyright (c) 2012 Brian Aker <brian@tangent.org>
  18. #
  19. # Copying and distribution of this file, with or without modification, are
  20. # permitted in any medium without royalty provided the copyright notice
  21. # and this notice are preserved. This file is offered as-is, without any
  22. # warranty.
  23. #serial 6
  24. AC_DEFUN([AX_LIBEVENT],
  25. [AC_PREREQ([2.63])dnl
  26. AC_CACHE_CHECK([test for a working libevent],[ax_cv_libevent],
  27. [AX_SAVE_FLAGS
  28. LIBS="-levent $LIBS"
  29. AC_LANG_PUSH([C])
  30. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  31. #include <sys/types.h>
  32. #include <sys/time.h>
  33. #include <stdlib.h>
  34. #include <event.h>
  35. ]],[[
  36. struct event_base *tmp_event= event_init();
  37. event_base_free(tmp_event);
  38. ]])],
  39. [ax_cv_libevent=yes],
  40. [ax_cv_libevent=no],
  41. [AC_MSG_WARN([test program execution failed])])
  42. AC_LANG_POP
  43. AX_RESTORE_FLAGS
  44. ])
  45. AS_IF([test "x$ax_cv_libevent" = "xyes"],
  46. [AC_SUBST([LIBEVENT_LIB],[-levent])
  47. AC_DEFINE([HAVE_LIBEVENT],[1],[Define if event_init is present in event.h.])],
  48. [AC_DEFINE([HAVE_LIBEVENT],[0],[Define if event_init is present in event.h.])])
  49. AM_CONDITIONAL(HAVE_LIBEVENT, test "x$ax_cv_libevent" = "xyes")
  50. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  51. AS_IF([test "x$ax_cv_libevent" = xyes],
  52. [$1],
  53. [$2])
  54. ])
  55. AC_DEFUN([AX_LIBEVENT2],
  56. [AC_REQUIRE([AX_LIBEVENT])
  57. AC_CACHE_CHECK([test for a working libevent version 2],[ax_cv_libevent2],
  58. [AX_SAVE_FLAGS
  59. LIBS="-levent $LIBS"
  60. AC_LANG_PUSH([C])
  61. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  62. #include <sys/types.h>
  63. #include <sys/time.h>
  64. #include <stdlib.h>
  65. #include <event2/event.h>
  66. ]],[[
  67. struct event_base *___event_base= event_base_new();
  68. event_base_free(___event_base);
  69. ]])],
  70. [ax_cv_libevent2=yes],
  71. [ax_cv_libevent2=no],
  72. [AC_MSG_WARN([test program execution failed])])
  73. AC_LANG_POP([C])
  74. AX_RESTORE_FLAGS
  75. ])
  76. AS_IF([test "x$ax_cv_libevent2" = xyes],
  77. [AC_SUBST([LIBEVENT2_LIB],[-levent])
  78. AC_DEFINE([HAVE_LIBEVENT2],[1],[Define if event_init is present in event2/event.h.])],
  79. [AC_DEFINE([HAVE_LIBEVENT2],[0],[Define if event_init is present in event2/event.h.])])
  80. AM_CONDITIONAL([HAVE_LIBEVENT2], [test "x$ax_cv_libevent2" = xyes])
  81. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  82. AS_IF([test "x$ax_cv_libevent2" = xyes],
  83. [$1],
  84. [$2])
  85. ])dnl AX_LIBEVENT2
  86. #
  87. AC_DEFUN([AX_LIBEVENT2_EVHTTP],
  88. [AC_REQUIRE([AX_LIBEVENT2])
  89. AC_CACHE_CHECK([test for a working libevent2 evhttp interface], [ax_cv_libevent2_evhttp],
  90. [AX_SAVE_FLAGS
  91. LIBS="-levent $LIBS"
  92. AC_LANG_PUSH([C])
  93. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  94. #include <sys/types.h>
  95. #include <sys/time.h>
  96. #include <stdlib.h>
  97. #include <event2/event.h>
  98. #include <event2/http.h>
  99. ]],[[
  100. struct event_base *___event_base= event_base_new();
  101. struct evhttp *___evhttp= evhttp_new(___event_base);
  102. evhttp_free(___evhttp);
  103. event_base_free(___event_base);
  104. ]])],
  105. [ax_cv_libevent2_evhttp=yes],
  106. [ax_cv_libevent2_evhttp=no],
  107. [AC_MSG_WARN([test program execution failed])])
  108. AC_LANG_POP([C])
  109. AX_RESTORE_FLAGS
  110. ])
  111. AS_IF([test "x$ax_cv_libevent2_evhttp" = "xyes"],
  112. [AC_DEFINE([HAVE_LIBEVENT2_EVHTTP],[1],[Define if event_init is present in event2/http.h.])],
  113. [AC_DEFINE([HAVE_LIBEVENT2_EVHTTP],[0],[Define if event_init is present in event2/http.h.])])
  114. AM_CONDITIONAL([HAVE_LIBEVENT2_EVHTTP],[test "x$ax_cv_libevent2_evhttp" = xyes])
  115. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  116. AS_IF([test "x$ax_cv_libevent2_evhttp" = xyes],
  117. [$1],
  118. [$2])
  119. ])dnl AX_LIBEVENT2_EVHTTP
  120. #
  121. AC_DEFUN([AX_LIBEVENT2_PTHREADS],
  122. [AC_REQUIRE([AX_LIBEVENT2])
  123. AC_CACHE_CHECK([test for a working libevent pthreads interface], [ax_cv_libevent2_pthreads],
  124. [AX_SAVE_FLAGS
  125. CFLAGS="-pthread $CFLAGS"
  126. LIBS="-levent_pthreads -levent $LIBS"
  127. AC_LANG_PUSH([C])
  128. AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  129. #include <event2/thread.h>
  130. ]],[[
  131. evthread_use_pthreads();
  132. ]])],
  133. [ax_cv_libevent2_pthreads=yes],
  134. [ax_cv_libevent2_pthreads=no],
  135. [AC_MSG_WARN([test program execution failed])])
  136. AC_LANG_POP([C])
  137. AX_RESTORE_FLAGS
  138. ])
  139. AS_IF([test "x$ax_cv_libevent2_pthreads" = "xyes"],
  140. [AC_SUBST([LIBEVENT2_PTHREADS_LIB],[-levent_pthreads])
  141. AC_DEFINE([HAVE_LIBEVENT2_PTHREADS],[1],[Define if evthread_use_pthreads is present in event2/thread.h.])],
  142. [AC_DEFINE([HAVE_LIBEVENT2_PTHREADS],[0],[Define if evthread_use_pthreads is present in event2/thread.h.])])
  143. AM_CONDITIONAL([HAVE_LIBEVENT2_PTHREADS],[test "x$ax_cv_libevent2_pthreads" = xyes])
  144. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  145. AS_IF([test "x$ax_cv_libevent2_pthreads" = xyes],
  146. [$1],
  147. [$2])
  148. ])dnl AX_LIBEVENT2_PTHREADS