1dnl @synopsis AX_LIB_EVENT([MINIMUM-VERSION]) 2dnl 3dnl Test for the libevent library of a particular version (or newer). 4dnl 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 28dnl @version 2007-09-12 29dnl @license AllPermissive 30dnl 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. 35 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_LINK_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 int lib_digits; 85 int wnt_digits; 86 for (;;) { 87 /* If we reached the end of the want version. We have it. */ 88 if (*wnt_version == '\0' || *wnt_version == '-') { 89 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. */ 93 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. */ 98 for (lib_digits = 0; 99 lib_version[lib_digits] >= '0' && 100 lib_version[lib_digits] <= '9'; 101 lib_digits++) 102 ; 103 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) { 112 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], 144 AS_HELP_STRING([--with-libevent@<:@=DIR@:>@], [use libevent [default=yes]. Optionally specify the root prefix dir where libevent is installed]), 145 [ 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 168 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 169 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]) 184 ax_have_libevent_[]m4_translit([$1], [.], [_])="yes" 185 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 ]) 195