Merge lp:~tangent-org/libmemcached/1.0-build Build: jenkins-Libmemcached-1.0-114
[awesomized/libmemcached] / m4 / ax_libevent.m4
1 # https://github.com/BrianAker/ddm4
2 # ===========================================================================
3 #
4 # SYNOPSIS
5 #
6 # AX_LIBEVENT(), AX_LIBEVENT2(), AX_LIBEVENT2_EVHTTP()
7 #
8 # DESCRIPTION
9 #
10 # libevent library
11 #
12 # LICENSE
13 #
14 # Copyright (c) 2012 Brian Aker <brian@tangent.org>
15 #
16 # Copying and distribution of this file, with or without modification, are
17 # permitted in any medium without royalty provided the copyright notice
18 # and this notice are preserved. This file is offered as-is, without any
19 # warranty.
20
21 #serial 2
22
23 AC_DEFUN([AX_LIBEVENT],
24 [AC_PREREQ([2.63])dnl
25 AC_CACHE_CHECK([test for a working libevent],[ax_cv_libevent],
26 [AX_SAVE_FLAGS
27 LIBS="-levent $LIBS"
28 AC_LANG_PUSH([C])
29 AC_RUN_IFELSE([
30 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
46 AS_IF([test "x$ax_cv_libevent" = "xyes"],
47 [LIBEVENT_LDFLAGS="-levent"
48 AC_SUBST(LIBEVENT_LDFLAGS)
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 ])
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([
62 AC_LANG_PROGRAM([
63 #include <sys/types.h>
64 #include <sys/time.h>
65 #include <stdlib.h>
66 #include <event2/event.h>
67 ],[
68 struct event_base *tmp_event= event_init();
69 event_base_free(tmp_event);
70 ])],
71 [ax_cv_libevent2=yes],
72 [ax_cv_libevent2=no],
73 [AC_MSG_WARN([test program execution failed])])
74 AC_LANG_POP
75 AX_RESTORE_FLAGS
76 ])
77
78 AS_IF([test "x$ax_cv_libevent2" = xyes],
79 [LIBEVENT2_LDFLAGS="-levent"
80 AC_SUBST(LIBEVENT2_LDFLAGS)
81 AC_DEFINE([HAVE_LIBEVENT2],[1],[Define if event_init is present in event2/event.h.])],
82 [AC_DEFINE([HAVE_LIBEVENT2],[0],[Define if event_init is present in event2/event.h.])])
83
84 AM_CONDITIONAL([HAVE_LIBEVENT2], [test "x$ax_cv_libevent2" = xyes])
85 ])
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([
94 AC_LANG_PROGRAM([
95 #include <sys/types.h>
96 #include <sys/time.h>
97 #include <stdlib.h>
98 #include <event2/event.h>
99 #include <event2/http.h>
100 ],[
101 struct event_base *libbase= event_base_new();
102 struct evhttp *libsrvr= evhttp_new(libbase);
103 ])],
104 [ax_cv_libevent2_evhttp=yes],
105 [ax_cv_libevent2_evhttp=no],
106 [AC_MSG_WARN([test program execution failed])])
107 AC_LANG_POP
108 AX_RESTORE_FLAGS
109 ])
110
111 AS_IF([test "x$ax_cv_libevent2_evhttp" = "xyes"],
112 [LIBEVENT2_LDFLAGS="-levent"
113 AC_SUBST(LIBEVENT2_LDFLAGS)
114 AC_DEFINE([HAVE_LIBEVENT2],[1],[Define if event_init is present in event2/event.h.])],
115 [AC_DEFINE([HAVE_LIBEVENT2],[0],[Define if event_init is present in event2/event.h.])])
116
117 AM_CONDITIONAL([HAVE_LIBEVENT2_EVHTTP],[test "x$ax_cv_libevent2_evhttp" = xyes])
118 ])