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