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