blob: 3a48156a7b19b0b1899b1a5310272a97a3855d98 [file] [log] [blame]
David Reiss79ae0f82007-09-17 21:15:47 +00001dnl @synopsis AX_LIB_EVENT([MINIMUM-VERSION])
2dnl
David Reissfaebedd2007-09-17 23:20:38 +00003dnl Test for the libevent library of a particular version (or newer).
David Reiss79ae0f82007-09-17 21:15:47 +00004dnl
5dnl If no path to the installed libevent is given, the macro will first try
6dnl using no -I or -L flags, then searches under /usr, /usr/local, /opt,
7dnl and /opt/libevent.
8dnl If these all fail, it will try the $LIBEVENT_ROOT environment variable.
9dnl
10dnl This macro requires that #include <sys/types.h> works and defines u_char.
11dnl
12dnl This macro calls:
13dnl AC_SUBST(LIBEVENT_CPPFLAGS)
14dnl AC_SUBST(LIBEVENT_LDFLAGS)
15dnl AC_SUBST(LIBEVENT_LIBS)
16dnl
17dnl And (if libevent is found):
18dnl AC_DEFINE(HAVE_LIBEVENT)
19dnl
20dnl It also leaves the shell variables "success" and "ax_have_libevent"
21dnl set to "yes" or "no".
22dnl
23dnl NOTE: This macro does not currently work for cross-compiling,
24dnl but it can be easily modified to allow it. (grep "cross").
25dnl
26dnl @category InstalledPackages
27dnl @category C
David Reiss79ae0f82007-09-17 21:15:47 +000028dnl @version 2007-09-12
29dnl @license AllPermissive
David Reissf82aee52009-03-30 22:52:29 +000030dnl
31dnl Copyright (C) 2009 David Reiss
32dnl Copying and distribution of this file, with or without modification,
33dnl are permitted in any medium without royalty provided the copyright
34dnl notice and this notice are preserved.
David Reiss79ae0f82007-09-17 21:15:47 +000035
36dnl Input: ax_libevent_path, WANT_LIBEVENT_VERSION
37dnl Output: success=yes/no
38AC_DEFUN([AX_LIB_EVENT_DO_CHECK],
39 [
40 # Save our flags.
41 CPPFLAGS_SAVED="$CPPFLAGS"
42 LDFLAGS_SAVED="$LDFLAGS"
43 LIBS_SAVED="$LIBS"
44 LD_LIBRARY_PATH_SAVED="$LD_LIBRARY_PATH"
45
46 # Set our flags if we are checking a specific directory.
47 if test -n "$ax_libevent_path" ; then
48 LIBEVENT_CPPFLAGS="-I$ax_libevent_path/include"
49 LIBEVENT_LDFLAGS="-L$ax_libevent_path/lib"
50 LD_LIBRARY_PATH="$ax_libevent_path/lib:$LD_LIBRARY_PATH"
51 else
52 LIBEVENT_CPPFLAGS=""
53 LIBEVENT_LDFLAGS=""
54 fi
55
56 # Required flag for libevent.
57 LIBEVENT_LIBS="-levent"
58
59 # Prepare the environment for compilation.
60 CPPFLAGS="$CPPFLAGS $LIBEVENT_CPPFLAGS"
61 LDFLAGS="$LDFLAGS $LIBEVENT_LDFLAGS"
62 LIBS="$LIBS $LIBEVENT_LIBS"
63 export CPPFLAGS
64 export LDFLAGS
65 export LIBS
66 export LD_LIBRARY_PATH
67
68 success=no
69
70 # Compile, link, and run the program. This checks:
71 # - event.h is available for including.
72 # - event_get_version() is available for linking.
73 # - The event version string is lexicographically greater
74 # than the required version.
75 AC_LANG_PUSH([C])
76 dnl This can be changed to AC_LINK_IFELSE if you are cross-compiling,
77 dnl but then the version cannot be checked.
78 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
79 #include <sys/types.h>
80 #include <event.h>
81 ]], [[
82 const char* lib_version = event_get_version();
83 const char* wnt_version = "$WANT_LIBEVENT_VERSION";
84 for (;;) {
85 /* If we reached the end of the want version. We have it. */
86 if (*wnt_version == '\0') {
87 return 0;
88 }
89 /* If the want version continues but the lib version does not, */
90 /* we are missing a letter. We don't have it. */
91 if (*lib_version == '\0') {
92 return 1;
93 }
94 /* If we have greater than what we want. We have it. */
95 if (*lib_version > *wnt_version) {
96 return 0;
97 }
98 /* If we have less, we don't. */
99 if (*lib_version < *wnt_version) {
100 return 1;
101 }
102 lib_version++;
103 wnt_version++;
104 }
105 return 0;
106 ]])], [
107 success=yes
108 ])
109 AC_LANG_POP([C])
110
111 # Restore flags.
112 CPPFLAGS="$CPPFLAGS_SAVED"
113 LDFLAGS="$LDFLAGS_SAVED"
114 LIBS="$LIBS_SAVED"
115 LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED"
116 ])
117
118
119AC_DEFUN([AX_LIB_EVENT],
120 [
121
122 dnl Allow search path to be overridden on the command line.
123 AC_ARG_WITH([libevent],
124 AS_HELP_STRING([--with-libevent@<:@=DIR@:>@], [use libevent (default is yes) - it is possible to specify an alternate root directory for libevent]),
125 [
126 if test "x$withval" = "xno"; then
127 want_libevent="no"
128 elif test "x$withval" = "xyes"; then
129 want_libevent="yes"
130 ax_libevent_path=""
131 else
132 want_libevent="yes"
133 ax_libevent_path="$withval"
134 fi
135 ],
136 [ want_libevent="yes" ; ax_libevent_path="" ])
137
138
139 if test "$want_libevent" = "yes"; then
140 WANT_LIBEVENT_VERSION=ifelse([$1], ,1.2,$1)
141
142 AC_MSG_CHECKING(for libevent >= $WANT_LIBEVENT_VERSION)
143
144 # Run tests.
145 if test -n "$ax_libevent_path"; then
146 AX_LIB_EVENT_DO_CHECK
147 else
T Jake Luciani9c983c22009-01-16 01:04:27 +0000148 for ax_libevent_path in "" /usr /usr/local /opt /opt/local /opt/libevent "$LIBEVENT_ROOT" ; do
David Reiss79ae0f82007-09-17 21:15:47 +0000149 AX_LIB_EVENT_DO_CHECK
150 if test "$success" = "yes"; then
151 break;
152 fi
153 done
154 fi
155
156 if test "$success" != "yes" ; then
157 AC_MSG_RESULT(no)
158 LIBEVENT_CPPFLAGS=""
159 LIBEVENT_LDFLAGS=""
160 LIBEVENT_LIBS=""
161 else
162 AC_MSG_RESULT(yes)
163 AC_DEFINE(HAVE_LIBEVENT,,[define if libevent is available])
164 fi
165
166 ax_have_libevent="$success"
167
168 AC_SUBST(LIBEVENT_CPPFLAGS)
169 AC_SUBST(LIBEVENT_LDFLAGS)
170 AC_SUBST(LIBEVENT_LIBS)
171 fi
172
173 ])