libcurl.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 2006 - 2020, David Shaw <dshaw@jabberwocky.com>
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.haxx.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. ###########################################################################
  22. # LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION],
  23. # [ACTION-IF-YES], [ACTION-IF-NO])
  24. # ----------------------------------------------------------
  25. # David Shaw <dshaw@jabberwocky.com> May-09-2006
  26. #
  27. # Checks for libcurl. DEFAULT-ACTION is the string yes or no to
  28. # specify whether to default to --with-libcurl or --without-libcurl.
  29. # If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the
  30. # minimum version of libcurl to accept. Pass the version as a regular
  31. # version number like 7.10.1. If not supplied, any version is
  32. # accepted. ACTION-IF-YES is a list of shell commands to run if
  33. # libcurl was successfully found and passed the various tests.
  34. # ACTION-IF-NO is a list of shell commands that are run otherwise.
  35. # Note that using --without-libcurl does run ACTION-IF-NO.
  36. #
  37. # This macro #defines HAVE_LIBCURL if a working libcurl setup is
  38. # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary
  39. # values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are
  40. # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy
  41. # where yyy are the various protocols supported by libcurl. Both xxx
  42. # and yyy are capitalized. See the list of AH_TEMPLATEs at the top of
  43. # the macro for the complete list of possible defines. Shell
  44. # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also
  45. # defined to 'yes' for those features and protocols that were found.
  46. # Note that xxx and yyy keep the same capitalization as in the
  47. # curl-config list (e.g. it's "HTTP" and not "http").
  48. #
  49. # Users may override the detected values by doing something like:
  50. # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure
  51. #
  52. # For the sake of sanity, this macro assumes that any libcurl that is
  53. # found is after version 7.7.2, the first version that included the
  54. # curl-config script. Note that it is very important for people
  55. # packaging binary versions of libcurl to include this script!
  56. # Without curl-config, we can only guess what protocols are available,
  57. # or use curl_version_info to figure it out at runtime.
  58. AC_DEFUN([LIBCURL_CHECK_CONFIG],
  59. [
  60. AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
  61. AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
  62. AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
  63. AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
  64. AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
  65. AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
  66. AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
  67. AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
  68. AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
  69. AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
  70. AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
  71. AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
  72. AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
  73. AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
  74. AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
  75. AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
  76. AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
  77. AH_TEMPLATE([LIBCURL_PROTOCOL_RTSP],[Defined if libcurl supports RTSP])
  78. AH_TEMPLATE([LIBCURL_PROTOCOL_POP3],[Defined if libcurl supports POP3])
  79. AH_TEMPLATE([LIBCURL_PROTOCOL_IMAP],[Defined if libcurl supports IMAP])
  80. AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP])
  81. AC_ARG_WITH(libcurl,
  82. AS_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]),
  83. [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
  84. if test "$_libcurl_with" != "no" ; then
  85. AC_PROG_AWK
  86. _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
  87. _libcurl_try_link=yes
  88. if test -d "$_libcurl_with" ; then
  89. LIBCURL_CPPFLAGS="-I$withval/include"
  90. _libcurl_ldflags="-L$withval/lib"
  91. AC_PATH_PROG([_libcurl_config],[curl-config],[],
  92. ["$withval/bin"])
  93. else
  94. AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH])
  95. fi
  96. if test x$_libcurl_config != "x" ; then
  97. AC_CACHE_CHECK([for the version of libcurl],
  98. [libcurl_cv_lib_curl_version],
  99. [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
  100. _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
  101. _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
  102. if test $_libcurl_wanted -gt 0 ; then
  103. AC_CACHE_CHECK([for libcurl >= version $2],
  104. [libcurl_cv_lib_version_ok],
  105. [
  106. if test $_libcurl_version -ge $_libcurl_wanted ; then
  107. libcurl_cv_lib_version_ok=yes
  108. else
  109. libcurl_cv_lib_version_ok=no
  110. fi
  111. ])
  112. fi
  113. if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
  114. if test x"$LIBCURL_CPPFLAGS" = "x" ; then
  115. LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
  116. fi
  117. if test x"$LIBCURL" = "x" ; then
  118. LIBCURL=`$_libcurl_config --libs`
  119. # This is so silly, but Apple actually has a bug in their
  120. # curl-config script. Fixed in Tiger, but there are still
  121. # lots of Panther installs around.
  122. case "${host}" in
  123. powerpc-apple-darwin7*)
  124. LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
  125. ;;
  126. esac
  127. fi
  128. # All curl-config scripts support --feature
  129. _libcurl_features=`$_libcurl_config --feature`
  130. # Is it modern enough to have --protocols? (7.12.4)
  131. if test $_libcurl_version -ge 461828 ; then
  132. _libcurl_protocols=`$_libcurl_config --protocols`
  133. fi
  134. else
  135. _libcurl_try_link=no
  136. fi
  137. unset _libcurl_wanted
  138. fi
  139. if test $_libcurl_try_link = yes ; then
  140. # we didn't find curl-config, so let's see if the user-supplied
  141. # link line (or failing that, "-lcurl") is enough.
  142. LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"}
  143. AC_CACHE_CHECK([whether libcurl is usable],
  144. [libcurl_cv_lib_curl_usable],
  145. [
  146. _libcurl_save_cppflags=$CPPFLAGS
  147. CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
  148. _libcurl_save_libs=$LIBS
  149. LIBS="$LIBCURL $LIBS"
  150. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <curl/curl.h>]],[[
  151. /* Try and use a few common options to force a failure if we are
  152. missing symbols or can't link. */
  153. int x;
  154. curl_easy_setopt(NULL,CURLOPT_URL,NULL);
  155. x=CURL_ERROR_SIZE;
  156. x=CURLOPT_WRITEFUNCTION;
  157. x=CURLOPT_WRITEDATA;
  158. x=CURLOPT_ERRORBUFFER;
  159. x=CURLOPT_STDERR;
  160. x=CURLOPT_VERBOSE;
  161. if (x) {;}
  162. ]])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
  163. CPPFLAGS=$_libcurl_save_cppflags
  164. LIBS=$_libcurl_save_libs
  165. unset _libcurl_save_cppflags
  166. unset _libcurl_save_libs
  167. ])
  168. if test $libcurl_cv_lib_curl_usable = yes ; then
  169. # Does curl_free() exist in this version of libcurl?
  170. # If not, fake it with free()
  171. _libcurl_save_cppflags=$CPPFLAGS
  172. CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
  173. _libcurl_save_libs=$LIBS
  174. LIBS="$LIBS $LIBCURL"
  175. AC_CHECK_FUNC(curl_free,,
  176. AC_DEFINE(curl_free,free,
  177. [Define curl_free() as free() if our version of curl lacks curl_free.]))
  178. CPPFLAGS=$_libcurl_save_cppflags
  179. LIBS=$_libcurl_save_libs
  180. unset _libcurl_save_cppflags
  181. unset _libcurl_save_libs
  182. AC_DEFINE(HAVE_LIBCURL,1,
  183. [Define to 1 if you have a functional curl library.])
  184. AC_SUBST(LIBCURL_CPPFLAGS)
  185. AC_SUBST(LIBCURL)
  186. for _libcurl_feature in $_libcurl_features ; do
  187. AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
  188. eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
  189. done
  190. if test "x$_libcurl_protocols" = "x" ; then
  191. # We don't have --protocols, so just assume that all
  192. # protocols are available
  193. _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP"
  194. if test x$libcurl_feature_SSL = xyes ; then
  195. _libcurl_protocols="$_libcurl_protocols HTTPS"
  196. # FTPS wasn't standards-compliant until version
  197. # 7.11.0 (0x070b00 == 461568)
  198. if test $_libcurl_version -ge 461568; then
  199. _libcurl_protocols="$_libcurl_protocols FTPS"
  200. fi
  201. fi
  202. # RTSP, IMAP, POP3 and SMTP were added in
  203. # 7.20.0 (0x071400 == 463872)
  204. if test $_libcurl_version -ge 463872; then
  205. _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP"
  206. fi
  207. fi
  208. for _libcurl_protocol in $_libcurl_protocols ; do
  209. AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
  210. eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
  211. done
  212. else
  213. unset LIBCURL
  214. unset LIBCURL_CPPFLAGS
  215. fi
  216. fi
  217. unset _libcurl_try_link
  218. unset _libcurl_version_parse
  219. unset _libcurl_config
  220. unset _libcurl_feature
  221. unset _libcurl_features
  222. unset _libcurl_protocol
  223. unset _libcurl_protocols
  224. unset _libcurl_version
  225. unset _libcurl_ldflags
  226. fi
  227. if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
  228. # This is the IF-NO path
  229. ifelse([$4],,:,[$4])
  230. else
  231. # This is the IF-YES path
  232. ifelse([$3],,:,[$3])
  233. fi
  234. unset _libcurl_with
  235. ])dnl