Imported Upstream version 3.3.0
[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])
102     AC_ARG_VAR(GLIB_LIBS, [libraries to build with glib; disables use of pkg-config])
103     AC_ARG_VAR(GLIB_GENMARSHAL, [genmarshal binary to use with glib; disables use of pkg-config])
104     AC_ARG_VAR(GOBJECT_QUERY, [gobject_query binary to use with glib; disables use of pkg-config])
105     AC_ARG_VAR(GLIB_MKENUMS, [mkenums binary to use with glib; disables use of pkg-config])
106
107     # if any of the precious variables are set, disable the pkg-config run
108     explicit_glib=no
109     test x"$GLIB_CFLAGS" = x"" || explicit_glib=yes
110     test x"$GLIB_LIBS" = x"" || explicit_glib=yes
111     test x"$GLIB_GENMARSHAL" = x"" || explicit_glib=yes
112     test x"$GOBJECT_QUERY" = x"" || explicit_glib=yes
113     test x"$GLIB_MKENUMS" = x"" || explicit_glib=yes
114
115     if test x"$explicit_glib" = x"no"; then
116         # search for pkg-config, which the glib configuration uses, adding a few
117         # system-specific search paths.
118         AC_PATH_PROG(PKG_CONFIG, pkg-config, [], $LOCSYSPATH:/opt/csw/bin:/usr/local/bin:/opt/local/bin)
119
120         case "$host" in
121             sparc-sun-solaris2.8) # Solaris 8
122                 # give the linker a runtime search path; pkg-config doesn't supply this.
123                 # Users could also specify this with LD_LIBRARY_PATH to both ./configure
124                 # and make.  Adding this support here makes straight './configure; make'
125                 # "just work" on Solaris 8
126                 if test -n "$PKG_CONFIG"; then
127                     glib_R_flag=`$PKG_CONFIG glib-2.0 --libs-only-L 2>/dev/null | sed -e 's/-L/-R/g'`
128                     LDFLAGS="$LDFLAGS $glib_R_flag"
129                 fi
130                 ;;
131         esac
132
133         AM_PATH_GLIB_2_0(2.2.0,,[
134             AC_MSG_ERROR(glib not found or too old; See http://wiki.zmanda.com/index.php/Installation for help)
135         ], gmodule gobject gthread)
136     else
137         AC_MSG_ERROR(explicit glib)
138     fi
139
140     # GLIB_CPPFLAGS is not set by autoconf, yet GLIB_CFLAGS contains what GLIB_CPPFLAGS should contain.
141     AMANDA_ADD_CPPFLAGS($GLIB_CFLAGS)
142     AMANDA_ADD_LIBS($GLIB_LIBS)
143 ])
144
145 # LIBCURL_CHECK_CONFIG is from the libcurl
146 # distribution and licensed under the BSD license:
147 # Copyright (c) 1996 - 2007, Daniel Stenberg, <daniel@haxx.se>.
148 #
149 # All rights reserved.
150 #
151 # Permission to use, copy, modify, and distribute this software for any purpose
152 # with or without fee is hereby granted, provided that the above copyright
153 # notice and this permission notice appear in all copies.
154 #
155 # LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION],
156 #                       [ACTION-IF-YES], [ACTION-IF-NO])
157 # ----------------------------------------------------------
158 #      David Shaw <dshaw@jabberwocky.com>   May-09-2006
159 #
160 # Checks for libcurl.  DEFAULT-ACTION is the string yes or no to
161 # specify whether to default to --with-libcurl or --without-libcurl.
162 # If not supplied, DEFAULT-ACTION is yes.  MINIMUM-VERSION is the
163 # minimum version of libcurl to accept.  Pass the version as a regular
164 # version number like 7.10.1. If not supplied, any version is
165 # accepted.  ACTION-IF-YES is a list of shell commands to run if
166 # libcurl was successfully found and passed the various tests.
167 # ACTION-IF-NO is a list of shell commands that are run otherwise.
168 # Note that using --without-libcurl does run ACTION-IF-NO.
169 #
170 # This macro #defines HAVE_LIBCURL if a working libcurl setup is
171 # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary
172 # values.  Other useful defines are LIBCURL_FEATURE_xxx where xxx are
173 # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy
174 # where yyy are the various protocols supported by libcurl.  Both xxx
175 # and yyy are capitalized.  See the list of AH_TEMPLATEs at the top of
176 # the macro for the complete list of possible defines.  Shell
177 # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also
178 # defined to 'yes' for those features and protocols that were found.
179 # Note that xxx and yyy keep the same capitalization as in the
180 # curl-config list (e.g. it's "HTTP" and not "http").
181 #
182 # Users may override the detected values by doing something like:
183 # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure
184 #
185 # For the sake of sanity, this macro assumes that any libcurl that is
186 # found is after version 7.7.2, the first version that included the
187 # curl-config script.  Note that it is very important for people
188 # packaging binary versions of libcurl to include this script!
189 # Without curl-config, we can only guess what protocols are available,
190 # or use curl_version_info to figure it out at runtime.
191
192 AC_DEFUN([LIBCURL_CHECK_CONFIG],
193 [
194   AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL])
195   AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4])
196   AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6])
197   AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz])
198   AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS])
199   AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN])
200   AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI])
201   AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM])
202
203   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP])
204   AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS])
205   AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP])
206   AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS])
207   AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE])
208   AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET])
209   AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP])
210   AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT])
211   AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP])
212
213   AC_ARG_WITH(libcurl,
214      AC_HELP_STRING([--with-libcurl=PREFIX],
215         [look for the curl library in PREFIX/lib and headers in PREFIX/include]),
216      [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])])
217
218   if test "$_libcurl_with" != "no" ; then
219
220      AC_PROG_AWK
221
222      _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
223
224      _libcurl_try_link=yes
225
226      if test -d "$_libcurl_with" ; then
227         LIBCURL_CPPFLAGS="-I$withval/include"
228         _libcurl_ldflags="-L$withval/lib"
229         AC_PATH_PROG([_libcurl_config],[curl-config],[],["$withval/bin"])
230      else
231         AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH])
232      fi
233
234      if test x$_libcurl_config != "x" ; then
235         AC_CACHE_CHECK([for the version of libcurl],
236            [libcurl_cv_lib_curl_version],
237            [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`])
238
239         _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse`
240         _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse`
241
242         if test $_libcurl_wanted -gt 0 ; then
243            AC_CACHE_CHECK([for libcurl >= version $2],
244               [libcurl_cv_lib_version_ok],
245               [
246               if test $_libcurl_version -ge $_libcurl_wanted ; then
247                  libcurl_cv_lib_version_ok=yes
248               else
249                  libcurl_cv_lib_version_ok=no
250               fi
251               ])
252         fi
253
254         if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then
255            if test x"$LIBCURL_CPPFLAGS" = "x" ; then
256               LIBCURL_CPPFLAGS=`$_libcurl_config --cflags`
257            fi
258            if test x"$LIBCURL" = "x" ; then
259               LIBCURL=`$_libcurl_config --libs`
260
261               # This is so silly, but Apple actually has a bug in their
262               # curl-config script.  Fixed in Tiger, but there are still
263               # lots of Panther installs around.
264               case "${host}" in
265                  powerpc-apple-darwin7*)
266                     LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'`
267                  ;;
268               esac
269            fi
270
271            # All curl-config scripts support --feature
272            _libcurl_features=`$_libcurl_config --feature`
273
274            # Is it modern enough to have --protocols? (7.12.4)
275            if test $_libcurl_version -ge 461828 ; then
276               _libcurl_protocols=`$_libcurl_config --protocols`
277            fi
278         else
279            _libcurl_try_link=no
280         fi
281
282         unset _libcurl_wanted
283      fi
284
285      if test $_libcurl_try_link = yes ; then
286
287         # we didn't find curl-config, so let's see if the user-supplied
288         # link line (or failing that, "-lcurl") is enough.
289         LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"}
290
291         AC_CACHE_CHECK([whether libcurl is usable],
292            [libcurl_cv_lib_curl_usable],
293            [
294            _libcurl_save_cppflags=$CPPFLAGS
295            CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS"
296            _libcurl_save_libs=$LIBS
297            LIBS="$LIBCURL $LIBS"
298
299            AC_LINK_IFELSE(AC_LANG_PROGRAM([#include <curl/curl.h>],[
300 /* Try and use a few common options to force a failure if we are
301    missing symbols or can't link. */
302 int x;
303 curl_easy_setopt(NULL,CURLOPT_URL,NULL);
304 x=CURL_ERROR_SIZE;
305 x=CURLOPT_WRITEFUNCTION;
306 x=CURLOPT_FILE;
307 x=CURLOPT_ERRORBUFFER;
308 x=CURLOPT_STDERR;
309 x=CURLOPT_VERBOSE;
310 ]),libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no)
311
312            CPPFLAGS=$_libcurl_save_cppflags
313            LIBS=$_libcurl_save_libs
314            unset _libcurl_save_cppflags
315            unset _libcurl_save_libs
316            ])
317
318         if test $libcurl_cv_lib_curl_usable = yes ; then
319
320            # Does curl_free() exist in this version of libcurl?
321            # If not, fake it with free()
322
323            _libcurl_save_cppflags=$CPPFLAGS
324            CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
325            _libcurl_save_libs=$LIBS
326            LIBS="$LIBS $LIBCURL"
327
328            AC_CHECK_FUNC(curl_free,,
329               AC_DEFINE(curl_free,free,
330                 [Define curl_free() as free() if our version of curl lacks curl_free.]))
331
332            CPPFLAGS=$_libcurl_save_cppflags
333            LIBS=$_libcurl_save_libs
334            unset _libcurl_save_cppflags
335            unset _libcurl_save_libs
336
337            AC_DEFINE(HAVE_LIBCURL,1,
338              [Define to 1 if you have a functional curl library.])
339            AC_SUBST(LIBCURL_CPPFLAGS)
340            AC_SUBST(LIBCURL)
341
342            for _libcurl_feature in $_libcurl_features ; do
343               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1])
344               eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes
345            done
346
347            if test "x$_libcurl_protocols" = "x" ; then
348
349               # We don't have --protocols, so just assume that all
350               # protocols are available
351               _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT"
352
353               if test x$libcurl_feature_SSL = xyes ; then
354                  _libcurl_protocols="$_libcurl_protocols HTTPS"
355
356                  # FTPS wasn't standards-compliant until version
357                  # 7.11.0
358                  if test $_libcurl_version -ge 461568; then
359                     _libcurl_protocols="$_libcurl_protocols FTPS"
360                  fi
361               fi
362            fi
363
364            for _libcurl_protocol in $_libcurl_protocols ; do
365               AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1])
366               eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes
367            done
368         else
369            unset LIBCURL
370            unset LIBCURL_CPPFLAGS
371         fi
372      fi
373
374      unset _libcurl_try_link
375      unset _libcurl_version_parse
376      unset _libcurl_config
377      unset _libcurl_feature
378      unset _libcurl_features
379      unset _libcurl_protocol
380      unset _libcurl_protocols
381      unset _libcurl_version
382      unset _libcurl_ldflags
383   fi
384
385   if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then
386      # This is the IF-NO path
387      ifelse([$4],,:,[$4])
388   else
389      # This is the IF-YES path
390      ifelse([$3],,:,[$3])
391   fi
392
393   unset _libcurl_with
394 ])dnl
395