e22038f5eb94e288f8525568277340ca9a029de6
[debian/amanda] / config / amanda / libs.m4
1 # OVERVIEW
2 #
3 #   This file contains macros that search for specific libraries that are
4 #   required or utilized by Amanda.
5
6 # SYNOPSIS
7 #
8 #   AMANDA_CHECK_LIBCURL
9 #
10 # OVERVIEW
11 #
12 #   Check for LIBCURL support.  Sets the shell variable HAVE_CURL to "yes" or
13 #   "no" depending on the result of the test.  If CURL is found, the necessary
14 #   compiler flags are added, and a few other type checks are performed.
15 #
16 #   Note that libcurl itself defines a number of useful symbols as well; see
17 #   the libcurl distribution for details.
18 #
19 AC_DEFUN([AMANDA_CHECK_LIBCURL], [
20     case "$host" in
21         sparc-sun-solaris2.10) # Solaris 10
22         # curl is not in the LD_LIBRARY_PATH on Solaris 10, so we search
23         # for it in a few common paths; we then extract the -L flags and
24         # translate them to -R flags, as required by the runtime linker.
25         AC_PATH_PROG(CURL_CONFIG, curl-config, [], $LOCSYSPATH:/opt/csw/bin:/usr/local/bin:/opt/local/bin)
26         if test -n "$CURL_CONFIG"; then
27             curlflags=`$CURL_CONFIG --libs 2>/dev/null`
28             for flag in curlflags; do
29                 case $flag in
30                     -L*) LDFLAGS="$LDFLAGS "`echo "x$flag" | sed -e 's/^x-L/-R/'`;;
31                 esac
32             done
33         fi
34         ;;
35     esac
36
37     LIBCURL_CHECK_CONFIG(yes, 7.10.0, HAVE_CURL=yes, HAVE_CURL=no)
38     if test x"$HAVE_CURL" = x"yes"; then
39         AMANDA_ADD_LIBS($LIBCURL)
40         AMANDA_ADD_CPPFLAGS($LIBCURL_CPPFLAGS)
41
42         AMANDA_CHECK_TYPE([curl_off_t], [off_t], [curl/curl.h])
43     fi
44 ])
45
46 # SYNOPSIS
47 #
48 #   AMANDA_CHECK_HMAC
49 #
50 # OVERVIEW
51 #
52 #   Check for HMAC support in -lcrypto.  If found, the shell
53 #   variable HAVE_HMAC will be set to 'yes'.  The appropriate one of
54 #   HAVE_OPENSSL_HMAC_H, HAVE_CRYPTO_HMAC_H, and HAVE_HMAC_H are also
55 #   defined via AC_CHECK_HEADERS.
56 #
57 AC_DEFUN([AMANDA_CHECK_HMAC], [
58     HAVE_HMAC=yes
59     AC_CHECK_LIB([crypto], [HMAC_CTX_init], [], [HAVE_HMAC=no])
60
61     found_hmac_h=no
62     AC_CHECK_HEADERS([openssl/hmac.h crypto/hmac.h hmac.h],
63                     [found_hmac_h=yes; break])
64     if test x"$found_hmac_h" != x"yes"; then
65         HAVE_HMAC=no
66     fi
67 ])
68
69 # SYNOPSIS
70 #
71 #   AMANDA_CHECK_NET_LIBS
72 #
73 # OVERIVEW
74 #
75 #   Check for the libraries we'll need to use sockets, etc.
76 #
77 AC_DEFUN([AMANDA_CHECK_NET_LIBS], [
78     # Make sure we don't use -lnsl and -lsun on Irix systems.
79     case "$host" in
80         *sgi-irix*)
81                             AC_CHECK_LIB(socket,main)
82                             ;;
83         *)
84                             AC_CHECK_LIB(resolv,main)
85                             AC_CHECK_LIB(nsl,main)
86                             AC_CHECK_LIB(socket,main)
87                             AC_CHECK_LIB(sun,main)
88                             ;;
89     esac
90 ])
91
92 # SYNOPSIS
93 #
94 #   AMANDA_CHECK_GLIB
95 #
96 # OVERVIEW
97 #
98 #   Search for glib.  This is basically a wrapper for AM_PATH_GLIB_2_0, with
99 #   the addition of system-specific configuration to convince Amanda to compile
100 #   "out of the box" on more boxes.
101 #
102 AC_DEFUN([AMANDA_CHECK_GLIB], [
103     # search for pkg-config, which the glib configuration uses, adding a few
104     # system-specific search paths.
105     AC_PATH_PROG(PKG_CONFIG, pkg-config, [], $LOCSYSPATH:/opt/csw/bin:/usr/local/bin:/opt/local/bin)
106
107     case "$host" in
108         sparc-sun-solaris2.8) # Solaris 8
109             # give the linker a runtime search path; pkg-config doesn't supply this.
110             # Users could also specify this with LD_LIBRARY_PATH to both ./configure
111             # and make.  Adding this support here makes straight './configure; make'
112             # "just work" on Solaris 8
113             if test -n "$PKG_CONFIG"; then
114                 glib_R_flag=`$PKG_CONFIG glib-2.0 --libs-only-L 2>/dev/null | sed -e 's/-L/-R/g'`
115                 LDFLAGS="$LDFLAGS $glib_R_flag"
116             fi
117             ;;
118     esac
119
120     AM_PATH_GLIB_2_0(2.2.0,,[
121         AC_MSG_ERROR(glib not found or too old; See http://wiki.zmanda.com/index.php/Installation for help)
122     ], gmodule gobject gthread)
123     # GLIB_CPPFLAGS is not set by autoconf, yet GLIB_CFLAGS contains what GLIB_CPPFLAGS should contain.
124     AMANDA_ADD_CPPFLAGS($GLIB_CFLAGS)
125     AMANDA_ADD_LIBS($GLIB_LIBS)
126 ])
127
128 # LIBCURL_CHECK_CONFIG is from the libcurl
129 # distribution and licensed under the BSD license:
130 # Copyright (c) 1996 - 2007, Daniel Stenberg, <daniel@haxx.se>.
131 #
132 # All rights reserved.
133 #
134 # Permission to use, copy, modify, and distribute this software for any purpose
135 # with or without fee is hereby granted, provided that the above copyright
136 # notice and this permission notice appear in all copies.
137 #
138 # LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION],
139 #                       [ACTION-IF-YES], [ACTION-IF-NO])
140 # ----------------------------------------------------------
141 #      David Shaw <dshaw@jabberwocky.com>   May-09-2006
142 #
143 # Checks for libcurl.  DEFAULT-ACTION is the string yes or no to
144 # specify whether to default to --with-libcurl or --without-libcurl.
145 # If not supplied, DEFAULT-ACTION is yes.  MINIMUM-VERSION is the
146 # minimum version of libcurl to accept.  Pass the version as a regular
147 # version number like 7.10.1. If not supplied, any version is
148 # accepted.  ACTION-IF-YES is a list of shell commands to run if
149 # libcurl was successfully found and passed the various tests.
150 # ACTION-IF-NO is a list of shell commands that are run otherwise.
151 # Note that using --without-libcurl does run ACTION-IF-NO.
152 #
153 # This macro #defines HAVE_LIBCURL if a working libcurl setup is
154 # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary
155 # values.  Other useful defines are LIBCURL_FEATURE_xxx where xxx are
156 # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy
157 # where yyy are the various protocols supported by libcurl.  Both xxx
158 # and yyy are capitalized.  See the list of AH_TEMPLATEs at the top of
159 # the macro for the complete list of possible defines.  Shell
160 # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also
161 # defined to 'yes' for those features and protocols that were found.
162 # Note that xxx and yyy keep the same capitalization as in the
163 # curl-config list (e.g. it's "HTTP" and not "http").
164 #
165 # Users may override the detected values by doing something like:
166 # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure
167 #
168 # For the sake of sanity, this macro assumes that any libcurl that is
169 # found is after version 7.7.2, the first version that included the
170 # curl-config script.  Note that it is very important for people
171 # packaging binary versions of libcurl to include this script!
172 # Without curl-config, we can only guess what protocols are available,
173 # or use curl_version_info to figure it out at runtime.
174
175 AC_DEFUN([LIBCURL_CHECK_CONFIG],
176 [
177   AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
178   AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
179   AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
180   AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
181   AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
182   AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
183   AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
184   AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
185
186   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
187   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
188   AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
189   AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
190   AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
191   AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
192   AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
193   AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
194   AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
195
196   AC_ARG_WITH(libcurl,
197      AC_HELP_STRING([--with-libcurl=DIR],[look for the curl library in DIR]),
198      [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
199
200   if test "$_libcurl_with" != "no" ; then
201
202      AC_PROG_AWK
203
204      _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
205
206      _libcurl_try_link=yes
207
208      if test -d "$_libcurl_with" ; then
209         LIBCURL_CPPFLAGS="-I$withval/include"
210         _libcurl_ldflags="-L$withval/lib"
211         AC_PATH_PROG([_libcurl_config],[curl-config],["$withval/bin"],["$withval/bin"])
212      else
213         AC_PATH_PROG([_libcurl_config],[curl-config])
214      fi
215
216      if test x$_libcurl_config != "x" ; then
217         AC_CACHE_CHECK([for the version of libcurl],
218            [libcurl_cv_lib_curl_version],
219            [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
220
221         _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
222         _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
223
224         if test $_libcurl_wanted -gt 0 ; then
225            AC_CACHE_CHECK([for libcurl >= version $2],
226               [libcurl_cv_lib_version_ok],
227               [
228               if test $_libcurl_version -ge $_libcurl_wanted ; then
229                  libcurl_cv_lib_version_ok=yes
230               else
231                  libcurl_cv_lib_version_ok=no
232               fi
233               ])
234         fi
235
236         if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
237            if test x"$LIBCURL_CPPFLAGS" = "x" ; then
238               LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
239            fi
240            if test x"$LIBCURL" = "x" ; then
241               LIBCURL=`$_libcurl_config --libs`
242
243               # This is so silly, but Apple actually has a bug in their
244               # curl-config script.  Fixed in Tiger, but there are still
245               # lots of Panther installs around.
246               case "${host}" in
247                  powerpc-apple-darwin7*)
248                     LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
249                  ;;
250               esac
251            fi
252
253            # All curl-config scripts support --feature
254            _libcurl_features=`$_libcurl_config --feature`
255
256            # Is it modern enough to have --protocols? (7.12.4)
257            if test $_libcurl_version -ge 461828 ; then
258               _libcurl_protocols=`$_libcurl_config --protocols`
259            fi
260         else
261            _libcurl_try_link=no
262         fi
263
264         unset _libcurl_wanted
265      fi
266
267      if test $_libcurl_try_link = yes ; then
268
269         # we didn't find curl-config, so let's see if the user-supplied
270         # link line (or failing that, "-lcurl") is enough.
271         LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"}
272
273         AC_CACHE_CHECK([whether libcurl is usable],
274            [libcurl_cv_lib_curl_usable],
275            [
276            _libcurl_save_cppflags=$CPPFLAGS
277            CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
278            _libcurl_save_libs=$LIBS
279            LIBS="$LIBCURL $LIBS"
280
281            AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <curl/curl.h>],[
282 /* Try and use a few common options to force a failure if we are
283    missing symbols or can't link. */
284 int x;
285 curl_easy_setopt(NULL,CURLOPT_URL,NULL);
286 x=CURL_ERROR_SIZE;
287 x=CURLOPT_WRITEFUNCTION;
288 x=CURLOPT_FILE;
289 x=CURLOPT_ERRORBUFFER;
290 x=CURLOPT_STDERR;
291 x=CURLOPT_VERBOSE;
292 ]),libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
293
294            CPPFLAGS=$_libcurl_save_cppflags
295            LIBS=$_libcurl_save_libs
296            unset _libcurl_save_cppflags
297            unset _libcurl_save_libs
298            ])
299
300         if test $libcurl_cv_lib_curl_usable = yes ; then
301
302            # Does curl_free() exist in this version of libcurl?
303            # If not, fake it with free()
304
305            _libcurl_save_cppflags=$CPPFLAGS
306            CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
307            _libcurl_save_libs=$LIBS
308            LIBS="$LIBS $LIBCURL"
309
310            AC_CHECK_FUNC(curl_free,,
311               AC_DEFINE(curl_free,free,
312                 [Define curl_free() as free() if our version of curl lacks curl_free.]))
313
314            CPPFLAGS=$_libcurl_save_cppflags
315            LIBS=$_libcurl_save_libs
316            unset _libcurl_save_cppflags
317            unset _libcurl_save_libs
318
319            AC_DEFINE(HAVE_LIBCURL,1,
320              [Define to 1 if you have a functional curl library.])
321            AC_SUBST(LIBCURL_CPPFLAGS)
322            AC_SUBST(LIBCURL)
323
324            for _libcurl_feature in $_libcurl_features ; do
325               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
326               eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
327            done
328
329            if test "x$_libcurl_protocols" = "x" ; then
330
331               # We don't have --protocols, so just assume that all
332               # protocols are available
333               _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT"
334
335               if test x$libcurl_feature_SSL = xyes ; then
336                  _libcurl_protocols="$_libcurl_protocols HTTPS"
337
338                  # FTPS wasn't standards-compliant until version
339                  # 7.11.0
340                  if test $_libcurl_version -ge 461568; then
341                     _libcurl_protocols="$_libcurl_protocols FTPS"
342                  fi
343               fi
344            fi
345
346            for _libcurl_protocol in $_libcurl_protocols ; do
347               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
348               eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
349            done
350         else
351            unset LIBCURL
352            unset LIBCURL_CPPFLAGS
353         fi
354      fi
355
356      unset _libcurl_try_link
357      unset _libcurl_version_parse
358      unset _libcurl_config
359      unset _libcurl_feature
360      unset _libcurl_features
361      unset _libcurl_protocol
362      unset _libcurl_protocols
363      unset _libcurl_version
364      unset _libcurl_ldflags
365   fi
366
367   if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
368      # This is the IF-NO path
369      ifelse([$4],,:,[$4])
370   else
371      # This is the IF-YES path
372      ifelse([$3],,:,[$3])
373   fi
374
375   unset _libcurl_with
376 ])dnl
377