Correct detection of various databases (PostgreSQL, MySQL, SQLite2/3, Oracle).
[apr-util.git] / build / apu-conf.m4
blob133e681d3dc2bbb1fa101493d4db91aa3f8f4e11
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Copyright 2000-2005 The Apache Software Foundation or its licensors, as
3 dnl applicable.
4 dnl
5 dnl Licensed under the Apache License, Version 2.0 (the "License");
6 dnl you may not use this file except in compliance with the License.
7 dnl You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
18 dnl
19 dnl custom autoconf rules for APRUTIL
20 dnl
22 dnl
23 dnl APU_FIND_APR: figure out where APR is located
24 dnl
25 AC_DEFUN([APU_FIND_APR], [
27   dnl use the find_apr.m4 script to locate APR. sets apr_found and apr_config
28   APR_FIND_APR(,,,[1])
29   if test "$apr_found" = "no"; then
30     AC_MSG_ERROR(APR could not be located. Please use the --with-apr option.)
31   fi
33   APR_BUILD_DIR="`$apr_config --installbuilddir`"
35   dnl make APR_BUILD_DIR an absolute directory (we'll need it in the
36   dnl sub-projects in some cases)
37   APR_BUILD_DIR="`cd $APR_BUILD_DIR && pwd`"
39   APR_INCLUDES="`$apr_config --includes`"
40   APR_LIBS="`$apr_config --link-libtool --libs`"
41   APR_SO_EXT="`$apr_config --apr-so-ext`"
42   APR_LIB_TARGET="`$apr_config --apr-lib-target`"
44   AC_SUBST(APR_INCLUDES)
45   AC_SUBST(APR_LIBS)
46   AC_SUBST(APR_BUILD_DIR)
50 dnl
51 dnl APU_TEST_EXPAT(directory): test if Expat is located in the specified dir
52 dnl
53 dnl if present: sets expat_include_dir, expat_libs, possibly expat_old
54 dnl
55 AC_DEFUN([APU_TEST_EXPAT], [
56   AC_MSG_CHECKING(for Expat in ifelse($2,,$1,$2))
58   expat_libtool=""
60   if test -r "$1/lib/expat.h.in"; then
61     dnl Expat 1.95.* distribution
62     expat_include_dir="$1/lib"
63     expat_ldflags="-L$1/lib"
64     expat_libs="-lexpat"
65     expat_libtool="$1/lib/libexpat.la"
66   elif test -r "$1/include/expat.h" -a \
67     -r "$1/lib/libexpat.la"; then
68     dnl Expat 1.95.* installation (with libtool)
69     expat_include_dir="$1/include"
70     expat_ldflags="-L$1/lib"
71     expat_libs="-lexpat"
72     expat_libtool="$1/lib/libexpat.la"
73   elif test -r "$1/include/expat.h" -a \
74     -r "$1/lib64/libexpat.la"; then
75     dnl Expat 1.95.* installation on certain 64-bit platforms (with libtool)
76     expat_include_dir="$1/include"
77     expat_ldflags="-L$1/lib64"
78     expat_libs="-lexpat"
79     expat_libtool="$1/lib64/libexpat.la"
80   elif test -r "$1/include/expat.h" -a \
81     -r "$1/lib/libexpat.a"; then
82     dnl Expat 1.95.* installation (without libtool)
83     dnl FreeBSD textproc/expat2
84     expat_include_dir="$1/include"
85     expat_ldflags="-L$1/lib"
86     expat_libs="-lexpat"
87   elif test -r "$1/xmlparse.h"; then
88     dnl maybe an expat-lite. use this dir for both includes and libs
89     expat_include_dir="$1"
90     expat_ldflags="-L$1"
91     expat_libs="-lexpat"
92     expat_libtool="$1/libexpat.la"
93     expat_old=yes
94   elif test -r "$1/include/xmlparse.h" -a \
95        -r "$1/lib/libexpat.a"; then
96     dnl previously installed expat
97     expat_include_dir="$1/include"
98     expat_ldflags="-L$1/lib"
99     expat_libs="-lexpat"
100     expat_old=yes
101   elif test -r "$1/include/xml/xmlparse.h" -a \
102        -r "$1/lib/xml/libexpat.a"; then
103     dnl previously installed expat
104     expat_include_dir="$1/include/xml"
105     expat_ldflags="-L$1/lib"
106     expat_libs="-lexpat"
107     expat_old=yes
108   elif test -r "$1/include/xmltok/xmlparse.h"; then
109     dnl Debian distribution
110     expat_include_dir="$1/include/xmltok"
111     expat_ldflags="-L$1/lib"
112     expat_libs="-lxmlparse -lxmltok"
113     expat_old=yes
114   elif test -r "$1/include/xml/xmlparse.h" -a \
115        -r "$1/lib/libexpat.a"; then
116     dnl FreeBSD textproc/expat package
117     expat_include_dir="$1/include/xml"
118     expat_ldflags="-L$1/lib"
119     expat_libs="-lexpat"
120     expat_old=yes
121   elif test -r "$1/xmlparse/xmlparse.h"; then
122     dnl Expat 1.0 or 1.1 source directory
123     expat_include_dir="$1/xmlparse"
124     expat_ldflags="-L$1"
125     expat_libs="-lexpat"
126     expat_old=yes
127   fi
128   dnl ### test for installed Expat 1.95.* distros
130   if test -n "$expat_include_dir"; then
131     dnl ### more info about what we found there? version? using .la?
132     AC_MSG_RESULT(yes)
133   else
134     AC_MSG_RESULT(no)
135   fi
140 dnl APU_FIND_EXPAT: figure out where EXPAT is located (or use bundled)
142 AC_DEFUN([APU_FIND_EXPAT], [
144 AC_ARG_WITH([expat],
145 [  --with-expat=DIR        specify Expat location, or 'builtin'], [
146   if test "$withval" = "yes"; then
147     AC_MSG_ERROR([a directory must be specified for --with-expat])
148   elif test "$withval" = "no"; then
149     AC_MSG_ERROR([Expat cannot be disabled (at this time)])
150   elif test "$withval" = "builtin"; then
151     abs_expatdir="`cd $srcdir/xml/expat && pwd`"
152     if test -d $abs_expatdir/. -a ! -d xml/expat/.; then
153       $mkdir_p xml/expat
154     fi
155     APU_TEST_EXPAT($abs_expatdir, xml/expat)
156   else
157     abs_expatdir="`cd $withval && pwd`"
158     APU_TEST_EXPAT($abs_expatdir, $withval)
159     if test -z "$expat_include_dir"; then
160       AC_MSG_ERROR([Expat was not found (or recognized) in \"$withval\"])
161     fi
162   fi
165 if test -z "$expat_include_dir"; then
166   for d in /usr /usr/local xml/expat-cvs xml/expat $srcdir/xml/expat ; do
167     APU_TEST_EXPAT($d)
168     if test -n "$expat_include_dir"; then
169       dnl For /usr installs of expat, we can't specify -L/usr/lib
170       if test "$d" = "/usr"; then
171         expat_ldflags=""
172       fi
173       break
174     fi
175   done
177 if test -z "$expat_include_dir"; then
178   AC_MSG_ERROR([could not locate Expat. use --with-expat])
181 dnl If this expat doesn't use libtool natively, we'll mimic it for our
182 dnl dependency library generation.
183 if test -z "$expat_libtool"; then
184   expat_libtool="$expat_ldflags $expat_libs" 
187 if test -n "$expat_old"; then
188   AC_DEFINE(APR_HAVE_OLD_EXPAT, 1, [define if Expat 1.0 or 1.1 was found])
191 dnl special-case the bundled distribution (use absolute dirs)
192 if test "$expat_include_dir" = "xml/expat/lib" -o "$expat_include_dir" = "xml/expat-cvs/lib"; then
193   bundled_subdir="`echo $expat_include_dir | sed -e 's%/lib%%'`"
194   APR_SUBDIR_CONFIG($bundled_subdir, [--prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir --includedir=$includedir --bindir=$bindir])
195   expat_include_dir=$top_builddir/$bundled_subdir/lib
196   expat_ldflags="-L$top_builddir/$bundled_subdir/lib"
197   expat_libs="-lexpat"
198   expat_libtool=$top_builddir/$bundled_subdir/lib/libexpat.la
199   APR_XML_SUBDIRS="`echo $bundled_subdir | sed -e 's%xml/%%'`"
200   APR_ADDTO(APRUTIL_EXPORT_LIBS, [$expat_libtool])
201 else
202 if test "$expat_include_dir" = "$abs_srcdir/xml/expat/include" -o "$expat_include_dir" = "$abs_srcdir/xml/expat/lib"; then
203   dnl This is a bit of a hack.  This only works because we know that
204   dnl we are working with the bundled version of the software.
205   bundled_subdir="xml/expat"
206   APR_SUBDIR_CONFIG($bundled_subdir, [--prefix=$prefix --exec-prefix=$exec_prefix --libdir=$libdir --includedir=$includedir --bindir=$bindir])
207   expat_include_dir=$top_builddir/$bundled_subdir/lib
208   expat_ldflags="-L$top_builddir/$bundled_subdir/lib"
209   expat_libs="-lexpat"
210   expat_libtool=$top_builddir/$bundled_subdir/lib/libexpat.la
211   APR_XML_SUBDIRS="`echo $bundled_subdir | sed -e 's%xml/%%'`"
212   APR_ADDTO(APRUTIL_EXPORT_LIBS, [$expat_libtool])
213 else
214   APR_ADDTO(APRUTIL_EXPORT_LIBS, [$expat_libs])
217 APR_XML_DIR=$bundled_subdir
218 APR_XML_EXPAT_OLD=$expat_old
219 AC_SUBST(APR_XML_SUBDIRS)
220 AC_SUBST(APR_XML_DIR)
221 AC_SUBST(APR_XML_EXPAT_OLD)
223 if test "$expat_include_dir" != "/usr/include"; then
224   APR_ADDTO(APRUTIL_INCLUDES, [-I$expat_include_dir])
226 APR_ADDTO(APRUTIL_LDFLAGS, [$expat_ldflags])
227 APR_ADDTO(APRUTIL_LIBS, [$expat_libtool])
231 dnl 
232 dnl Find a particular LDAP library
234 AC_DEFUN([APU_FIND_LDAPLIB], [
235   if test ${apu_has_ldap} != "1"; then
236     ldaplib=$1
237     extralib=$2
238     unset ac_cv_lib_${ldaplib}_ldap_init
239     unset ac_cv_lib_${ldaplib}___ldap_init
240     AC_CHECK_LIB(${ldaplib}, ldap_init, 
241       [
242         APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l${ldaplib} ${extralib}])
243         APR_ADDTO(APRUTIL_LIBS,[-l${ldaplib} ${extralib}])
244         AC_CHECK_LIB(${ldaplib}, ldapssl_client_init, apu_has_ldapssl_client_init="1", , ${extralib})
245         AC_CHECK_LIB(${ldaplib}, ldapssl_client_deinit, apu_has_ldapssl_client_deinit="1", , ${extralib})
246         AC_CHECK_LIB(${ldaplib}, ldapssl_add_trusted_cert, apu_has_ldapssl_add_trusted_cert="1", , ${extralib})
247         AC_CHECK_LIB(${ldaplib}, ldap_start_tls_s, apu_has_ldap_start_tls_s="1", , ${extralib})
248         AC_CHECK_LIB(${ldaplib}, ldap_sslinit, apu_has_ldap_sslinit="1", , ${extralib})
249         AC_CHECK_LIB(${ldaplib}, ldapssl_init, apu_has_ldapssl_init="1", , ${extralib})
250         AC_CHECK_LIB(${ldaplib}, ldapssl_install_routines, apu_has_ldapssl_install_routines="1", , ${extralib})
251         apu_has_ldap="1";
252       ], , ${extralib})
253   fi
258 dnl APU_FIND_LDAP: figure out where LDAP is located
260 AC_DEFUN([APU_FIND_LDAP],  [
262 echo $ac_n "${nl}checking for ldap support..."
264 apu_has_ldap="0";
265 apu_has_ldapssl_client_init="0"
266 apu_has_ldapssl_client_deinit="0"
267 apu_has_ldapssl_add_trusted_cert="0"
268 apu_has_ldap_start_tls_s="0"
269 apu_has_ldapssl_init="0"
270 apu_has_ldap_sslinit="0"
271 apu_has_ldapssl_install_routines="0"
272 apu_has_ldap_openldap="0"
273 apu_has_ldap_solaris="0"
274 apu_has_ldap_novell="0"
275 apu_has_ldap_microsoft="0"
276 apu_has_ldap_netscape="0"
277 apu_has_ldap_mozilla="0"
278 apu_has_ldap_other="0"
280 AC_ARG_WITH(ldap-include,[  --with-ldap-include=path  path to ldap include files with trailing slash])
281 AC_ARG_WITH(ldap-lib,[  --with-ldap-lib=path    path to ldap lib file])
282 AC_ARG_WITH(ldap,[  --with-ldap=library     ldap library to use],
283   [
284     save_cppflags="$CPPFLAGS"
285     save_ldflags="$LDFLAGS"
286     save_libs="$LIBS"
287     if test -n "$with_ldap_include"; then
288       CPPFLAGS="$CPPFLAGS -I$with_ldap_include"
289       APR_ADDTO(APRUTIL_INCLUDES, [-I$with_ldap_include])
290     fi
291     if test -n "$with_ldap_lib"; then
292       LDFLAGS="$LDFLAGS -L$with_ldap_lib"
293       APR_ADDTO(APRUTIL_LDFLAGS, [-L$with_ldap_lib])
294     fi
296     LIBLDAP="$withval"
297     if test "$LIBLDAP" = "yes"; then
298 dnl The iPlanet C SDK 5.0 is as yet untested... 
299       APU_FIND_LDAPLIB("ldap50", "-lnspr4 -lplc4 -lplds4 -liutil50 -llber50 -lldif50 -lnss3 -lprldap50 -lssl3 -lssldap50")
300       APU_FIND_LDAPLIB("ldapssl41", "-lnspr3 -lplc3 -lplds3")
301       APU_FIND_LDAPLIB("ldapssl40")
302       APU_FIND_LDAPLIB("ldapssl30")
303       APU_FIND_LDAPLIB("ldapssl20")
304       APU_FIND_LDAPLIB("ldapsdk", "-lldapx -lldapssl -lldapgss -lgssapi_krb5")
305       APU_FIND_LDAPLIB("ldapsdk", "-lldapx -lldapssl -lldapgss -lgss -lresolv -lsocket")
306       APU_FIND_LDAPLIB("ldap", "-llber")
307       APU_FIND_LDAPLIB("ldap", "-llber -lresolv")
308       APU_FIND_LDAPLIB("ldap", "-llber -lresolv -lsocket -lnsl")
309       APU_FIND_LDAPLIB("ldap", "-ldl -lpthread")
310     else
311       APU_FIND_LDAPLIB($LIBLDAP)
312       APU_FIND_LDAPLIB($LIBLDAP, "-lresolv")
313       APU_FIND_LDAPLIB($LIBLDAP, "-lresolv -lsocket -lnsl")
314       APU_FIND_LDAPLIB($LIBLDAP, "-ldl -lpthread")
315     fi
317     test ${apu_has_ldap} != "1" && AC_MSG_ERROR(could not find an LDAP library)
318     AC_CHECK_LIB(lber, ber_init)
320     AC_CHECK_HEADERS(lber.h, lber_h=["#include <lber.h>"])
322     # Solaris has a problem in <ldap.h> which prevents it from
323     # being included by itself.  Check for <ldap.h> manually,
324     # including lber.h first.
325     AC_CACHE_CHECK([for ldap.h], [apr_cv_hdr_ldap_h],
326     [AC_TRY_CPP(
327     [#ifdef HAVE_LBER_H
328     #include <lber.h>
329     #endif
330     #include <ldap.h>
331     ], [apr_cv_hdr_ldap_h=yes], [apr_cv_hdr_ldap_h=no])])
332     if test "$apr_cv_hdr_ldap_h" = "yes"; then
333       ldap_h=["#include <ldap.h>"]
334       AC_DEFINE([HAVE_LDAP_H], 1, [Defined if ldap.h is present])
335     fi
337     AC_CHECK_HEADERS(ldap_ssl.h, ldap_ssl_h=["#include <ldap_ssl.h>"])
339     if test "$apr_cv_hdr_ldap_h" = "yes"; then
340       AC_CACHE_CHECK([for LDAP toolkit],
341                      [apr_cv_ldap_toolkit], [
342         if test "x$apr_cv_ldap_toolkit" = "x"; then
343           AC_EGREP_CPP([OpenLDAP], [$lber_h
344                        $ldap_h 
345                        LDAP_VENDOR_NAME], [apu_has_ldap_openldap="1"
346                                            apr_cv_ldap_toolkit="OpenLDAP"])
347         fi
348         if test "x$apr_cv_ldap_toolkit" = "x"; then
349           AC_EGREP_CPP([Sun Microsystems Inc.], [$lber_h
350                        $ldap_h
351                        LDAP_VENDOR_NAME], [apu_has_ldap_solaris="1"
352                                            apr_cv_ldap_toolkit="Solaris"])
353         fi
354         if test "x$apr_cv_ldap_toolkit" = "x"; then
355           AC_EGREP_CPP([Novell], [$lber_h
356                        $ldap_h
357                        LDAP_VENDOR_NAME], [apu_has_ldap_novell="1"
358                                            apr_cv_ldap_toolkit="Novell"])
359         fi
360         if test "x$apr_cv_ldap_toolkit" = "x"; then
361           AC_EGREP_CPP([Microsoft Corporation.], [$lber_h
362                        $ldap_h
363                        LDAP_VENDOR_NAME], [apu_has_ldap_microsoft="1"
364                                            apr_cv_ldap_toolkit="Microsoft"])
365         fi
366         if test "x$apr_cv_ldap_toolkit" = "x"; then
367           AC_EGREP_CPP([Netscape Communications Corp.], [$lber_h
368                        $ldap_h
369                        LDAP_VENDOR_NAME], [apu_has_ldap_netscape="1"
370                                            apr_cv_ldap_toolkit="Netscape"])
371         fi
372         if test "x$apr_cv_ldap_toolkit" = "x"; then
373           AC_EGREP_CPP([mozilla.org], [$lber_h
374                        $ldap_h
375                        LDAP_VENDOR_NAME], [apu_has_ldap_mozilla="1"
376                                            apr_cv_ldap_toolkit="Mozilla"])
377         fi
378         if test "x$apr_cv_ldap_toolkit" = "x"; then
379           apu_has_ldap_other="1"
380           apr_cv_ldap_toolkit="unknown"
381         fi
382       ])
383     fi
385     CPPFLAGS=$save_cppflags
386     LDFLAGS=$save_ldflags
387     LIBS=$save_libs
388   ])
390 AC_SUBST(ldap_h)
391 AC_SUBST(lber_h)
392 AC_SUBST(ldap_ssl_h)
393 AC_SUBST(apu_has_ldapssl_client_init)
394 AC_SUBST(apu_has_ldapssl_client_deinit)
395 AC_SUBST(apu_has_ldapssl_add_trusted_cert)
396 AC_SUBST(apu_has_ldap_start_tls_s)
397 AC_SUBST(apu_has_ldapssl_init)
398 AC_SUBST(apu_has_ldap_sslinit)
399 AC_SUBST(apu_has_ldapssl_install_routines)
400 AC_SUBST(apu_has_ldap)
401 AC_SUBST(apu_has_ldap_openldap)
402 AC_SUBST(apu_has_ldap_solaris)
403 AC_SUBST(apu_has_ldap_novell)
404 AC_SUBST(apu_has_ldap_microsoft)
405 AC_SUBST(apu_has_ldap_netscape)
406 AC_SUBST(apu_has_ldap_mozilla)
407 AC_SUBST(apu_has_ldap_other)
412 dnl APU_CHECK_CRYPT_R_STYLE
414 dnl  Decide which of a couple of flavors of crypt_r() is necessary for
415 dnl  this platform.
417 AC_DEFUN([APU_CHECK_CRYPT_R_STYLE], [
419 AC_CACHE_CHECK([style of crypt_r], apr_cv_crypt_r_style, 
420 [AC_TRY_COMPILE([#include <crypt.h>],
421  [CRYPTD buffer;
422   crypt_r("passwd", "hash", &buffer);], 
423  [apr_cv_crypt_r_style=cryptd],
424  [AC_TRY_COMPILE([#include <crypt.h>],
425   [struct crypt_data buffer;
426    crypt_r("passwd", "hash", &buffer);], 
427   [apr_cv_crypt_r_style=struct_crypt_data],
428   [apr_cv_crypt_r_style=none])])])
430 if test "$apr_cv_crypt_r_style" = "cryptd"; then
431    AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
432 elif test "$apr_cv_crypt_r_style" = "struct_crypt_data"; then
433    AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])