chiark / gitweb /
doc: Document summary values of TOFU_STATS
[gnupg2.git] / m4 / libcurl.m4
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@ and @LIBCURL_CPPFLAGS@ 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="-lcurl" LIBCURL_CPPFLAGS="-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
38 AC_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   AC_ARG_WITH(libcurl,
60      AC_HELP_STRING([--with-libcurl=DIR],[look for the curl library in DIR]),
61      [_libcurl_with=$withval],[_libcurl_with=m4_if([$1],,[yes],[$1])])
62
63   if test "$_libcurl_with" != "no" ; then
64
65      AC_PROG_AWK
66
67      _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
68      # More recent versions of curl-config have a direct --vernum
69      # option, but we'd like this code to work with older versions as
70      # well, so just convert --version.
71      _libcurl_vernum_parse="eval $AWK '{printf \"0x%06X\",\$NF}'"
72
73      _libcurl_try_link=yes
74
75      if test -d "$_libcurl_with" ; then
76         LIBCURL_CPPFLAGS="-I$withval/include"
77         _libcurl_ldflags="-L$withval/lib"
78         if test -x "$withval/bin/curl-config" ; then
79           _libcurl_config="$withval/bin/curl-config"
80         else
81           _libcurl_config=
82         fi
83      else
84         AC_PATH_PROG([_libcurl_config],[curl-config])
85      fi
86
87      if test x$_libcurl_config != "x" ; 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 m4_if([$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_CPPFLAGS" = "x" ; then
109               LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
110            fi
111            if test x"$LIBCURL" = "x" ; then
112               LIBCURL=`$_libcurl_config --libs`
113
114               # This is so silly, but Apple actually has a bug in their
115               # curl-config script.  Fixed in Tiger, but there are still
116               # lots of Panther installs around.
117               case "${host}" in
118                  powerpc-apple-darwin7*)
119                     LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
120                  ;;
121               esac
122            fi
123
124            # All curl-config scripts support --feature
125            _libcurl_features=`$_libcurl_config --feature`
126
127            # Is it modern enough to have --protocols? (7.12.4)
128            if test $_libcurl_version -ge 461828 ; then
129               _libcurl_protocols=`$_libcurl_config --protocols`
130            fi
131         else
132            _libcurl_try_link=no
133         fi
134
135         unset _libcurl_wanted
136      fi
137
138      if test $_libcurl_try_link = yes ; then
139
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
144         AC_CACHE_CHECK([whether libcurl is usable],
145            [libcurl_cv_lib_curl_usable],
146            [
147            _libcurl_save_cppflags=$CPPFLAGS
148            CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
149            _libcurl_save_libs=$LIBS
150            LIBS="$LIBCURL $LIBS"
151
152            AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <curl/curl.h>]],[[
153 /* Try and use a few common options to force a failure if we are
154    missing symbols or cannot link. */
155 int x;
156 curl_easy_setopt(NULL,CURLOPT_URL,NULL);
157 x=CURL_ERROR_SIZE;
158 x=CURLOPT_WRITEFUNCTION;
159 x=CURLOPT_FILE;
160 x=CURLOPT_ERRORBUFFER;
161 x=CURLOPT_STDERR;
162 x=CURLOPT_VERBOSE;
163 ]])],[libcurl_cv_lib_curl_usable=yes],[libcurl_cv_lib_curl_usable=no])
164
165            CPPFLAGS=$_libcurl_save_cppflags
166            LIBS=$_libcurl_save_libs
167            unset _libcurl_save_cppflags
168            unset _libcurl_save_libs
169            ])
170
171         if test $libcurl_cv_lib_curl_usable = yes ; then
172
173            # Does curl_free() exist in this version of libcurl?
174            # If not, fake it with free()
175
176            _libcurl_save_cppflags=$CPPFLAGS
177            CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
178            _libcurl_save_libs=$LIBS
179            LIBS="$LIBS $LIBCURL"
180
181            AC_CHECK_FUNC(curl_free,,
182               AC_DEFINE(curl_free,free,
183                 [Define curl_free() as free() if our version of curl lacks curl_free.]))
184
185            CPPFLAGS=$_libcurl_save_cppflags
186            LIBS=$_libcurl_save_libs
187            unset _libcurl_save_cppflags
188            unset _libcurl_save_libs
189
190            AC_DEFINE(HAVE_LIBCURL,1,
191              [Define to 1 if you have a functional curl library.])
192            AC_SUBST(LIBCURL_CPPFLAGS)
193            AC_SUBST(LIBCURL)
194
195            _libcurl_vernum=`echo $_libcurl_version | $_libcurl_vernum_parse`
196
197            AC_DEFINE_UNQUOTED(LIBCURL_VERNUM, $_libcurl_vernum,
198                   [The version of the libcurl library in packed hex form])
199
200            for _libcurl_feature in $_libcurl_features ; do
201               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
202               eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
203            done
204
205            if test "x$_libcurl_protocols" = "x" ; then
206
207               # We don't have --protocols, so just assume that all
208               # protocols are available
209               _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT"
210
211               if test x$libcurl_feature_SSL = xyes ; then
212                  _libcurl_protocols="$_libcurl_protocols HTTPS"
213
214                  # FTPS wasn't standards-compliant until version
215                  # 7.11.0
216                  if test $_libcurl_version -ge 461568; then
217                     _libcurl_protocols="$_libcurl_protocols FTPS"
218                  fi
219               fi
220            fi
221
222            for _libcurl_protocol in $_libcurl_protocols ; do
223               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
224               eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
225            done
226         else
227            unset LIBCURL
228            unset LIBCURL_CPPFLAGS
229         fi
230      fi
231
232      unset _libcurl_try_link
233      unset _libcurl_version_parse
234      unset _libcurl_config
235      unset _libcurl_feature
236      unset _libcurl_features
237      unset _libcurl_protocol
238      unset _libcurl_protocols
239      unset _libcurl_version
240      unset _libcurl_vernum
241      unset _libcurl_ldflags
242   fi
243
244   if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
245      # This is the IF-NO path
246      m4_if([$4],,:,[$4])
247   else
248      # This is the IF-YES path
249      m4_if([$3],,:,[$3])
250   fi
251
252   unset _libcurl_with
253 ])dnl