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 |
David Reiss | f82aee5 | 2009-03-30 22:52:29 +0000 | [diff] [blame^] | 30 | dnl |
| 31 | dnl Copyright (C) 2009 David Reiss |
| 32 | dnl Copying and distribution of this file, with or without modification, |
| 33 | dnl are permitted in any medium without royalty provided the copyright |
| 34 | dnl notice and this notice are preserved. |
David Reiss | 79ae0f8 | 2007-09-17 21:15:47 +0000 | [diff] [blame] | 35 | |
| 36 | dnl Input: ax_libevent_path, WANT_LIBEVENT_VERSION |
| 37 | dnl Output: success=yes/no |
| 38 | AC_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 | |
| 119 | AC_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 Luciani | 9c983c2 | 2009-01-16 01:04:27 +0000 | [diff] [blame] | 148 | 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] | 149 | 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 | ]) |