libcurl.m4 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_CURL if a working libcurl setup is
  17. # found, and sets @CURL_LIB@ and @CURL_INCLUDE@ 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. # CURL_LIB="-lcurl" CURL_INCLUDE="-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. AC_DEFUN([AST_LIBCURL_CHECK_CONFIG],
  38. [
  39. AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
  40. AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
  41. AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
  42. AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
  43. AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
  44. AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
  45. AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
  46. AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
  47. AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
  48. AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
  49. AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
  50. AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
  51. AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
  52. AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
  53. AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
  54. AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
  55. AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
  56. AC_SUBST(PBX_CURL)
  57. AC_ARG_WITH(libcurl,
  58. AC_HELP_STRING([--with-libcurl=DIR],[look for the curl library in DIR]),
  59. [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
  60. if test "$_libcurl_with" != "no" ; then
  61. AC_PROG_AWK
  62. _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
  63. _libcurl_try_link=yes
  64. if test -d "$_libcurl_with" ; then
  65. CURL_INCLUDE="-I$withval/include"
  66. _libcurl_ldflags="-L$withval/lib"
  67. AC_PATH_PROG([_libcurl_config],[curl-config],["$withval/bin"],
  68. ["$withval/bin"])
  69. else
  70. AC_PATH_PROG([_libcurl_config],[curl-config])
  71. fi
  72. if test x$_libcurl_config != "x" ; then
  73. AC_CACHE_CHECK([for the version of libcurl],
  74. [libcurl_cv_lib_curl_version],
  75. [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
  76. _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
  77. _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
  78. if test $_libcurl_wanted -gt 0 ; then
  79. AC_CACHE_CHECK([for libcurl >= version $2],
  80. [libcurl_cv_lib_version_ok],
  81. [
  82. if test $_libcurl_version -ge $_libcurl_wanted ; then
  83. libcurl_cv_lib_version_ok=yes
  84. else
  85. libcurl_cv_lib_version_ok=no
  86. fi
  87. ])
  88. fi
  89. if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
  90. if test x"$CURL_INCLUDE" = "x" ; then
  91. CURL_INCLUDE=`$_libcurl_config --cflags`
  92. fi
  93. if test x"$CURL_LIB" = "x" ; then
  94. CURL_LIB=`$_libcurl_config --libs`
  95. # This is so silly, but Apple actually has a bug in their
  96. # curl-config script. Fixed in Tiger, but there are still
  97. # lots of Panther installs around.
  98. case "${host}" in
  99. powerpc-apple-darwin7*)
  100. CURL_LIB=`echo $CURL_LIB | sed -e 's|-arch i386||g'`
  101. ;;
  102. esac
  103. fi
  104. # All curl-config scripts support --feature
  105. _libcurl_features=`$_libcurl_config --feature`
  106. # Is it modern enough to have --protocols? (7.12.4)
  107. if test $_libcurl_version -ge 461828 ; then
  108. _libcurl_protocols=`$_libcurl_config --protocols`
  109. fi
  110. else
  111. _libcurl_try_link=no
  112. fi
  113. unset _libcurl_wanted
  114. fi
  115. if test $_libcurl_try_link = yes ; then
  116. # we didn't find curl-config, so let's see if the user-supplied
  117. # link line (or failing that, "-lcurl") is enough.
  118. CURL_LIB=${CURL_LIB-"$_libcurl_ldflags -lcurl"}
  119. AC_CACHE_CHECK([whether libcurl is usable],
  120. [libcurl_cv_lib_curl_usable],
  121. [
  122. _libcurl_save_cppflags=$CPPFLAGS
  123. CPPFLAGS="$CURL_INCLUDE $CPPFLAGS"
  124. _libcurl_save_libs=$LIBS
  125. LIBS="$CURL_LIB $LIBS"
  126. AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <curl/curl.h>],[
  127. /* Try and use a few common options to force a failure if we are
  128. missing symbols or can't link. */
  129. int x;
  130. curl_easy_setopt(NULL,CURLOPT_URL,NULL);
  131. x=CURL_ERROR_SIZE;
  132. x=CURLOPT_WRITEFUNCTION;
  133. x=CURLOPT_FILE;
  134. x=CURLOPT_ERRORBUFFER;
  135. x=CURLOPT_STDERR;
  136. x=CURLOPT_VERBOSE;
  137. ])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
  138. CPPFLAGS=$_libcurl_save_cppflags
  139. LIBS=$_libcurl_save_libs
  140. unset _libcurl_save_cppflags
  141. unset _libcurl_save_libs
  142. ])
  143. if test $libcurl_cv_lib_curl_usable = yes ; then
  144. # Does curl_free() exist in this version of libcurl?
  145. # If not, fake it with free()
  146. _libcurl_save_cppflags=$CPPFLAGS
  147. CPPFLAGS="$CPPFLAGS $CURL_INCLUDE"
  148. _libcurl_save_libs=$LIBS
  149. LIBS="$LIBS $CURL_LIB"
  150. AC_CHECK_FUNC(curl_free,,
  151. AC_DEFINE(curl_free,free,
  152. [Define curl_free() as free() if our version of curl lacks curl_free.]))
  153. CPPFLAGS=$_libcurl_save_cppflags
  154. LIBS=$_libcurl_save_libs
  155. unset _libcurl_save_cppflags
  156. unset _libcurl_save_libs
  157. AC_DEFINE(HAVE_CURL,1,
  158. [Define to 1 if you have a functional curl library.])
  159. AC_SUBST(CURL_INCLUDE)
  160. AC_SUBST(CURL_LIB)
  161. PBX_CURL=1
  162. for _libcurl_feature in $_libcurl_features ; do
  163. AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
  164. eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
  165. done
  166. if test "x$_libcurl_protocols" = "x" ; then
  167. # We don't have --protocols, so just assume that all
  168. # protocols are available
  169. _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT"
  170. if test x$libcurl_feature_SSL = xyes ; then
  171. _libcurl_protocols="$_libcurl_protocols HTTPS"
  172. # FTPS wasn't standards-compliant until version
  173. # 7.11.0
  174. if test $_libcurl_version -ge 461568; then
  175. _libcurl_protocols="$_libcurl_protocols FTPS"
  176. fi
  177. fi
  178. fi
  179. for _libcurl_protocol in $_libcurl_protocols ; do
  180. AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
  181. eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
  182. done
  183. else
  184. unset CURL_LIB
  185. unset CURL_INCLUDE
  186. PBX_CURL=0
  187. fi
  188. fi
  189. unset _libcurl_try_link
  190. unset _libcurl_version_parse
  191. unset _libcurl_config
  192. unset _libcurl_feature
  193. unset _libcurl_features
  194. unset _libcurl_protocol
  195. unset _libcurl_protocols
  196. unset _libcurl_version
  197. unset _libcurl_ldflags
  198. fi
  199. if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
  200. # This is the IF-NO path
  201. ifelse([$4],,:,[$4])
  202. else
  203. # This is the IF-YES path
  204. ifelse([$3],,:,[$3])
  205. fi
  206. unset _libcurl_with
  207. ])dnl