David Reiss | 79ae0f8 | 2007-09-17 21:15:47 +0000 | [diff] [blame^] | 1 | dnl @synopsis AX_LIB_EVENT([MINIMUM-VERSION]) |
| 2 | dnl |
| 3 | dnl Test for the libz library of a particular version (or newer). |
| 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 |
| 28 | dnl @author David Reiss <dreiss@facebook.com> |
| 29 | dnl @version 2007-09-12 |
| 30 | dnl @license AllPermissive |
| 31 | |
| 32 | dnl Input: ax_libevent_path, WANT_LIBEVENT_VERSION |
| 33 | dnl Output: success=yes/no |
| 34 | AC_DEFUN([AX_LIB_EVENT_DO_CHECK], |
| 35 | [ |
| 36 | # Save our flags. |
| 37 | CPPFLAGS_SAVED="$CPPFLAGS" |
| 38 | LDFLAGS_SAVED="$LDFLAGS" |
| 39 | LIBS_SAVED="$LIBS" |
| 40 | LD_LIBRARY_PATH_SAVED="$LD_LIBRARY_PATH" |
| 41 | |
| 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" |
| 47 | else |
| 48 | LIBEVENT_CPPFLAGS="" |
| 49 | LIBEVENT_LDFLAGS="" |
| 50 | fi |
| 51 | |
| 52 | # Required flag for libevent. |
| 53 | LIBEVENT_LIBS="-levent" |
| 54 | |
| 55 | # Prepare the environment for compilation. |
| 56 | CPPFLAGS="$CPPFLAGS $LIBEVENT_CPPFLAGS" |
| 57 | LDFLAGS="$LDFLAGS $LIBEVENT_LDFLAGS" |
| 58 | LIBS="$LIBS $LIBEVENT_LIBS" |
| 59 | export CPPFLAGS |
| 60 | export LDFLAGS |
| 61 | export LIBS |
| 62 | export LD_LIBRARY_PATH |
| 63 | |
| 64 | success=no |
| 65 | |
| 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. |
| 71 | AC_LANG_PUSH([C]) |
| 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> |
| 76 | #include <event.h> |
| 77 | ]], [[ |
| 78 | const char* lib_version = event_get_version(); |
| 79 | const char* wnt_version = "$WANT_LIBEVENT_VERSION"; |
| 80 | for (;;) { |
| 81 | /* If we reached the end of the want version. We have it. */ |
| 82 | if (*wnt_version == '\0') { |
| 83 | return 0; |
| 84 | } |
| 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') { |
| 88 | return 1; |
| 89 | } |
| 90 | /* If we have greater than what we want. We have it. */ |
| 91 | if (*lib_version > *wnt_version) { |
| 92 | return 0; |
| 93 | } |
| 94 | /* If we have less, we don't. */ |
| 95 | if (*lib_version < *wnt_version) { |
| 96 | return 1; |
| 97 | } |
| 98 | lib_version++; |
| 99 | wnt_version++; |
| 100 | } |
| 101 | return 0; |
| 102 | ]])], [ |
| 103 | success=yes |
| 104 | ]) |
| 105 | AC_LANG_POP([C]) |
| 106 | |
| 107 | # Restore flags. |
| 108 | CPPFLAGS="$CPPFLAGS_SAVED" |
| 109 | LDFLAGS="$LDFLAGS_SAVED" |
| 110 | LIBS="$LIBS_SAVED" |
| 111 | LD_LIBRARY_PATH="$LD_LIBRARY_PATH_SAVED" |
| 112 | ]) |
| 113 | |
| 114 | |
| 115 | AC_DEFUN([AX_LIB_EVENT], |
| 116 | [ |
| 117 | |
| 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]), |
| 121 | [ |
| 122 | if test "x$withval" = "xno"; then |
| 123 | want_libevent="no" |
| 124 | elif test "x$withval" = "xyes"; then |
| 125 | want_libevent="yes" |
| 126 | ax_libevent_path="" |
| 127 | else |
| 128 | want_libevent="yes" |
| 129 | ax_libevent_path="$withval" |
| 130 | fi |
| 131 | ], |
| 132 | [ want_libevent="yes" ; ax_libevent_path="" ]) |
| 133 | |
| 134 | |
| 135 | if test "$want_libevent" = "yes"; then |
| 136 | WANT_LIBEVENT_VERSION=ifelse([$1], ,1.2,$1) |
| 137 | |
| 138 | AC_MSG_CHECKING(for libevent >= $WANT_LIBEVENT_VERSION) |
| 139 | |
| 140 | # Run tests. |
| 141 | if test -n "$ax_libevent_path"; then |
| 142 | AX_LIB_EVENT_DO_CHECK |
| 143 | else |
| 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 |
| 147 | break; |
| 148 | fi |
| 149 | done |
| 150 | fi |
| 151 | |
| 152 | if test "$success" != "yes" ; then |
| 153 | AC_MSG_RESULT(no) |
| 154 | LIBEVENT_CPPFLAGS="" |
| 155 | LIBEVENT_LDFLAGS="" |
| 156 | LIBEVENT_LIBS="" |
| 157 | else |
| 158 | AC_MSG_RESULT(yes) |
| 159 | AC_DEFINE(HAVE_LIBEVENT,,[define if libevent is available]) |
| 160 | fi |
| 161 | |
| 162 | ax_have_libevent="$success" |
| 163 | |
| 164 | AC_SUBST(LIBEVENT_CPPFLAGS) |
| 165 | AC_SUBST(LIBEVENT_LDFLAGS) |
| 166 | AC_SUBST(LIBEVENT_LIBS) |
| 167 | fi |
| 168 | |
| 169 | ]) |