Document PostgreSQL row counting fix.
[apr-util.git] / build / dbm.m4
blob6998eee3d4f502c7a133cee155bbf5fd2a67ed71
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Licensed to the Apache Software Foundation (ASF) under one or more
3 dnl contributor license agreements.  See the NOTICE file distributed with
4 dnl this work for additional information regarding copyright ownership.
5 dnl The ASF licenses this file to You under the Apache License, Version 2.0
6 dnl (the "License"); you may not use this file except in compliance with
7 dnl the License.  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 DBM module
20 dnl
22 dnl   APU_LIB_BERKELEY_DB(major, minor, patch, places, headers, libnames)
23 dnl
24 dnl   Search for a useable version of Berkeley DB in a number of
25 dnl   common places.  The installed DB must be no older than the
26 dnl   version given by MAJOR, MINOR, and PATCH.  All of these
27 dnl   arguments are allowed to be '-1', indicating we don't care.
28 dnl   PLACES is a list of places to search for a Berkeley DB
29 dnl   installation.  HEADERS is a list of headers to try.  LIBNAMES
30 dnl   is a list of names of the library to attempt to link against,
31 dnl   typically 'db' and 'db4'.
32 dnl
33 dnl   If we find a useable version, set CPPFLAGS and LIBS as
34 dnl   appropriate, and set the shell variable `apu_have_db' to
35 dnl   `1', and apu_db_lib to the matching lib name, and apu_db_header
36 dnl   to the header to use.  Otherwise, set `apu_have_db' to `0'.
37 dnl
38 dnl   This macro also checks for the `--with-berkeley-db=PATH' flag;
39 dnl   if given, the macro will use the PATH specified, and the
40 dnl   configuration script will die if it can't find the library.  If
41 dnl   the user gives the `--without-berkeley-db' flag, the entire
42 dnl   search is skipped.
43 dnl
44 dnl   We cache the results of individual searches under particular
45 dnl   prefixes, not the overall result of whether we found Berkeley
46 dnl   DB.  That way, the user can re-run the configure script with
47 dnl   different --with-berkeley-db switch values, without interference
48 dnl   from the cache.
51 AC_DEFUN([APU_CHECK_BERKELEY_DB], [
52   bdb_version=$1
53   if test "$2" != "-1"; then
54     bdb_version="$bdb_version.$2"
55     if test "$3" != "-1"; then
56       bdb_version="$bdb_version.$3"
57     fi
58   fi
59   bdb_places=$4
60   bdb_default_search_headers=$5
61   bdb_default_search_lib_names=$6
63   apu_have_db=0
65   # Save the original values of the flags we tweak.
66   apu_check_lib_save_libs="$LIBS"
67   apu_check_lib_save_ldflags="$LDFLAGS"
68   apu_check_lib_save_cppflags="$CPPFLAGS"
70   # The variable `found' is the prefix under which we've found
71   # Berkeley DB, or `not' if we haven't found it anywhere yet.
72   found=not
73   for bdb_place in $bdb_places; do
75     LDFLAGS="$apu_check_lib_save_ldflags"
76     CPPFLAGS="$apu_check_lib_save_cppflags"
77     case "$bdb_place" in
78       "std" )
79         description="the standard places"
80       ;;
81       *":"* )
82         header="`echo $bdb_place | sed -e 's/:.*$//'`"
83         lib="`echo $bdb_place | sed -e 's/^.*://'`"
84         CPPFLAGS="$CPPFLAGS -I$header"
85         LDFLAGS="$LDFLAGS -L$lib"
86         description="$header and $lib"
87       ;;
88       * )
89         if test -d $bdb_place; then
90           LDFLAGS="$LDFLAGS -L$bdb_place/lib"
91           CPPFLAGS="$CPPFLAGS -I$bdb_place/include"
92         else
93           AC_MSG_CHECKING([for Berkeley DB $bdb_version in $bdb_place])
94           AC_MSG_RESULT([directory not found])
95           continue
96         fi
97         description="$bdb_place"
98       ;;
99     esac
101     # Since there is no AC_MSG_NOTICE in autoconf 2.13, we use this
102     # trick to display a message instead.
103     AC_MSG_CHECKING([for Berkeley DB $bdb_version in $description])
104     AC_MSG_RESULT()
106     for bdb_libname in $bdb_default_search_lib_names; do
107       for bdb_header in $bdb_default_search_headers; do
108         # Clear the header cache variable for each location
109         changequote(,)
110         cache_id="`echo ac_cv_header_${bdb_header} \
111                  | sed -e 's/[^a-zA-Z0-9_]/_/g'`"
112         changequote([,])
113         unset $cache_id
114         AC_CHECK_HEADER([$bdb_header], [
115           if test "$1" = "3" -o "$1" = "4"; then
116             # We generate a separate cache variable for each prefix and libname
117             # we search under.  That way, we avoid caching information that
118             # changes if the user runs `configure' with a different set of
119             # switches.
120             changequote(,)
121             cache_id="`echo apu_cv_check_berkeley_db_$1_$2_$3_${bdb_header}_${bdb_libname}_in_${bdb_place} \
122                      | sed -e 's/[^a-zA-Z0-9_]/_/g'`"
123             changequote([,])
125             AC_MSG_CHECKING([for -l$bdb_libname])
126             dnl We can't use AC_CACHE_CHECK here, because that won't print out
127             dnl the value of the computed cache variable properly.
128             AC_CACHE_VAL($cache_id,
129               [
130                 APU_TRY_BERKELEY_DB($1, $2, $3, $bdb_header, $bdb_libname)
131                 eval "$cache_id=$apu_try_berkeley_db"
132               ])
133             result="`eval echo '$'$cache_id`"
134             AC_MSG_RESULT($result)
135           elif test "$1" = "1"; then
136             AC_CHECK_LIB($bdb_libname,
137               dbopen,
138               [result=yes],
139               [result=no]
140             )
141           elif test "$1" = "2"; then
142             AC_CHECK_LIB($bdb_libname,
143               db_open,
144               [result=yes],
145               [result=no]
146             )
147           fi
148         ], [result="no"])
149         
150         # If we found it, no need to search any more.
151         if test "$result" = "yes"; then
152           found="$bdb_place"
153           break
154         fi
155       done
156       test "$found" != "not" && break
157     done
158     test "$found" != "not" && break
159   done
161   # Restore the original values of the flags we tweak.
162   LDFLAGS="$apu_check_lib_save_ldflags"
163   CPPFLAGS="$apu_check_lib_save_cppflags"
165   case "$found" in
166   "not")
167     apu_have_db=0
168     ;;
169   "std")
170     apu_db_header=$bdb_header
171     apu_db_lib=$bdb_libname
172     apu_have_db=1
173     ;;
174   *":"*)
175     header="`echo $found | sed -e 's/:.*$//'`"
176     lib="`echo $found | sed -e 's/^.*://'`"
178     APR_ADDTO(APRUTIL_INCLUDES, [-I$header])
179     APR_ADDTO(APRUTIL_LDFLAGS, [-L$lib])
180     apu_db_header=$bdb_header
181     apu_db_lib=$bdb_libname
182     apu_have_db=1
183     ;;
184   *)
185     APR_ADDTO(APRUTIL_INCLUDES, [-I$found/include])
186     APR_ADDTO(APRUTIL_LDFLAGS, [-L$found/lib])
187     apu_db_header=$bdb_header
188     apu_db_lib=$bdb_libname
189     apu_have_db=1
190     ;;
191   esac
195 dnl   APU_TRY_BERKELEY_DB(major, minor, patch, header, libname)
197 dnl   A subroutine of APU_CHECK_BERKELEY_DB.
199 dnl   Check that a new-enough version of Berkeley DB is installed.
200 dnl   "New enough" means no older than the version given by MAJOR,
201 dnl   MINOR, and PATCH.  The result of the test is not cached; no
202 dnl   messages are printed.  Use HEADER as the header file to include.
203 dnl   Use LIBNAME as the library to link against.
204 dnl   (e.g. LIBNAME should usually be "db" or "db4".)
206 dnl   Set the shell variable `apu_try_berkeley_db' to `yes' if we found
207 dnl   an appropriate version installed, or `no' otherwise.
209 dnl   This macro uses the Berkeley DB library function `db_version' to
210 dnl   find the version.  If the library installed doesn't have this
211 dnl   function, then this macro assumes it is too old.
213 dnl   NOTE: This is pretty messed up.  It seems that the FreeBSD port of
214 dnl   Berkeley DB 4 puts the header file in /usr/local/include/db4, but the
215 dnl   database library in /usr/local/lib, as libdb4.[a|so].  There is no
216 dnl   /usr/local/include/db.h.  So if you check for /usr/local first, you'll
217 dnl   get the old header file from /usr/include, and the new library from
218 dnl   /usr/local/lib.  Disaster.  Thus this test compares the version constants
219 dnl   in the db.h header with the ones returned by db_version().
222 AC_DEFUN([APU_TRY_BERKELEY_DB],
223   [
224     apu_try_berkeley_db_save_libs="$LIBS"
226     apu_check_berkeley_db_major=$1
227     apu_check_berkeley_db_minor=$2
228     apu_check_berkeley_db_patch=$3
229     apu_try_berkeley_db_header=$4
230     apu_try_berkeley_db_libname=$5
232     LIBS="$LIBS -l$apu_try_berkeley_db_libname"
233     AC_TRY_RUN(
234       [
235 #include <stdlib.h>
236 #include <stdio.h>
237 #include <$apu_try_berkeley_db_header>
238 main ()
240   int major, minor, patch;
242   db_version(&major, &minor, &patch);
244   /* Sanity check: ensure that db.h constants actually match the db library */
245   if (major != DB_VERSION_MAJOR
246       || minor != DB_VERSION_MINOR
247       || patch != DB_VERSION_PATCH)
248     exit (1);
250   /* Run-time check:  ensure the library claims to be the correct version. */
252   if ($apu_check_berkeley_db_major != -1) {
253     if (major < $apu_check_berkeley_db_major)
254       exit (1);
255     if (major > $apu_check_berkeley_db_major)
256       exit (0);
257   }
259   if ($apu_check_berkeley_db_minor != -1) {
260     if (minor < $apu_check_berkeley_db_minor)
261       exit (1);
262     if (minor > $apu_check_berkeley_db_minor)
263       exit (0);
264   }
266   if ($apu_check_berkeley_db_patch == -1
267       || patch >= $apu_check_berkeley_db_patch)
268     exit (0);
269   else
270     exit (1);
272       ],
273       [apu_try_berkeley_db=yes],
274       [apu_try_berkeley_db=no],
275       [apu_try_berkeley_db=yes]
276     )
278     LIBS="$apu_try_berkeley_db_save_libs"
279   ]
284 dnl APU_CHECK_DB1: is DB1 present?
286 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
288 AC_DEFUN([APU_CHECK_DB1], [
289   places=$1
290   if test -z "$places"; then
291     places="std"
292   fi
293   APU_CHECK_BERKELEY_DB(1, 0, 0,
294     "$places",
295     "db1/db.h db.h",
296     "db1"
297   )
298   if test "$apu_have_db" = "1"; then
299     apu_db_version=1
300   fi
305 dnl APU_CHECK_DB185: is DB1.85 present?
307 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
309 dnl NB: BerkelyDB v2 and above can be compiled in 1.85 mode
310 dnl which has a libdb not libdb1 or libdb185
311 AC_DEFUN([APU_CHECK_DB185], [
312   places=$1
313   if test -z "$places"; then
314     places="std"
315   fi
316   APU_CHECK_BERKELEY_DB(1, -1, -1,
317     "$places",
318     "db_185.h",
319     "db"
320   )
321   if test "$apu_have_db" = "1"; then
322     apu_db_version=185
323   fi
328 dnl APU_CHECK_DB2: is DB2 present?
330 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
332 AC_DEFUN([APU_CHECK_DB2], [
333   places=$1
334   if test -z "$places"; then
335     places="std"
336   fi
337   APU_CHECK_BERKELEY_DB(2, -1, -1,
338     "$places",
339     "db2/db.h db.h",
340     "db2 db"
341   )
342   if test "$apu_have_db" = "1"; then
343     apu_db_version=2
344   fi
349 dnl APU_CHECK_DB3: is DB3 present?
351 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
353 AC_DEFUN([APU_CHECK_DB3], [
354   places=$1
355   if test -z "$places"; then
356     places="std"
357   fi
358   APU_CHECK_BERKELEY_DB(3, -1, -1,
359     "$places",
360     "db3/db.h db.h",
361     "db3 db"
362   )
363   if test "$apu_have_db" = "1"; then
364     apu_db_version=3
365   fi
370 dnl APU_CHECK_DB4: is DB4 present?
372 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
374 AC_DEFUN([APU_CHECK_DB4], [
375   places=$1
376   if test -z "$places"; then
377     places="std /usr/local /usr/local/BerkeleyDB.4.0 /boot/home/config"
378   fi
379   APU_CHECK_BERKELEY_DB("4", "0", "-1",
380     "$places",
381     "db4/db.h db.h",
382     "db-4.0 db4 db"
383   )
384   if test "$apu_have_db" = "1"; then
385     apu_db_version=4
386   fi
391 dnl APU_CHECK_DB41: is DB4.1 present?
393 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
395 AC_DEFUN([APU_CHECK_DB41], [
396   places=$1
397   if test -z "$places"; then
398     places="std /usr/local /usr/local/BerkeleyDB.4.1 /boot/home/config"
399   fi
400   APU_CHECK_BERKELEY_DB("4", "1", "-1",
401     "$places",
402     "db41/db.h db4/db.h db.h",
403     "db-4.1 db41 db4 db"
404   )
405   if test "$apu_have_db" = "1"; then
406     apu_db_version=4
407   fi
412 dnl APU_CHECK_DB42: is DB4.2 present?
414 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
416 AC_DEFUN([APU_CHECK_DB42], [
417   places=$1
418   if test -z "$places"; then
419     places="std /usr/local /usr/local/BerkeleyDB.4.2 /boot/home/config"
420   fi
421   APU_CHECK_BERKELEY_DB("4", "2", "-1",
422     "$places",
423     "db42/db.h db4/db.h db.h",
424     "db-4.2 db42 db4 db"
425   )
426   if test "$apu_have_db" = "1"; then
427     apu_db_version=4
428   fi
431 dnl APU_CHECK_DB43: is DB4.3 present?
433 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
435 AC_DEFUN([APU_CHECK_DB43], [
436   places=$1
437   if test -z "$places"; then
438     places="std /usr/local/BerkeleyDB.4.3 /boot/home/config"
439   fi
440   APU_CHECK_BERKELEY_DB("4", "3", "-1",
441     "$places",
442     "db43/db.h db4/db.h db.h",
443     "db-4.3 db4-4.3 db43 db4 db"
444   )
445   if test "$apu_have_db" = "1"; then
446     apu_db_version=4
447   fi
450 dnl APU_CHECK_DB44: is DB4.4 present?
452 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
454 AC_DEFUN([APU_CHECK_DB44], [
455   places=$1
456   if test -z "$places"; then
457     places="std /usr/local/BerkeleyDB.4.4 /boot/home/config"
458   fi
459   APU_CHECK_BERKELEY_DB("4", "4", "-1",
460     "$places",
461     "db44/db.h db4/db.h db.h",
462     "db-4.4 db4-4.4 db44 db4 db"
463   )
464   if test "$apu_have_db" = "1"; then
465     apu_db_version=4
466   fi
469 dnl APU_CHECK_DB45: is DB4.5 present?
471 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
473 AC_DEFUN([APU_CHECK_DB45], [
474   places=$1
475   if test -z "$places"; then
476     places="std /usr/local/BerkeleyDB.4.5 /boot/home/config"
477   fi
478   APU_CHECK_BERKELEY_DB("4", "5", "-1",
479     "$places",
480     "db45/db.h db4/db.h db.h",
481     "db-4.5 db4-4.5 db45 db4 db"
482   )
483   if test "$apu_have_db" = "1"; then
484     apu_db_version=4
485   fi
488 dnl APU_CHECK_DB46: is DB4.6 present?
490 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
492 AC_DEFUN([APU_CHECK_DB46], [
493   places=$1
494   if test -z "$places"; then
495     places="std /usr/local/BerkeleyDB.4.6 /boot/home/config"
496   fi
497   APU_CHECK_BERKELEY_DB("4", "6", "-1",
498     "$places",
499     "db46/db.h db4/db.h db.h",
500     "db-4.6 db4-4.6 db46 db4 db"
501   )
502   if test "$apu_have_db" = "1"; then
503     apu_db_version=4
504   fi
507 dnl APU_CHECK_DB47: is DB4.7 present?
509 dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
511 AC_DEFUN([APU_CHECK_DB47], [
512   places=$1
513   if test -z "$places"; then
514     places="std /usr/local/BerkeleyDB.4.7 /boot/home/config"
515   fi
516   APU_CHECK_BERKELEY_DB("4", "7", "-1",
517     "$places",
518     "db47/db.h db4/db.h db.h",
519     "db-4.7 db4-4.7 db47 db4 db"
520   )
521   if test "$apu_have_db" = "1"; then
522     apu_db_version=4
523   fi
526 AC_DEFUN([APU_CHECK_DB], [
527   requested=$1
528   check_places=$2
530   case "$requested" in
531   db)
532     APU_CHECK_DB_ALL("$check_places")
533     if test "$apu_have_db" = "0"; then
534       AC_MSG_ERROR(Berkeley db requested, but not found)
535     fi
536     ;;
537   db1)
538     APU_CHECK_DB1("$check_places")
539     if test "$apu_db_version" != "1"; then
540       AC_MSG_ERROR(Berkeley db1 not found)
541     fi
542     ;;
543   db185)
544     APU_CHECK_DB185("$check_places")
545     if test "$apu_db_version" != "185"; then
546       AC_MSG_ERROR(Berkeley db185 not found)
547     fi
548     ;;
549   db2)
550     APU_CHECK_DB2("$check_places")
551     if test "$apu_db_version" != "2"; then
552       AC_MSG_ERROR(Berkeley db2 not found)
553     fi
554     ;;
555   db3)
556     APU_CHECK_DB3("$check_places")
557     if test "$apu_db_version" != "3"; then
558       AC_MSG_ERROR(Berkeley db3 not found)
559     fi
560     ;;
561   db4)
562     APU_CHECK_DB4("$check_places")
563     if test "$apu_db_version" != "4"; then
564       AC_MSG_ERROR(Berkeley db4 not found)
565     fi
566     ;;
567   db41)
568     APU_CHECK_DB41("$check_places")
569     if test "$apu_db_version" != "4"; then
570       AC_MSG_ERROR(Berkeley db4 not found)
571     fi
572     ;;
573   db42)
574     APU_CHECK_DB42("$check_places")
575     if test "$apu_db_version" != "4"; then
576       AC_MSG_ERROR(Berkeley db4 not found)
577     fi
578     ;;
579   db43)
580     APU_CHECK_DB43("$check_places")
581     if test "$apu_db_version" != "4"; then
582       AC_MSG_ERROR(Berkeley db4 not found)
583     fi
584     ;;
585   db44)
586     APU_CHECK_DB44("$check_places")
587     if test "$apu_db_version" != "4"; then
588       AC_MSG_ERROR(Berkeley db4 not found)
589     fi
590     ;;
591   db45)
592     APU_CHECK_DB45("$check_places")
593     if test "$apu_db_version" != "4"; then
594       AC_MSG_ERROR(Berkeley db4 not found)
595     fi
596     ;;
597   db46)
598     APU_CHECK_DB46("$check_places")
599     if test "$apu_db_version" != "4"; then
600       AC_MSG_ERROR(Berkeley db4 not found)
601     fi
602     ;;
603   db47)
604     APU_CHECK_DB47("$check_places")
605     if test "$apu_db_version" != "4"; then
606       AC_MSG_ERROR(Berkeley db4 not found)
607     fi
608     ;;
609   default)
610     APU_CHECK_DB_ALL("$check_places")
611     ;;
612   esac
616 dnl APU_CHECK_DB_ALL: Try all Berkeley DB versions, from 4.7 to 1.
618 AC_DEFUN([APU_CHECK_DB_ALL], [
619   all_places=$1
621   APU_CHECK_DB47("$all_places")
622   if test "$apu_db_version" != "4"; then
623     APU_CHECK_DB46("$all_places")
624     if test "$apu_db_version" != "4"; then
625       APU_CHECK_DB45("$all_places")
626       if test "$apu_db_version" != "4"; then
627         APU_CHECK_DB44("$all_places")
628         if test "$apu_db_version" != "4"; then
629           APU_CHECK_DB43("$all_places")
630           if test "$apu_db_version" != "4"; then
631             APU_CHECK_DB42("$all_places")
632             if test "$apu_db_version" != "4"; then
633               APU_CHECK_DB41("$all_places")
634               if test "$apu_db_version" != "4"; then
635                 APU_CHECK_DB4("$all_places")
636                 if test "$apu_db_version" != "4"; then
637                   APU_CHECK_DB3("$all_places")
638                   if test "$apu_db_version" != "3"; then
639                     APU_CHECK_DB2("$all_places")
640                     if test "$apu_db_version" != "2"; then
641                       APU_CHECK_DB1("$all_places")
642                       if test "$apu_db_version" != "1"; then
643                         APU_CHECK_DB185("$all_places")
644                       fi
645                     fi
646                   fi
647                 fi
648               fi
649             fi
650           fi
651         fi
652       fi
653     fi
654   fi
655   AC_MSG_CHECKING(for Berkeley DB)
656   if test "$apu_have_db" = "1"; then
657     AC_MSG_RESULT(found db$apu_db_version)
658   else
659     AC_MSG_RESULT(not found)
660   fi
665 dnl APU_CHECK_DBM: see what kind of DBM backend to use for apr_dbm.
667 AC_DEFUN([APU_CHECK_DBM], [
668   apu_use_sdbm=0
669   apu_use_ndbm=0
670   apu_use_gdbm=0
671   apu_use_db=0
672   dnl it's in our codebase
673   apu_have_sdbm=1
674   apu_have_gdbm=0
675   apu_have_ndbm=0
676   apu_have_db=0
678   apu_db_header=db.h                # default so apu_select_dbm.h is syntactically correct
679   apu_db_version=0
681   AC_ARG_WITH(dbm, [APR_HELP_STRING([--with-dbm=DBM], [choose the DBM type to use.
682       DBM={sdbm,gdbm,ndbm,db,db1,db185,db2,db3,db4,db41,db42,db43,db44,db45,db46,db47}])],
683   [
684     if test "$withval" = "yes"; then
685       AC_MSG_ERROR([--with-dbm needs to specify a DBM type to use.
686         One of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4, db41, db42, db43, db44, db45, db46, db47])
687     fi
688     requested="$withval"
689   ], [
690     requested=default
691   ])
693   dnl We don't pull in GDBM unless the user asks for it, since it's GPL
694   AC_ARG_WITH([gdbm], [APR_HELP_STRING([--with-gdbm=DIR], [enable GDBM support])],
695   [
696     apu_have_gdbm=0
697     if test "$withval" = "yes"; then
698       AC_CHECK_HEADER(gdbm.h, AC_CHECK_LIB(gdbm, gdbm_open, [apu_have_gdbm=1]))
699     elif test "$withval" = "no"; then
700       apu_have_gdbm=0
701     else
702       saved_cppflags="$CPPFLAGS"
703       saved_ldflags="$LDFLAGS"
704       CPPFLAGS="$CPPFLAGS -I$withval/include"
705       LDFLAGS="$LDFLAGS -L$withval/lib "
707       AC_MSG_CHECKING(checking for gdbm in $withval)
708       AC_CHECK_HEADER(gdbm.h, AC_CHECK_LIB(gdbm, gdbm_open, [apu_have_gdbm=1]))
709       if test "$apu_have_gdbm" != "0"; then
710         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
711         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
712       fi
713       CPPFLAGS="$saved_cppflags"
714       LDFLAGS="$saved_ldflags"
715     fi
716   ])
718   AC_ARG_WITH([ndbm], [APR_HELP_STRING([--with-ndbm=PATH], [
719       Find the NDBM header and library in `PATH/include' and 
720       `PATH/lib'.  If PATH is of the form `HEADER:LIB', then search 
721       for header files in HEADER, and the library in LIB.  If you omit
722       the `=PATH' part completely, the configure script will search
723       for NDBM in a number of standard places.])],
724   [
725     apu_have_ndbm=0
726     if test "$withval" = "yes"; then
727       AC_MSG_CHECKING(checking for ndbm in the usual places)
728       apu_want_ndbm=1
729       NDBM_INC=""
730       NDBM_LDFLAGS=""
731     elif test "$withval" = "no"; then
732       apu_want_ndbm=0
733     else
734       apu_want_ndbm=1
735       case "$withval" in
736         *":"*)
737           NDBM_INC="-I`echo $withval |sed -e 's/:.*$//'`"
738           NDBM_LDFLAGS="-L`echo $withval |sed -e 's/^.*://'`"
739           AC_MSG_CHECKING(checking for ndbm includes with $NDBM_INC libs with $NDBM_LDFLAGS )
740         ;;
741         *)
742           NDBM_INC="-I$withval/include"
743           NDBM_LDFLAGS="-L$withval/lib"
744           AC_MSG_CHECKING(checking for ndbm includes in $withval)
745         ;;
746       esac
747     fi
749     save_cppflags="$CPPFLAGS"
750     save_ldflags="$LDFLAGS"
751     CPPFLAGS="$CPPFLAGS $NDBM_INC"
752     LDFLAGS="$LDFLAGS $NDBM_LDFLAGS"
753     dnl db_ndbm_open is what sleepcat's compatibility library actually has in it's lib
754     if test "$apu_want_ndbm" != "0"; then
755       AC_CHECK_HEADER(ndbm.h, 
756         AC_CHECK_LIB(c, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=c],
757           AC_CHECK_LIB(dbm, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=dbm],
758             AC_CHECK_LIB(db, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db],
759               AC_CHECK_LIB(db, __db_ndbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db])
760             )
761           )
762         )
763       )
764       if test "$apu_have_ndbm" != "0";  then
765         if test "$withval" != "yes"; then
766           APR_ADDTO(APRUTIL_INCLUDES, [$NDBM_INC])
767           APR_ADDTO(APRUTIL_LDFLAGS, [$NDBM_LDFLAGS])
768         fi
769       elif test "$withval" != "yes"; then
770         AC_ERROR( NDBM not found in the specified directory)
771       fi
772     fi
773     CPPFLAGS="$save_cppflags"
774     LDFLAGS="$save_ldflags"
775   ], [
776     dnl don't check it no one has asked us for it
777     apu_have_ndbm=0
778   ])
781   if test -n "$apu_db_xtra_libs"; then
782     saveddbxtralibs="$LIBS"
783     LIBS="$apu_db_xtra_libs $LIBS"
784   fi
786   dnl We're going to try to find the highest version of Berkeley DB supported.
787   dnl
788   dnl Note that we only do this if the user requested it, since the Sleepycat
789   dnl license is viral and requires distribution of source along with programs
790   dnl that use it.
791   AC_ARG_WITH([berkeley-db], [APR_HELP_STRING([--with-berkeley-db=PATH],
792       [Find the Berkeley DB header and library in `PATH/include' and
793       `PATH/lib'.  If PATH is of the form `HEADER:LIB', then search
794       for header files in HEADER, and the library in LIB.  If you omit
795       the `=PATH' part completely, the configure script will search
796       for Berkeley DB in a number of standard places.])],
797   [
798     if test "$withval" = "yes"; then
799       apu_want_db=1
800       user_places=""
801     elif test "$withval" = "no"; then
802       apu_want_db=0
803     else
804       apu_want_db=1
805       user_places="$withval"
806     fi
808     if test "$apu_want_db" != "0"; then
809       APU_CHECK_DB($requested, $user_places)
810       if test "$apu_have_db" = "0"; then
811         AC_ERROR(Berkeley DB not found.)
812       fi
813     fi 
814   ])
816   if test -n "$apu_db_xtra_libs"; then
817     LIBS="$saveddbxtralibs"
818   fi
820   case "$requested" in
821     sdbm)
822       apu_use_sdbm=1
823       apu_default_dbm=sdbm
824       ;;
825     gdbm)
826       apu_use_gdbm=1
827       apu_default_dbm=gdbm
828       ;;
829     ndbm)
830       apu_use_ndbm=1
831       apu_default_dbm=ndbm
832       ;;
833     db)
834       apu_use_db=1
835       apu_default_dbm=db
836       ;;
837     db1)
838       apu_use_db=1
839       apu_default_dbm=db1
840       ;;
841     db185)
842       apu_use_db=1
843       apu_default_dbm=db185
844       ;;
845     db2)
846       apu_use_db=1
847       apu_default_dbm=db2
848       ;;
849     db3)
850       apu_use_db=1
851       apu_default_dbm=db3
852       ;;
853     db4)
854       apu_use_db=1
855       apu_default_dbm=db4
856       ;;
857     db41)
858       apu_use_db=1
859       apu_default_dbm=db4
860       ;;
861     db42)
862       apu_use_db=1
863       apu_default_dbm=db4
864       ;;
865     db43)
866       apu_use_db=1
867       apu_default_dbm=db4
868       ;;
869     db44)
870       apu_use_db=1
871       apu_default_dbm=db4
872       ;;
873     db45)
874       apu_use_db=1
875       apu_default_dbm=db4
876       ;;
877     db46)
878       apu_use_db=1
879       apu_default_dbm=db4
880       ;;
881     db47)
882       apu_use_db=1
883       apu_default_dbm=db4
884       ;;
885     default)
886       dnl ### use more sophisticated DBMs for the default?
887       apu_default_dbm="sdbm (default)"
888       apu_use_sdbm=1
889       ;;
890     *)
891       AC_MSG_ERROR([--with-dbm=$look_for is an unknown DBM type.
892         Use one of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4, db41, db42, db43, db44, db45, db46, db47])
893       ;;
894   esac
896   dnl Yes, it'd be nice if we could collate the output in an order
897   dnl so that the AC_MSG_CHECKING would be output before the actual
898   dnl checks, but it isn't happening now.
899   AC_MSG_CHECKING(for default DBM)
900   AC_MSG_RESULT($apu_default_dbm)
902   AC_SUBST(apu_use_sdbm)
903   AC_SUBST(apu_use_gdbm)
904   AC_SUBST(apu_use_ndbm)
905   AC_SUBST(apu_use_db)
907   AC_SUBST(apu_have_sdbm)
908   AC_SUBST(apu_have_gdbm)
909   AC_SUBST(apu_have_ndbm)
910   AC_SUBST(apu_have_db)
911   AC_SUBST(apu_db_header)
912   AC_SUBST(apu_db_version)
914   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
915   dnl we know the library is there.
916   if test "$apu_have_gdbm" = "1"; then
917     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lgdbm])
918     APR_ADDTO(APRUTIL_LIBS,[-lgdbm])
919   fi
921   if test "$apu_have_ndbm" = "1"; then
922     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l$apu_ndbm_lib])
923     APR_ADDTO(APRUTIL_LIBS,[-l$apu_ndbm_lib])
924   fi
926   if test "$apu_have_db" = "1"; then
927     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l$apu_db_lib])
928     APR_ADDTO(APRUTIL_LIBS,[-l$apu_db_lib])
929     if test -n "apu_db_xtra_libs"; then
930       APR_ADDTO(APRUTIL_EXPORT_LIBS,[$apu_db_xtra_libs])
931       APR_ADDTO(APRUTIL_LIBS,[$apu_db_xtra_libs])
932     fi
933   fi