1 dnl @synopsis AX_LIB_EVENT([MINIMUM-VERSION])
3 dnl Test for the libevent library of a particular version (or newer).
5 dnl If no path to the installed libevent is given, the macro will first try
6 dnl using no -I or -L flags, then searches under /usr, /usr/local, /opt,
8 dnl If these all fail, it will try the $LIBEVENT_ROOT environment variable.
10 dnl This macro requires that #include <sys/types.h> works and defines u_char.
13 dnl AC_SUBST(LIBEVENT_CPPFLAGS)
14 dnl AC_SUBST(LIBEVENT_LDFLAGS)
15 dnl AC_SUBST(LIBEVENT_LIBS)
17 dnl And (if libevent is found):
18 dnl AC_DEFINE(HAVE_LIBEVENT)
20 dnl It also leaves the shell variables "success" and "ax_have_libevent"
21 dnl set to "yes" or "no".
23 dnl NOTE: This macro does not currently work for cross-compiling,
24 dnl but it can be easily modified to allow it. (grep "cross").
26 dnl @category InstalledPackages
28 dnl @author David Reiss <dreiss@facebook.com>
29 dnl @version 2007-09-12
30 dnl @license AllPermissive
32 dnl Input: ax_libevent_path, WANT_LIBEVENT_VERSION
33 dnl Output: success=yes/no
34 AC_DEFUN([AX_LIB_EVENT_DO_CHECK],
37 CPPFLAGS_SAVED="$CPPFLAGS"
38 LDFLAGS_SAVED="$LDFLAGS"
40 LD_LIBRARY_PATH_SAVED="$LD_LIBRARY_PATH"
42 # Set our flags if we are checking a specific directory.
43 if test -n "$ax_libevent_path" ; then
44 LIBEVENT_CPPFLAGS="-I$ax_libevent_path/include"
45 LIBEVENT_LDFLAGS="-L$ax_libevent_path/lib"
46 LD_LIBRARY_PATH="$ax_libevent_path/lib:$LD_LIBRARY_PATH"
52 # Required flag for libevent.
53 LIBEVENT_LIBS="-levent"
55 # Prepare the environment for compilation.
56 CPPFLAGS="$CPPFLAGS $LIBEVENT_CPPFLAGS"
57 LDFLAGS="$LDFLAGS $LIBEVENT_LDFLAGS"
58 LIBS="$LIBS $LIBEVENT_LIBS"
62 export LD_LIBRARY_PATH
66 # Compile, link, and run the program. This checks:
67 # - event.h is available for including.
68 # - event_get_version() is available for linking.
69 # - The event version string is lexicographically greater
70 # than the required version.
72 dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling,
73 dnl but then the version cannot be checked.
74 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
75 #include <sys/types.h>
78 const char* lib_version = event_get_version();
79 const char* wnt_version = "$WANT_LIBEVENT_VERSION";
81 /* If we reached the end of the want version. We have it. */
82 if (*wnt_version == '\0') {
85 /* If the want version continues but the lib version does not, */
86 /* we are missing a letter. We don't have it. */
87 if (*lib_version == '\0') {
90 /* If we have greater than what we want. We have it. */
91 if (*lib_version > *wnt_version) {
94 /* If we have less, we don't. */
95 if (*lib_version < *wnt_version) {
108 CPPFLAGS="$CPPFLAGS_SAVED"
109 LDFLAGS="$LDFLAGS_SAVED"
111 LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED"
115 AC_DEFUN([AX_LIB_EVENT],
118 dnl Allow search path to be overridden on the command line.
119 AC_ARG_WITH([libevent],
120 AS_HELP_STRING([--with-libevent@<:@=DIR@:>@], [use libevent (default is yes) - it is possible to specify an alternate root directory for libevent]),
122 if test "x$withval" = "xno"; then
124 elif test "x$withval" = "xyes"; then
129 ax_libevent_path="$withval"
132 [ want_libevent="yes" ; ax_libevent_path="" ])
135 if test "$want_libevent" = "yes"; then
136 WANT_LIBEVENT_VERSION=ifelse([$1], ,1.2,$1)
138 AC_MSG_CHECKING(for libevent >= $WANT_LIBEVENT_VERSION)
141 if test -n "$ax_libevent_path"; then
142 AX_LIB_EVENT_DO_CHECK
144 for ax_libevent_path in "" /usr /usr/local /opt /opt/libevent "$LIBEVENT_ROOT" ; do
145 AX_LIB_EVENT_DO_CHECK
146 if test "$success" = "yes"; then
152 if test "$success" != "yes" ; then
159 AC_DEFINE(HAVE_LIBEVENT,,[define if libevent is available])
162 ax_have_libevent="$success"
164 AC_SUBST(LIBEVENT_CPPFLAGS)
165 AC_SUBST(LIBEVENT_LDFLAGS)
166 AC_SUBST(LIBEVENT_LIBS)