blob: d4dcdc9a64f8a5dc4947dbf3fe2a860caf1a1280 [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.
Gustavo Zacariase856d682015-04-25 17:53:28 +020078 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
David Reiss79ae0f82007-09-17 21:15:47 +000079 #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";
Roger Meier013b2e52011-08-04 22:37:16 +000084 int lib_digits;
85 int wnt_digits;
David Reiss79ae0f82007-09-17 21:15:47 +000086 for (;;) {
87 /* If we reached the end of the want version. We have it. */
David Reisse657eb42009-07-29 19:07:27 +000088 if (*wnt_version == '\0' || *wnt_version == '-') {
David Reiss79ae0f82007-09-17 21:15:47 +000089 return 0;
90 }
91 /* If the want version continues but the lib version does not, */
92 /* we are missing a letter. We don't have it. */
David Reisse657eb42009-07-29 19:07:27 +000093 if (*lib_version == '\0' || *lib_version == '-') {
94 return 1;
95 }
96 /* In the 1.4 version numbering style, if there are more digits */
97 /* in one version than the other, that one is higher. */
David Reisse657eb42009-07-29 19:07:27 +000098 for (lib_digits = 0;
99 lib_version[lib_digits] >= '0' &&
100 lib_version[lib_digits] <= '9';
101 lib_digits++)
102 ;
David Reisse657eb42009-07-29 19:07:27 +0000103 for (wnt_digits = 0;
104 wnt_version[wnt_digits] >= '0' &&
105 wnt_version[wnt_digits] <= '9';
106 wnt_digits++)
107 ;
108 if (lib_digits > wnt_digits) {
109 return 0;
110 }
111 if (lib_digits < wnt_digits) {
David Reiss79ae0f82007-09-17 21:15:47 +0000112 return 1;
113 }
114 /* If we have greater than what we want. We have it. */
115 if (*lib_version > *wnt_version) {
116 return 0;
117 }
118 /* If we have less, we don't. */
119 if (*lib_version < *wnt_version) {
120 return 1;
121 }
122 lib_version++;
123 wnt_version++;
124 }
125 return 0;
126 ]])], [
127 success=yes
128 ])
129 AC_LANG_POP([C])
130
131 # Restore flags.
132 CPPFLAGS="$CPPFLAGS_SAVED"
133 LDFLAGS="$LDFLAGS_SAVED"
134 LIBS="$LIBS_SAVED"
135 LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED"
136 ])
137
138
139AC_DEFUN([AX_LIB_EVENT],
140 [
141
142 dnl Allow search path to be overridden on the command line.
143 AC_ARG_WITH([libevent],
Jake Farrell2fd8a152012-09-29 00:26:36 +0000144 AS_HELP_STRING([--with-libevent@<:@=DIR@:>@], [use libevent [default=yes]. Optionally specify the root prefix dir where libevent is installed]),
David Reiss79ae0f82007-09-17 21:15:47 +0000145 [
146 if test "x$withval" = "xno"; then
147 want_libevent="no"
148 elif test "x$withval" = "xyes"; then
149 want_libevent="yes"
150 ax_libevent_path=""
151 else
152 want_libevent="yes"
153 ax_libevent_path="$withval"
154 fi
155 ],
156 [ want_libevent="yes" ; ax_libevent_path="" ])
157
158
159 if test "$want_libevent" = "yes"; then
160 WANT_LIBEVENT_VERSION=ifelse([$1], ,1.2,$1)
161
162 AC_MSG_CHECKING(for libevent >= $WANT_LIBEVENT_VERSION)
163
164 # Run tests.
165 if test -n "$ax_libevent_path"; then
166 AX_LIB_EVENT_DO_CHECK
167 else
jfarrell4d3f9372014-10-08 23:35:05 -0400168 for ax_libevent_path in "" $lt_sysroot/usr $lt_sysroot/usr/local $lt_sysroot/opt $lt_sysroot/opt/local $lt_sysroot/opt/libevent "$LIBEVENT_ROOT" ; do
David Reiss79ae0f82007-09-17 21:15:47 +0000169 AX_LIB_EVENT_DO_CHECK
170 if test "$success" = "yes"; then
171 break;
172 fi
173 done
174 fi
175
176 if test "$success" != "yes" ; then
177 AC_MSG_RESULT(no)
178 LIBEVENT_CPPFLAGS=""
179 LIBEVENT_LDFLAGS=""
180 LIBEVENT_LIBS=""
181 else
182 AC_MSG_RESULT(yes)
183 AC_DEFINE(HAVE_LIBEVENT,,[define if libevent is available])
David Reissad557422009-07-29 19:07:33 +0000184 ax_have_libevent_[]m4_translit([$1], [.], [_])="yes"
David Reiss79ae0f82007-09-17 21:15:47 +0000185 fi
186
187 ax_have_libevent="$success"
188
189 AC_SUBST(LIBEVENT_CPPFLAGS)
190 AC_SUBST(LIBEVENT_LDFLAGS)
191 AC_SUBST(LIBEVENT_LIBS)
192 fi
193
194 ])