Merge lp:~tangent-org/libmemcached/1.0-build/ Build: jenkins-Libmemcached-187
[m6w6/libmemcached] / m4 / ax_libevent.m4
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 #
10 # DESCRIPTION
11 #
12 # libevent library
13 #
14 # LICENSE
15 #
16 # Copyright (c) 2012 Brian Aker <brian@tangent.org>
17 #
18 # Copying and distribution of this file, with or without modification, are
19 # permitted in any medium without royalty provided the copyright notice
20 # and this notice are preserved. This file is offered as-is, without any
21 # warranty.
22
23 #serial 4
24
25 AC_DEFUN([AX_LIBEVENT],
26 [AC_PREREQ([2.63])dnl
27 AC_CACHE_CHECK([test for a working libevent],[ax_cv_libevent],
28 [AX_SAVE_FLAGS
29 LIBS="-levent $LIBS"
30 AC_LANG_PUSH([C])
31 AC_RUN_IFELSE([AC_LANG_PROGRAM([
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <stdlib.h>
35 #include <event.h>
36 ],[
37 struct event_base *tmp_event= event_init();
38 event_base_free(tmp_event);
39 ])],
40 [ax_cv_libevent=yes],
41 [ax_cv_libevent=no],
42 [AC_MSG_WARN([test program execution failed])])
43 AC_LANG_POP
44 AX_RESTORE_FLAGS
45 ])
46
47 AS_IF([test "x$ax_cv_libevent" = "xyes"],
48 [AC_SUBST([LIBEVENT_LIB],[-levent])
49 AC_DEFINE([HAVE_LIBEVENT],[1],[Define if event_init is present in event.h.])],
50 [AC_DEFINE([HAVE_LIBEVENT],[0],[Define if event_init is present in event.h.])])
51
52 AM_CONDITIONAL(HAVE_LIBEVENT, test "x$ax_cv_libevent" = "xyes")
53 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
54 AS_IF([test "x$ax_cv_libevent" = xyes],
55 [$1],
56 [$2])
57 ])
58
59 AC_DEFUN([AX_LIBEVENT2],
60 [AC_REQUIRE([AX_LIBEVENT])
61 AC_CACHE_CHECK([test for a working libevent version 2],[ax_cv_libevent2],
62 [AX_SAVE_FLAGS
63 LIBS="-levent $LIBS"
64 AC_LANG_PUSH([C])
65 AC_RUN_IFELSE([AC_LANG_PROGRAM([
66 #include <sys/types.h>
67 #include <sys/time.h>
68 #include <stdlib.h>
69 #include <event2/event.h>
70 ],[
71 struct event_base *tmp_event= event_init();
72 event_base_free(tmp_event);
73 ])],
74 [ax_cv_libevent2=yes],
75 [ax_cv_libevent2=no],
76 [AC_MSG_WARN([test program execution failed])])
77 AC_LANG_POP([C])
78 AX_RESTORE_FLAGS
79 ])
80
81 AS_IF([test "x$ax_cv_libevent2" = xyes],
82 [AC_SUBST([LIBEVENT2_LIB],[-levent])
83 AC_DEFINE([HAVE_LIBEVENT2],[1],[Define if event_init is present in event2/event.h.])],
84 [AC_DEFINE([HAVE_LIBEVENT2],[0],[Define if event_init is present in event2/event.h.])])
85
86 AM_CONDITIONAL([HAVE_LIBEVENT2], [test "x$ax_cv_libevent2" = xyes])
87 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
88 AS_IF([test "x$ax_cv_libevent2" = xyes],
89 [$1],
90 [$2])
91 ])dnl AX_LIBEVENT2
92
93 #
94 AC_DEFUN([AX_LIBEVENT2_EVHTTP],
95 [AC_REQUIRE([AX_LIBEVENT2])
96 AC_CACHE_CHECK([test for a working libevent2 evhttp interface], [ax_cv_libevent2_evhttp],
97 [AX_SAVE_FLAGS
98 LIBS="-levent $LIBS"
99 AC_LANG_PUSH([C])
100 AC_RUN_IFELSE([AC_LANG_PROGRAM([
101 #include <sys/types.h>
102 #include <sys/time.h>
103 #include <stdlib.h>
104 #include <event2/event.h>
105 #include <event2/http.h>
106 ],[
107 struct event_base *libbase= event_base_new();
108 struct evhttp *libsrvr= evhttp_new(libbase);
109 ])],
110 [ax_cv_libevent2_evhttp=yes],
111 [ax_cv_libevent2_evhttp=no],
112 [AC_MSG_WARN([test program execution failed])])
113 AC_LANG_POP([C])
114 AX_RESTORE_FLAGS
115 ])
116
117 AS_IF([test "x$ax_cv_libevent2_evhttp" = "xyes"],
118 [AC_DEFINE([HAVE_LIBEVENT2_EVHTTP],[1],[Define if event_init is present in event2/http.h.])],
119 [AC_DEFINE([HAVE_LIBEVENT2_EVHTTP],[0],[Define if event_init is present in event2/http.h.])])
120
121 AM_CONDITIONAL([HAVE_LIBEVENT2_EVHTTP],[test "x$ax_cv_libevent2_evhttp" = xyes])
122 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
123 AS_IF([test "x$ax_cv_libevent2_evhttp" = xyes],
124 [$1],
125 [$2])
126 ])dnl AX_LIBEVENT2_EVHTTP