bcf6f3bc13cf87e8eb278e29e8047ebad31ff4e0
[supertux.git] / mk / autoconf / 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 # ----------------------------------------------------------------------------
7 # libcurl.m4 - autoconf script to detect libcurl
8 # Copyright (C) 2006 David Shaw <dshaw@jabberwocky.com>
9 #
10 # All rights reserved.
11
12 # Permission to use, copy, modify, and distribute this software for any purpose
13 # with or without fee is hereby granted, provided that the above copyright
14 # notice and this permission notice appear in all copies.
15
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
19 # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 # OR OTHER DEALINGS IN THE SOFTWARE.
23
24 # Except as contained in this notice, the name of a copyright holder shall not
25 # be used in advertising or otherwise to promote the sale, use or other dealings
26 # in this Software without prior written authorization of the copyright holder.
27 # ----------------------------------------------------------------------------
28 #
29 # Checks for libcurl.  DEFAULT-ACTION is the string yes or no to
30 # specify whether to default to --with-libcurl or --without-libcurl.
31 # If not supplied, DEFAULT-ACTION is yes.  MINIMUM-VERSION is the
32 # minimum version of libcurl to accept.  Pass the version as a regular
33 # version number like 7.10.1. If not supplied, any version is
34 # accepted.  ACTION-IF-YES is a list of shell commands to run if
35 # libcurl was successfully found and passed the various tests.
36 # ACTION-IF-NO is a list of shell commands that are run otherwise.
37 # Note that using --without-libcurl does run ACTION-IF-NO.
38 #
39 # This macro #defines HAVE_LIBCURL if a working libcurl setup is
40 # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary
41 # values.  Other useful defines are LIBCURL_FEATURE_xxx where xxx are
42 # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy
43 # where yyy are the various protocols supported by libcurl.  Both xxx
44 # and yyy are capitalized.  See the list of AH_TEMPLATEs at the top of
45 # the macro for the complete list of possible defines.  Shell
46 # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also
47 # defined to 'yes' for those features and protocols that were found.
48 # Note that xxx and yyy keep the same capitalization as in the
49 # curl-config list (e.g. it's "HTTP" and not "http").
50 #
51 # Users may override the detected values by doing something like:
52 # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure
53 #
54 # For the sake of sanity, this macro assumes that any libcurl that is
55 # found is after version 7.7.2, the first version that included the
56 # curl-config script.  Note that it is very important for people
57 # packaging binary versions of libcurl to include this script!
58 # Without curl-config, we can only guess what protocols are available,
59 # or use curl_version_info to figure it out at runtime.
60
61 AC_DEFUN([LIBCURL_CHECK_CONFIG],
62 [
63   AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
64   AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
65   AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
66   AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
67   AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
68   AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
69   AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
70   AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
71
72   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
73   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
74   AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
75   AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
76   AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
77   AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
78   AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
79   AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
80   AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
81
82   AC_ARG_WITH(libcurl,
83      AC_HELP_STRING([--with-libcurl=DIR],[look for the curl library in DIR]),
84      [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
85
86   if test "$_libcurl_with" != "no" ; then
87
88      AC_PROG_AWK
89
90      _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
91
92      _libcurl_try_link=yes
93
94      if test -d "$_libcurl_with" ; then
95         LIBCURL_CPPFLAGS="-I$withval/include"
96         _libcurl_ldflags="-L$withval/lib"
97         AC_PATH_PROG([_libcurl_config],["$withval/bin/curl-config"])
98      else
99         AC_PATH_PROG([_libcurl_config],[curl-config])
100      fi
101
102      if test x$_libcurl_config != "x" ; then
103         AC_CACHE_CHECK([for the version of libcurl],
104            [libcurl_cv_lib_curl_version],
105            [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
106
107         _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
108         _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
109
110         if test $_libcurl_wanted -gt 0 ; then
111            AC_CACHE_CHECK([for libcurl >= version $2],
112               [libcurl_cv_lib_version_ok],
113               [
114               if test $_libcurl_version -ge $_libcurl_wanted ; then
115                  libcurl_cv_lib_version_ok=yes
116               else
117                  libcurl_cv_lib_version_ok=no
118               fi
119               ])
120         fi
121
122         if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
123            if test x"$LIBCURL_CPPFLAGS" = "x" ; then
124               LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
125            fi
126            if test x"$LIBCURL" = "x" ; then
127               LIBCURL=`$_libcurl_config --libs`
128
129               # This is so silly, but Apple actually has a bug in their
130               # curl-config script.  Fixed in Tiger, but there are still
131               # lots of Panther installs around.
132               case "${host}" in
133                  powerpc-apple-darwin7*)
134                     LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
135                  ;;
136               esac
137            fi
138
139            # All curl-config scripts support --feature
140            _libcurl_features=`$_libcurl_config --feature`
141
142            # Is it modern enough to have --protocols? (7.12.4)
143            if test $_libcurl_version -ge 461828 ; then
144               _libcurl_protocols=`$_libcurl_config --protocols`
145            fi
146         else
147            _libcurl_try_link=no
148         fi
149
150         unset _libcurl_wanted
151      fi
152
153      if test $_libcurl_try_link = yes ; then
154
155         # we didn't find curl-config, so let's see if the user-supplied
156         # link line (or failing that, "-lcurl") is enough.
157         LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"}
158
159         AC_CACHE_CHECK([whether libcurl is usable],
160            [libcurl_cv_lib_curl_usable],
161            [
162            _libcurl_save_cppflags=$CPPFLAGS
163            CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
164            _libcurl_save_libs=$LIBS
165            LIBS="$LIBCURL $LIBS"
166
167            AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <curl/curl.h>],[
168 /* Try and use a few common options to force a failure if we are
169    missing symbols or can't link. */
170 int x;
171 curl_easy_setopt(NULL,CURLOPT_URL,NULL);
172 x=CURL_ERROR_SIZE;
173 x=CURLOPT_WRITEFUNCTION;
174 x=CURLOPT_FILE;
175 x=CURLOPT_ERRORBUFFER;
176 x=CURLOPT_STDERR;
177 x=CURLOPT_VERBOSE;
178 ]),libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
179
180            CPPFLAGS=$_libcurl_save_cppflags
181            LIBS=$_libcurl_save_libs
182            unset _libcurl_save_cppflags
183            unset _libcurl_save_libs
184            ])
185
186         if test $libcurl_cv_lib_curl_usable = yes ; then
187
188            # Does curl_free() exist in this version of libcurl?
189            # If not, fake it with free()
190
191            _libcurl_save_cppflags=$CPPFLAGS
192            CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
193            _libcurl_save_libs=$LIBS
194            LIBS="$LIBS $LIBCURL"
195
196            AC_CHECK_FUNC(curl_free,,
197               AC_DEFINE(curl_free,free,
198                 [Define curl_free() as free() if our version of curl lacks curl_free.]))
199
200            CPPFLAGS=$_libcurl_save_cppflags
201            LIBS=$_libcurl_save_libs
202            unset _libcurl_save_cppflags
203            unset _libcurl_save_libs
204
205            AC_DEFINE(HAVE_LIBCURL,1,
206              [Define to 1 if you have a functional curl library.])
207            AC_SUBST(LIBCURL_CPPFLAGS)
208            AC_SUBST(LIBCURL)
209
210            for _libcurl_feature in $_libcurl_features ; do
211               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
212               eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
213            done
214
215            if test "x$_libcurl_protocols" = "x" ; then
216
217               # We don't have --protocols, so just assume that all
218               # protocols are available
219               _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT"
220
221               if test x$libcurl_feature_SSL = xyes ; then
222                  _libcurl_protocols="$_libcurl_protocols HTTPS"
223
224                  # FTPS wasn't standards-compliant until version
225                  # 7.11.0
226                  if test $_libcurl_version -ge 461568; then
227                     _libcurl_protocols="$_libcurl_protocols FTPS"
228                  fi
229               fi
230            fi
231
232            for _libcurl_protocol in $_libcurl_protocols ; do
233               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
234               eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
235            done
236         else
237            unset LIBCURL
238            unset LIBCURL_CPPFLAGS
239         fi
240      fi
241
242      unset _libcurl_try_link
243      unset _libcurl_version_parse
244      unset _libcurl_config
245      unset _libcurl_feature
246      unset _libcurl_features
247      unset _libcurl_protocol
248      unset _libcurl_protocols
249      unset _libcurl_version
250      unset _libcurl_ldflags
251   fi
252
253   if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
254      # This is the IF-NO path
255      ifelse([$4],,:,[$4])
256   else
257      # This is the IF-YES path
258      ifelse([$3],,:,[$3])
259   fi
260
261   unset _libcurl_with
262 ])dnl