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