1dnl -------------------------------------------------------- -*- autoconf -*-
2dnl Copyright 2002-2005 The Apache Software Foundation or its licensors, as
3dnl applicable.
4dnl
5dnl Licensed under the Apache License, Version 2.0 (the "License");
6dnl you may not use this file except in compliance with the License.
7dnl You may obtain a copy of the License at
8dnl
9dnl     http://www.apache.org/licenses/LICENSE-2.0
10dnl
11dnl Unless required by applicable law or agreed to in writing, software
12dnl distributed under the License is distributed on an "AS IS" BASIS,
13dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dnl See the License for the specific language governing permissions and
15dnl limitations under the License.
16
17
18dnl
19dnl DBM module
20dnl
21
22dnl   APU_LIB_BERKELEY_DB(major, minor, patch, places, headers, libnames)
23dnl
24dnl   Search for a useable version of Berkeley DB in a number of
25dnl   common places.  The installed DB must be no older than the
26dnl   version given by MAJOR, MINOR, and PATCH.  All of these
27dnl   arguments are allowed to be '-1', indicating we don't care.
28dnl   PLACES is a list of places to search for a Berkeley DB
29dnl   installation.  HEADERS is a list of headers to try.  LIBNAMES
30dnl   is a list of names of the library to attempt to link against,
31dnl   typically 'db' and 'db4'.
32dnl
33dnl   If we find a useable version, set CPPFLAGS and LIBS as
34dnl   appropriate, and set the shell variable `apu_have_db' to
35dnl   `1', and apu_db_lib to the matching lib name, and apu_db_header
36dnl   to the header to use.  Otherwise, set `apu_have_db' to `0'.
37dnl
38dnl   This macro also checks for the `--with-berkeley-db=PATH' flag;
39dnl   if given, the macro will use the PATH specified, and the
40dnl   configuration script will die if it can't find the library.  If
41dnl   the user gives the `--without-berkeley-db' flag, the entire
42dnl   search is skipped.
43dnl
44dnl   We cache the results of individual searches under particular
45dnl   prefixes, not the overall result of whether we found Berkeley
46dnl   DB.  That way, the user can re-run the configure script with
47dnl   different --with-berkeley-db switch values, without interference
48dnl   from the cache.
49
50
51AC_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
62
63  apu_have_db=0
64
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"
69
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
74
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
100
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()
105
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([,])
124
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
160
161  # Restore the original values of the flags we tweak.
162  LDFLAGS="$apu_check_lib_save_ldflags"
163  CPPFLAGS="$apu_check_lib_save_cppflags"
164
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/^.*://'`"
177
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
192])
193
194
195dnl   APU_TRY_BERKELEY_DB(major, minor, patch, header, libname)
196dnl
197dnl   A subroutine of APU_CHECK_BERKELEY_DB.
198dnl
199dnl   Check that a new-enough version of Berkeley DB is installed.
200dnl   "New enough" means no older than the version given by MAJOR,
201dnl   MINOR, and PATCH.  The result of the test is not cached; no
202dnl   messages are printed.  Use HEADER as the header file to include.
203dnl   Use LIBNAME as the library to link against.
204dnl   (e.g. LIBNAME should usually be "db" or "db4".)
205dnl
206dnl   Set the shell variable `apu_try_berkeley_db' to `yes' if we found
207dnl   an appropriate version installed, or `no' otherwise.
208dnl
209dnl   This macro uses the Berkeley DB library function `db_version' to
210dnl   find the version.  If the library installed doesn't have this
211dnl   function, then this macro assumes it is too old.
212
213dnl   NOTE: This is pretty messed up.  It seems that the FreeBSD port of
214dnl   Berkeley DB 4 puts the header file in /usr/local/include/db4, but the
215dnl   database library in /usr/local/lib, as libdb4.[a|so].  There is no
216dnl   /usr/local/include/db.h.  So if you check for /usr/local first, you'll
217dnl   get the old header file from /usr/include, and the new library from
218dnl   /usr/local/lib.  Disaster.  Thus this test compares the version constants
219dnl   in the db.h header with the ones returned by db_version().
220
221
222AC_DEFUN([APU_TRY_BERKELEY_DB],
223  [
224    apu_try_berkeley_db_save_libs="$LIBS"
225
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
231
232    LIBS="$LIBS -l$apu_try_berkeley_db_libname"
233    AC_TRY_RUN(
234      [
235#include <stdio.h>
236#include <$apu_try_berkeley_db_header>
237main ()
238{
239  int major, minor, patch;
240
241  db_version(&major, &minor, &patch);
242
243  /* Sanity check: ensure that db.h constants actually match the db library */
244  if (major != DB_VERSION_MAJOR
245      || minor != DB_VERSION_MINOR
246      || patch != DB_VERSION_PATCH)
247    exit (1);
248
249  /* Run-time check:  ensure the library claims to be the correct version. */
250
251  if ($apu_check_berkeley_db_major != -1) {
252    if (major < $apu_check_berkeley_db_major)
253      exit (1);
254    if (major > $apu_check_berkeley_db_major)
255      exit (0);
256  }
257
258  if ($apu_check_berkeley_db_minor != -1) {
259    if (minor < $apu_check_berkeley_db_minor)
260      exit (1);
261    if (minor > $apu_check_berkeley_db_minor)
262      exit (0);
263  }
264
265  if ($apu_check_berkeley_db_patch == -1
266      || patch >= $apu_check_berkeley_db_patch)
267    exit (0);
268  else
269    exit (1);
270}
271      ],
272      [apu_try_berkeley_db=yes],
273      [apu_try_berkeley_db=no],
274      [apu_try_berkeley_db=yes]
275    )
276
277    LIBS="$apu_try_berkeley_db_save_libs"
278  ]
279)
280
281
282dnl
283dnl APU_CHECK_DB1: is DB1 present?
284dnl
285dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
286dnl
287AC_DEFUN([APU_CHECK_DB1], [
288  places=$1
289  if test -z "$places"; then
290    places="std"
291  fi
292  APU_CHECK_BERKELEY_DB(1, 0, 0,
293    "$places",
294    "db1/db.h db.h",
295    "db1"
296  )
297  if test "$apu_have_db" = "1"; then
298    apu_db_version=1
299  fi
300])
301
302
303dnl
304dnl APU_CHECK_DB185: is DB1.85 present?
305dnl
306dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
307dnl
308dnl NB: BerkelyDB v2 and above can be compiled in 1.85 mode
309dnl which has a libdb not libdb1 or libdb185
310AC_DEFUN([APU_CHECK_DB185], [
311  places=$1
312  if test -z "$places"; then
313    places="std"
314  fi
315  APU_CHECK_BERKELEY_DB(1, -1, -1,
316    "$places",
317    "db_185.h",
318    "db"
319  )
320  if test "$apu_have_db" = "1"; then
321    apu_db_version=185
322  fi
323])
324
325
326dnl
327dnl APU_CHECK_DB2: is DB2 present?
328dnl
329dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
330dnl
331AC_DEFUN([APU_CHECK_DB2], [
332  places=$1
333  if test -z "$places"; then
334    places="std"
335  fi
336  APU_CHECK_BERKELEY_DB(2, -1, -1,
337    "$places",
338    "db2/db.h db.h",
339    "db2 db"
340  )
341  if test "$apu_have_db" = "1"; then
342    apu_db_version=2
343  fi
344])
345
346
347dnl
348dnl APU_CHECK_DB3: is DB3 present?
349dnl
350dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
351dnl
352AC_DEFUN([APU_CHECK_DB3], [
353  places=$1
354  if test -z "$places"; then
355    places="std"
356  fi
357  APU_CHECK_BERKELEY_DB(3, -1, -1,
358    "$places",
359    "db3/db.h db.h",
360    "db3 db"
361  )
362  if test "$apu_have_db" = "1"; then
363    apu_db_version=3
364  fi
365])
366
367
368dnl
369dnl APU_CHECK_DB4: is DB4 present?
370dnl
371dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
372dnl
373AC_DEFUN([APU_CHECK_DB4], [
374  places=$1
375  if test -z "$places"; then
376    places="std /usr/local /usr/local/BerkeleyDB.4.0 /boot/home/config"
377  fi
378  APU_CHECK_BERKELEY_DB("4", "0", "-1",
379    "$places",
380    "db4/db.h db.h",
381    "db-4.0 db4 db"
382  )
383  if test "$apu_have_db" = "1"; then
384    apu_db_version=4
385  fi
386])
387
388
389dnl
390dnl APU_CHECK_DB41: is DB4.1 present?
391dnl
392dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
393dnl
394AC_DEFUN([APU_CHECK_DB41], [
395  places=$1
396  if test -z "$places"; then
397    places="std /usr/local /usr/local/BerkeleyDB.4.1 /boot/home/config"
398  fi
399  APU_CHECK_BERKELEY_DB("4", "1", "-1",
400    "$places",
401    "db41/db.h db4/db.h db.h",
402    "db-4.1 db41 db4 db"
403  )
404  if test "$apu_have_db" = "1"; then
405    apu_db_version=4
406  fi
407])
408
409
410dnl
411dnl APU_CHECK_DB42: is DB4.2 present?
412dnl
413dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
414dnl
415AC_DEFUN([APU_CHECK_DB42], [
416  places=$1
417  if test -z "$places"; then
418    places="std /usr/local /usr/local/BerkeleyDB.4.2 /boot/home/config"
419  fi
420  APU_CHECK_BERKELEY_DB("4", "2", "-1",
421    "$places",
422    "db42/db.h db4/db.h db.h",
423    "db-4.2 db42 db4 db"
424  )
425  if test "$apu_have_db" = "1"; then
426    apu_db_version=4
427  fi
428])
429dnl
430dnl APU_CHECK_DB43: is DB4.3 present?
431dnl
432dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
433dnl
434AC_DEFUN([APU_CHECK_DB43], [
435  places=$1
436  if test -z "$places"; then
437    places="std /usr/local/BerkeleyDB.4.3 /boot/home/config"
438  fi
439  APU_CHECK_BERKELEY_DB("4", "3", "-1",
440    "$places",
441    "db43/db.h db4/db.h db.h",
442    "db-4.3 db4-4.3 db43 db4 db"
443  )
444  if test "$apu_have_db" = "1"; then
445    apu_db_version=4
446  fi
447])
448dnl
449dnl APU_CHECK_DB44: is DB4.4 present?
450dnl
451dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
452dnl
453AC_DEFUN([APU_CHECK_DB44], [
454  places=$1
455  if test -z "$places"; then
456    places="std /usr/local/BerkeleyDB.4.4 /boot/home/config"
457  fi
458  APU_CHECK_BERKELEY_DB("4", "4", "-1",
459    "$places",
460    "db44/db.h db4/db.h db.h",
461    "db-4.4 db4-4.4 db44 db4 db"
462  )
463  if test "$apu_have_db" = "1"; then
464    apu_db_version=4
465  fi
466])
467dnl
468dnl APU_CHECK_DB45: is DB4.5 present?
469dnl
470dnl if present: sets apu_db_header, apu_db_lib, and apu_db_version
471dnl
472AC_DEFUN([APU_CHECK_DB45], [
473  places=$1
474  if test -z "$places"; then
475    places="std /usr/local/BerkeleyDB.4.5 /boot/home/config"
476  fi
477  APU_CHECK_BERKELEY_DB("4", "5", "-1",
478    "$places",
479    "db45/db.h db4/db.h db.h",
480    "db-4.5 db4-4.5 db45 db4 db"
481  )
482  if test "$apu_have_db" = "1"; then
483    apu_db_version=4
484  fi
485])
486
487AC_DEFUN([APU_CHECK_DB], [
488  requested=$1
489  check_places=$2
490
491  case "$requested" in
492  db)
493    APU_CHECK_DB_ALL("$check_places")
494    if test "$apu_have_db" = "0"; then
495      AC_MSG_ERROR(Berkeley db requested, but not found)
496    fi
497    ;;
498  db1)
499    APU_CHECK_DB1("$check_places")
500    if test "$apu_db_version" != "1"; then
501      AC_MSG_ERROR(Berkeley db1 not found)
502    fi
503    ;;
504  db185)
505    APU_CHECK_DB185("$check_places")
506    if test "$apu_db_version" != "185"; then
507      AC_MSG_ERROR(Berkeley db185 not found)
508    fi
509    ;;
510  db2)
511    APU_CHECK_DB2("$check_places")
512    if test "$apu_db_version" != "2"; then
513      AC_MSG_ERROR(Berkeley db2 not found)
514    fi
515    ;;
516  db3)
517    APU_CHECK_DB3("$check_places")
518    if test "$apu_db_version" != "3"; then
519      AC_MSG_ERROR(Berkeley db3 not found)
520    fi
521    ;;
522  db4)
523    APU_CHECK_DB4("$check_places")
524    if test "$apu_db_version" != "4"; then
525      AC_MSG_ERROR(Berkeley db4 not found)
526    fi
527    ;;
528  db41)
529    APU_CHECK_DB41("$check_places")
530    if test "$apu_db_version" != "4"; then
531      AC_MSG_ERROR(Berkeley db4 not found)
532    fi
533    ;;
534  db42)
535    APU_CHECK_DB42("$check_places")
536    if test "$apu_db_version" != "4"; then
537      AC_MSG_ERROR(Berkeley db4 not found)
538    fi
539    ;;
540  db43)
541    APU_CHECK_DB43("$check_places")
542    if test "$apu_db_version" != "4"; then
543      AC_MSG_ERROR(Berkeley db4 not found)
544    fi
545    ;;
546  db44)
547    APU_CHECK_DB44("$check_places")
548    if test "$apu_db_version" != "4"; then
549      AC_MSG_ERROR(Berkeley db4 not found)
550    fi
551    ;;
552  db45)
553    APU_CHECK_DB44("$check_places")
554    if test "$apu_db_version" != "4"; then
555      AC_MSG_ERROR(Berkeley db4 not found)
556    fi
557    ;;
558  default)
559    APU_CHECK_DB_ALL("$check_places")
560    ;;
561  esac
562])
563
564dnl
565dnl APU_CHECK_DB_ALL: Try all Berkeley DB versions, from 4.3 to 1.
566dnl
567AC_DEFUN([APU_CHECK_DB_ALL], [
568  all_places=$1
569
570  APU_CHECK_DB45("$all_places")
571  if test "$apu_db_version" != "4"; then
572    APU_CHECK_DB44("$all_places")
573    if test "$apu_db_version" != "4"; then
574      APU_CHECK_DB43("$all_places")
575      if test "$apu_db_version" != "4"; then
576        APU_CHECK_DB42("$all_places")
577        if test "$apu_db_version" != "4"; then
578          APU_CHECK_DB41("$all_places")
579          if test "$apu_db_version" != "4"; then
580            APU_CHECK_DB4("$all_places")
581            if test "$apu_db_version" != "4"; then
582              APU_CHECK_DB3("$all_places")
583              if test "$apu_db_version" != "3"; then
584                APU_CHECK_DB2("$all_places")
585                if test "$apu_db_version" != "2"; then
586                  APU_CHECK_DB1("$all_places")
587                  if test "$apu_db_version" != "1"; then
588                    APU_CHECK_DB185("$all_places")
589                  fi
590                fi
591              fi
592            fi
593          fi
594        fi
595      fi
596    fi
597  fi
598  AC_MSG_CHECKING(for Berkeley DB)
599  if test "$apu_have_db" = "1"; then
600    AC_MSG_RESULT(found db$apu_db_version)
601  else
602    AC_MSG_RESULT(not found)
603  fi
604])
605
606
607dnl
608dnl APU_CHECK_DBM: see what kind of DBM backend to use for apr_dbm.
609dnl
610AC_DEFUN([APU_CHECK_DBM], [
611  apu_use_sdbm=0
612  apu_use_ndbm=0
613  apu_use_gdbm=0
614  apu_use_db=0
615  dnl it's in our codebase
616  apu_have_sdbm=1
617  apu_have_gdbm=0
618  apu_have_ndbm=0
619  apu_have_db=0
620
621  apu_db_header=db.h                # default so apu_select_dbm.h is syntactically correct
622  apu_db_version=0
623
624  AC_ARG_WITH(dbm, [
625    --with-dbm=DBM          choose the DBM type to use.
626      DBM={sdbm,gdbm,ndbm,db,db1,db185,db2,db3,db4,db41,db42,db43,db44,db45}
627  ], [
628    if test "$withval" = "yes"; then
629      AC_MSG_ERROR([--with-dbm needs to specify a DBM type to use.
630        One of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4, db41, db42, db43, db44, db45])
631    fi
632    requested="$withval"
633  ], [
634    requested=default
635  ])
636
637  dnl We don't pull in GDBM unless the user asks for it, since it's GPL
638  AC_ARG_WITH([gdbm], [
639    --with-gdbm=DIR          specify GDBM location
640  ], [
641    apu_have_gdbm=0
642    if test "$withval" = "yes"; then
643      AC_CHECK_HEADER(gdbm.h, AC_CHECK_LIB(gdbm, gdbm_open, [apu_have_gdbm=1]))
644    elif test "$withval" = "no"; then
645      apu_have_gdbm=0
646    else
647      CPPFLAGS="-I$withval/include"
648      LIBS="-L$withval/lib "
649
650      AC_MSG_CHECKING(checking for gdbm in $withval)
651      AC_CHECK_HEADER(gdbm.h, AC_CHECK_LIB(gdbm, gdbm_open, [apu_have_gdbm=1]))
652      if test "$apu_have_gdbm" != "0"; then
653        APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
654        APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
655      fi
656    fi
657  ])
658
659  AC_ARG_WITH([ndbm], [
660    --with-ndbm=PATH
661      Find the NDBM header and library in \`PATH/include' and
662      \`PATH/lib'.  If PATH is of the form \`HEADER:LIB', then search
663      for header files in HEADER, and the library in LIB.  If you omit
664      the \`=PATH' part completely, the configure script will search
665      for NDBM in a number of standard places.
666  ], [
667    apu_have_ndbm=0
668    if test "$withval" = "yes"; then
669      AC_MSG_CHECKING(checking for ndbm in the usual places)
670      apu_want_ndbm=1
671      NDBM_INC=""
672      NDBM_LDFLAGS=""
673    elif test "$withval" = "no"; then
674      apu_want_ndbm=0
675    else
676      apu_want_ndbm=1
677      case "$withval" in
678        *":"*)
679          NDBM_INC="-I`echo $withval |sed -e 's/:.*$//'`"
680          NDBM_LDFLAGS="-L`echo $withval |sed -e 's/^.*://'`"
681          AC_MSG_CHECKING(checking for ndbm includes with $NDBM_INC libs with $NDBM_LDFLAGS )
682        ;;
683        *)
684          NDBM_INC="-I$withval/include"
685          NDBM_LDFLAGS="-L$withval/lib"
686          AC_MSG_CHECKING(checking for ndbm includes in $withval)
687        ;;
688      esac
689    fi
690
691    save_cppflags="$CPPFLAGS"
692    save_ldflags="$LDFLAGS"
693    CPPFLAGS="$CPPFLAGS $NDBM_INC"
694    LDFLAGS="$LDFLAGS $NDBM_LDFLAGS"
695    dnl db_ndbm_open is what sleepcat's compatibility library actually has in it's lib
696    if test "$apu_want_ndbm" != "0"; then
697      AC_CHECK_HEADER(ndbm.h,
698        AC_CHECK_LIB(c, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=c],
699          AC_CHECK_LIB(dbm, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=dbm],
700            AC_CHECK_LIB(db, dbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db],
701              AC_CHECK_LIB(db, __db_ndbm_open, [apu_have_ndbm=1;apu_ndbm_lib=db])
702            )
703          )
704        )
705      )
706      if test "$apu_have_ndbm" != "0";  then
707        if test "$withval" != "yes"; then
708          APR_ADDTO(APRUTIL_INCLUDES, [$NDBM_INC])
709          APR_ADDTO(APRUTIL_LDFLAGS, [$NDBM_LDFLAGS])
710        fi
711      elif test "$withval" != "yes"; then
712        AC_ERROR( NDBM not found in the specified directory)
713      fi
714    fi
715    CPPFLAGS="$save_cppflags"
716    LDFLAGS="$save_ldflags"
717  ], [
718    dnl don't check it no one has asked us for it
719    apu_have_ndbm=0
720  ])
721
722
723  if test -n "$apu_db_xtra_libs"; then
724    saveddbxtralibs="$LIBS"
725    LIBS="$apu_db_xtra_libs $LIBS"
726  fi
727
728  dnl We're going to try to find the highest version of Berkeley DB supported.
729  dnl
730  dnl Note that we only do this if the user requested it, since the Sleepycat
731  dnl license is viral and requires distribution of source along with programs
732  dnl that use it.
733  AC_ARG_WITH([berkeley-db], [
734    --with-berkeley-db=PATH
735      Find the Berkeley DB header and library in \`PATH/include' and
736      \`PATH/lib'.  If PATH is of the form \`HEADER:LIB', then search
737      for header files in HEADER, and the library in LIB.  If you omit
738      the \`=PATH' part completely, the configure script will search
739      for Berkeley DB in a number of standard places.
740  ], [
741    if test "$withval" = "yes"; then
742      apu_want_db=1
743      user_places=""
744    elif test "$withval" = "no"; then
745      apu_want_db=0
746    else
747      apu_want_db=1
748      user_places="$withval"
749    fi
750
751    if test "$apu_want_db" != "0"; then
752      APU_CHECK_DB($requested, $user_places)
753      if test "$apu_have_db" = "0"; then
754        AC_ERROR(Berkeley DB not found.)
755      fi
756    fi
757  ])
758
759  if test -n "$apu_db_xtra_libs"; then
760    LIBS="$saveddbxtralibs"
761  fi
762
763  case "$requested" in
764    sdbm)
765      apu_use_sdbm=1
766      apu_default_dbm=sdbm
767      ;;
768    gdbm)
769      apu_use_gdbm=1
770      apu_default_dbm=gdbm
771      ;;
772    ndbm)
773      apu_use_ndbm=1
774      apu_default_dbm=ndbm
775      ;;
776    db)
777      apu_use_db=1
778      apu_default_dbm=db
779      ;;
780    db1)
781      apu_use_db=1
782      apu_default_dbm=db1
783      ;;
784    db185)
785      apu_use_db=1
786      apu_default_dbm=db185
787      ;;
788    db2)
789      apu_use_db=1
790      apu_default_dbm=db2
791      ;;
792    db3)
793      apu_use_db=1
794      apu_default_dbm=db3
795      ;;
796    db4)
797      apu_use_db=1
798      apu_default_dbm=db4
799      ;;
800    db41)
801      apu_use_db=1
802      apu_default_dbm=db4
803      ;;
804    db42)
805      apu_use_db=1
806      apu_default_dbm=db4
807      ;;
808    db43)
809      apu_use_db=1
810      apu_default_dbm=db4
811      ;;
812    db44)
813      apu_use_db=1
814      apu_default_dbm=db4
815      ;;
816    db45)
817      apu_use_db=1
818      apu_default_dbm=db4
819      ;;
820    default)
821      dnl ### use more sophisticated DBMs for the default?
822      apu_default_dbm="sdbm (default)"
823      apu_use_sdbm=1
824      ;;
825    *)
826      AC_MSG_ERROR([--with-dbm=$look_for is an unknown DBM type.
827        Use one of: sdbm, gdbm, ndbm, db, db1, db185, db2, db3, db4, db41, db42, db43, db44 db45])
828      ;;
829  esac
830
831  dnl Yes, it'd be nice if we could collate the output in an order
832  dnl so that the AC_MSG_CHECKING would be output before the actual
833  dnl checks, but it isn't happening now.
834  AC_MSG_CHECKING(for default DBM)
835  AC_MSG_RESULT($apu_default_dbm)
836
837  AC_SUBST(apu_use_sdbm)
838  AC_SUBST(apu_use_gdbm)
839  AC_SUBST(apu_use_ndbm)
840  AC_SUBST(apu_use_db)
841
842  AC_SUBST(apu_have_sdbm)
843  AC_SUBST(apu_have_gdbm)
844  AC_SUBST(apu_have_ndbm)
845  AC_SUBST(apu_have_db)
846  AC_SUBST(apu_db_header)
847  AC_SUBST(apu_db_version)
848
849  dnl Since we have already done the AC_CHECK_LIB tests, if we have it,
850  dnl we know the library is there.
851  if test "$apu_have_gdbm" = "1"; then
852    APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lgdbm])
853    APR_ADDTO(APRUTIL_LIBS,[-lgdbm])
854  fi
855
856  if test "$apu_have_ndbm" = "1"; then
857    APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l$apu_ndbm_lib])
858    APR_ADDTO(APRUTIL_LIBS,[-l$apu_ndbm_lib])
859  fi
860
861  if test "$apu_have_db" = "1"; then
862    APR_ADDTO(APRUTIL_EXPORT_LIBS,[-l$apu_db_lib])
863    APR_ADDTO(APRUTIL_LIBS,[-l$apu_db_lib])
864    if test -n "apu_db_xtra_libs"; then
865      APR_ADDTO(APRUTIL_EXPORT_LIBS,[$apu_db_xtra_libs])
866      APR_ADDTO(APRUTIL_LIBS,[$apu_db_xtra_libs])
867    fi
868  fi
869])
870
871