1# LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION], 2# [ACTION-IF-YES], [ACTION-IF-NO]) 3# ---------------------------------------------------------- 4# David Shaw <dshaw@jabberwocky.com> May-09-2006 5# 6# Checks for libcurl. DEFAULT-ACTION is the string yes or no to 7# specify whether to default to --with-libcurl or --without-libcurl. 8# If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the 9# minimum version of libcurl to accept. Pass the version as a regular 10# version number like 7.10.1. If not supplied, any version is 11# accepted. ACTION-IF-YES is a list of shell commands to run if 12# libcurl was successfully found and passed the various tests. 13# ACTION-IF-NO is a list of shell commands that are run otherwise. 14# Note that using --without-libcurl does run ACTION-IF-NO. 15# 16# This macro #defines HAVE_LIBCURL if a working libcurl setup is 17# found, and sets @LIBCURL_LIBS@ and @LIBCURL_CFLAGS@ to the necessary 18# values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are 19# the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy 20# where yyy are the various protocols supported by libcurl. Both xxx 21# and yyy are capitalized. See the list of AH_TEMPLATEs at the top of 22# the macro for the complete list of possible defines. Shell 23# variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also 24# defined to 'yes' for those features and protocols that were found. 25# Note that xxx and yyy keep the same capitalization as in the 26# curl-config list (e.g. it's "HTTP" and not "http"). 27# 28# Users may override the detected values by doing something like: 29# LIBCURL_LIBS="-lcurl" LIBCURL_CFLAGS="-I/usr/myinclude" ./configure 30# 31# For the sake of sanity, this macro assumes that any libcurl that is 32# found is after version 7.7.2, the first version that included the 33# curl-config script. Note that it is very important for people 34# packaging binary versions of libcurl to include this script! 35# Without curl-config, we can only guess what protocols are available, 36# or use curl_version_info to figure it out at runtime. 37 38AC_DEFUN([LIBCURL_CHECK_CONFIG], 39[ 40 AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL]) 41 AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4]) 42 AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6]) 43 AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz]) 44 AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS]) 45 AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN]) 46 AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI]) 47 AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM]) 48 49 AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP]) 50 AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS]) 51 AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP]) 52 AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS]) 53 AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE]) 54 AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET]) 55 AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP]) 56 AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT]) 57 AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP]) 58 59 _libcurl_config="no" 60 61 AC_ARG_WITH(libcurl, 62 [ 63If you want to use cURL library: 64AC_HELP_STRING([--with-libcurl@<:@=DIR@:>@],[use cURL package @<:@default=no@:>@, optionally specify path to curl-config])], 65 [ 66 if test "x$withval" = "xno"; then 67 want_curl="no" 68 elif test "x$withval" = "xyes"; then 69 want_curl="yes" 70 else 71 want_curl="yes" 72 _libcurl_config=$withval 73 fi 74 ], 75 [want_curl=ifelse([$1],,[no],[$1])]) 76 77 if test "x$want_curl" != "xno"; then 78 79 AC_PROG_AWK 80 81 _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'" 82 83 _libcurl_try_link=no 84 85 AC_PATH_PROG([_libcurl_config], [curl-config], []) 86 87 if test -x "$_libcurl_config"; then 88 AC_CACHE_CHECK([for the version of libcurl], 89 [libcurl_cv_lib_curl_version], 90 [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`]) 91 92 _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse` 93 _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse` 94 95 if test $_libcurl_wanted -gt 0; then 96 AC_CACHE_CHECK([for libcurl >= version $2], 97 [libcurl_cv_lib_version_ok], 98 [ 99 if test $_libcurl_version -ge $_libcurl_wanted; then 100 libcurl_cv_lib_version_ok=yes 101 else 102 libcurl_cv_lib_version_ok=no 103 fi 104 ]) 105 fi 106 107 if test $_libcurl_wanted -eq 0 || test "x$libcurl_cv_lib_version_ok" = "xyes"; then 108 if test "x$LIBCURL_CFLAGS" = "x"; then 109 LIBCURL_CFLAGS=`$_libcurl_config --cflags` 110 fi 111 if test "x$LIBCURL_LIBS" = "x"; then 112 _full_libcurl_libs=`$_libcurl_config --libs` 113 for i in $_full_libcurl_libs; do 114 case $i in 115 -L*) 116 LIBCURL_LDFLAGS="$LIBCURL_LDFLAGS $i" 117 ;; 118 -l*) 119 LIBCURL_LIBS="$LIBCURL_LIBS $i" 120 ;; 121 esac 122 done 123 124 if test "x$enable_static" = "xyes"; then 125 _full_libcurl_libs=`$_libcurl_config --static-libs` 126 for i in $_full_libcurl_libs; do 127 case $i in 128 -lcurl) 129 ;; 130 -l*) 131 _lib_name=`echo "$i" | cut -b3-` 132 AC_CHECK_LIB($_lib_name , main,[ 133 LIBCURL_LIBS="$LIBCURL_LIBS $i" 134 ],[ 135 AC_MSG_ERROR([static library $_lib_name required for linking libcurl not found]) 136 ]) 137 138 ;; 139 esac 140 done 141 fi 142 143 _save_curl_cflags="$CFLAGS" 144 _save_curl_ldflags="$LDFLAGS" 145 _save_curl_libs="$LIBS" 146 CFLAGS="$CFLAGS $LIBCURL_CFLAGS" 147 LDFLAGS="$LDFLAGS $LIBCURL_LDFLAGS" 148 LIBS="$LIBS $LIBCURL_LIBS" 149 150 AC_CHECK_LIB(curl, main, , [AC_MSG_ERROR([libcurl library not found])]) 151 152 CFLAGS="$_save_curl_cflags" 153 LDFLAGS="$_save_curl_ldflags" 154 LIBS="$_save_curl_libs" 155 unset _save_curl_cflags 156 unset _save_curl_ldflags 157 unset _save_curl_libs 158 159 # This is so silly, but Apple actually has a bug in their 160 # curl-config script. Fixed in Tiger, but there are still 161 # lots of Panther installs around. 162 case "${host}" in 163 powerpc-apple-darwin7*) 164 LIBCURL_LIBS=`echo $LIBCURL_LIBS | sed -e 's|-arch i386||g'` 165 ;; 166 esac 167 fi 168 169 # All curl-config scripts support --feature 170 _libcurl_features=`$_libcurl_config --feature` 171 172 # Is it modern enough to have --protocols? (7.12.4) 173 if test $_libcurl_version -ge 461828; then 174 _libcurl_protocols=`$_libcurl_config --protocols` 175 fi 176 177 _libcurl_try_link=yes 178 fi 179 180 unset _libcurl_wanted 181 fi 182 if test "x$_libcurl_try_link" = "xyes"; then 183 # we didn't find curl-config, so let's see if the user-supplied 184 # link line (or failing that, "-lcurl") is enough. 185 LIBCURL_LIBS=${LIBCURL_LIBS-"$_libcurl_libs -lcurl"} 186 187 AC_CACHE_CHECK([whether libcurl is usable], 188 [libcurl_cv_lib_curl_usable], 189 [ 190 _save_curl_libs="${LIBS}" 191 _save_curl_ldflags="${LDFLAGS}" 192 _save_curl_cflags="${CFLAGS}" 193 LIBS="${LIBS} ${LIBCURL_LIBS}" 194 LDFLAGS="${LDFLAGS} ${LIBCURL_LDFLAGS}" 195 CFLAGS="${CFLAGS} ${LIBCURL_CFLAGS}" 196 197 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <curl/curl.h> 198#ifndef NULL 199#define NULL (void *)0 200#endif],[ 201/* Try and use a few common options to force a failure if we are 202 missing symbols or can't link. */ 203int x; 204curl_easy_setopt(NULL,CURLOPT_URL,NULL); 205x=CURL_ERROR_SIZE; 206x=CURLOPT_WRITEFUNCTION; 207x=CURLOPT_FILE; 208x=CURLOPT_ERRORBUFFER; 209x=CURLOPT_STDERR; 210x=CURLOPT_VERBOSE; 211])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no) 212 213 LIBS="${_save_curl_libs}" 214 LDFLAGS="${_save_curl_ldflags}" 215 CFLAGS="${_save_curl_cflags}" 216 unset _save_curl_libs 217 unset _save_curl_ldflags 218 unset _save_curl_cflags 219 ]) 220 221 if test "x$libcurl_cv_lib_curl_usable" = "xno"; then 222 link_mode="dynamic" 223 if test "x$enable_static" = "xyes"; then 224 link_mode="static" 225 fi 226 AC_MSG_ERROR([libcurl is not available for ${link_mode} linking]) 227 fi 228 229 # Does curl_free() exist in this version of libcurl? 230 # If not, fake it with free() 231 232 _save_curl_libs="${LIBS}" 233 _save_curl_ldflags="${LDFLAGS}" 234 _save_curl_cflags="${CFLAGS}" 235 LIBS="${LIBS} ${LIBCURL_LIBS}" 236 LDFLAGS="${LDFLAGS} ${LIBCURL_LDFLAGS}" 237 CFLAGS="${CFLAGS} ${LIBCURL_CFLAGS}" 238 239 AC_CHECK_FUNC(curl_free,, 240 AC_DEFINE(curl_free,free, 241 [Define curl_free() as free() if our version of curl lacks curl_free.])) 242 243 AC_CHECK_FUNC(curl_easy_escape, 244 AC_DEFINE(HAVE_FUNCTION_CURL_EASY_ESCAPE,1, 245 [Define to 1 if function 'curl_easy_escape' exists.])) 246 247 LIBS="${_save_curl_libs}" 248 LDFLAGS="${_save_curl_ldflags}" 249 CFLAGS="${_save_curl_cflags}" 250 unset _save_curl_libs 251 unset _save_curl_ldflags 252 unset _save_curl_cflags 253 254 AC_DEFINE(HAVE_LIBCURL,1, 255 [Define to 1 if you have a functional curl library.]) 256 AC_SUBST(LIBCURL_CFLAGS) 257 AC_SUBST(LIBCURL_LDFLAGS) 258 AC_SUBST(LIBCURL_LIBS) 259 found_curl="yes" 260 261 for _libcurl_feature in $_libcurl_features ; do 262 AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1]) 263 eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes 264 done 265 266 if test "x$_libcurl_protocols" = "x"; then 267 # We don't have --protocols, so just assume that all 268 # protocols are available 269 _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT" 270 271 if test "x$libcurl_feature_SSL" = "xyes"; then 272 _libcurl_protocols="$_libcurl_protocols HTTPS" 273 274 # FTPS wasn't standards-compliant until version 275 # 7.11.0 276 if test $_libcurl_version -ge 461568; then 277 _libcurl_protocols="$_libcurl_protocols FTPS" 278 fi 279 fi 280 fi 281 282 for _libcurl_protocol in $_libcurl_protocols ; do 283 AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1]) 284 eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes 285 done 286 else 287 unset LIBCURL_LIBS 288 unset LIBCURL_CFLAGS 289 fi 290 291 unset _libcurl_try_link 292 unset _libcurl_version_parse 293 unset _libcurl_config 294 unset _libcurl_feature 295 unset _libcurl_features 296 unset _libcurl_protocol 297 unset _libcurl_protocols 298 unset _libcurl_version 299 unset _libcurl_libs 300 fi 301 302 if test "x$want_curl" = "xno" || test "x$libcurl_cv_lib_curl_usable" != "xyes"; then 303 # This is the IF-NO path 304 ifelse([$4],,:,[$4]) 305 else 306 # This is the IF-YES path 307 ifelse([$3],,:,[$3]) 308 fi 309 310])dnl 311