dnl -------------------------------------------------------- -*- autoconf -*- dnl Copyright 2007 The Apache Software Foundation or its licensors, dnl as applicable. dnl dnl Licensed under the Apache License, Version 2.0 (the "License"); dnl you may not use this file except in compliance with the License. dnl You may obtain a copy of the License at dnl dnl http://www.apache.org/licenses/LICENSE-2.0 dnl dnl Unless required by applicable law or agreed to in writing, software dnl distributed under the License is distributed on an "AS IS" BASIS, dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. dnl See the License for the specific language governing permissions and dnl limitations under the License. dnl The standard places we expect to find Berkeley DB installed. dnl The original version of this code didn't have the same requirement. std_dirs="/usr /usr/local /boot/home/config" dnl TS_LIB_BERKELEY_DB(major, minor, patch, places, headers, libnames) dnl dnl Search for a useable version of Berkeley DB in a number of dnl common places. The installed DB must be no older than the dnl version given by MAJOR, MINOR, and PATCH. All of these dnl arguments are allowed to be '-1', indicating we don't care. dnl PLACES is a list of places to search for a Berkeley DB dnl installation. HEADERS is a list of headers to try. LIBNAMES dnl is a list of names of the library to attempt to link against, dnl typically 'db' and 'db4'. dnl dnl If we find a useable version, set CPPFLAGS and LIBS as dnl appropriate, and set the shell variable `ts_have_db' to dnl `1', and ts_db_lib to the matching lib name, and ts_db_header dnl to the header to use. Otherwise, set `ts_have_db' to `0'. dnl dnl This macro also checks for the `--with-berkeley-db=PATH' flag; dnl if given, the macro will use the PATH specified, and the dnl configuration script will die if it can't find the library. If dnl the user gives the `--without-berkeley-db' flag, the entire dnl search is skipped. dnl dnl We cache the results of individual searches under particular dnl prefixes, not the overall result of whether we found Berkeley dnl DB. That way, the user can re-run the configure script with dnl different --with-berkeley-db switch values, without interference dnl from the cache. AC_DEFUN([TS_CHECK_BERKELEY_DB], [ bdb_version=$1 if test "$2" != "-1"; then bdb_version="$bdb_version.$2" if test "$3" != "-1"; then bdb_version="$bdb_version.$3" fi fi bdb_places=$4 bdb_default_search_headers=$5 bdb_default_search_lib_names=$6 ts_have_db=0 # Save the original values of the flags we tweak. ts_check_lib_save_libs="$LIBS" ts_check_lib_save_ldflags="$LDFLAGS" ts_check_lib_save_cppflags="$CPPFLAGS" # The variable `found' is the prefix under which we've found # Berkeley DB, or `not' if we haven't found it anywhere yet. found=not for bdb_place in $bdb_places; do LDFLAGS="$ts_check_lib_save_ldflags" CPPFLAGS="$ts_check_lib_save_cppflags" case "$bdb_place" in "$std_dirs" ) description="the standard places" ;; *":"* ) header="`echo $bdb_place | sed -e 's/:.*$//'`" lib="`echo $bdb_place | sed -e 's/^.*://'`" CPPFLAGS="$CPPFLAGS -I$header" LDFLAGS="$LDFLAGS -L$lib" description="$header and $lib" ;; * ) if test -d $bdb_place && test -d $bdb_place/lib && test -d $bdb_place/include; then LDFLAGS="$LDFLAGS -L$bdb_place/lib" CPPFLAGS="$CPPFLAGS -I$bdb_place/include" else AC_MSG_CHECKING([for Berkeley DB $bdb_version in $bdb_place]) AC_MSG_RESULT([directory not found]) continue fi description="$bdb_place" ;; esac # Since there is no AC_MSG_NOTICE in autoconf 2.13, we use this # trick to display a message instead. AC_MSG_CHECKING([for Berkeley DB $bdb_version in $description]) AC_MSG_RESULT() for bdb_libname in $bdb_default_search_lib_names; do for bdb_header in $bdb_default_search_headers; do # Clear the header cache variable for each location changequote(,) cache_id="`echo ac_cv_header_${bdb_header} \ | sed -e 's/[^a-zA-Z0-9_]/_/g'`" changequote([,]) unset $cache_id AC_CHECK_HEADER([$bdb_header], [ if test "$1" = "3" -o "$1" = "4"; then # We generate a separate cache variable for each prefix and libname # we search under. That way, we avoid caching information that # changes if the user runs `configure' with a different set of # switches. changequote(,) cache_id="`echo ts_cv_check_berkeley_db_$1_$2_$3_${bdb_header}_${bdb_libname}_in_${bdb_place} \ | sed -e 's/[^a-zA-Z0-9_]/_/g'`" changequote([,]) AC_MSG_CHECKING([for -l$bdb_libname]) dnl We can't use AC_CACHE_CHECK here, because that won't print out dnl the value of the computed cache variable properly. AC_CACHE_VAL($cache_id, [ TS_TRY_BERKELEY_DB($1, $2, $3, $bdb_header, $bdb_libname) eval "$cache_id=$ts_try_berkeley_db" ]) result="`eval echo '$'$cache_id`" AC_MSG_RESULT($result) elif test "$1" = "1"; then AC_CHECK_LIB($bdb_libname, dbopen, [result=yes], [result=no] ) elif test "$1" = "2"; then AC_CHECK_LIB($bdb_libname, db_open, [result=yes], [result=no] ) fi ], [result="no"]) # If we found it, no need to search any more. if test "$result" = "yes"; then found="$bdb_place" break fi done test "$found" != "not" && break done test "$found" != "not" && break done # Restore the original values of the flags we tweak. LDFLAGS="$ts_check_lib_save_ldflags" CPPFLAGS="$ts_check_lib_save_cppflags" case "$found" in "not") ts_have_db=0 ;; "$std_dirs") ts_db_dir=$found ts_db_header=$bdb_header ts_db_lib=$bdb_libname ts_have_db=1 ;; *":"*) ts_bdb_dir=$found header="`echo $found | sed -e 's/:.*$//'`" lib="`echo $found | sed -e 's/^.*://'`" ts_db_header=$bdb_header ts_db_lib=$bdb_libname ts_have_db=1 ;; *) ts_db_dir=$found ts_db_header=$bdb_header ts_db_lib=$bdb_libname ts_have_db=1 ;; esac ]) dnl TS_TRY_BERKELEY_DB(major, minor, patch, header, libname) dnl dnl A subroutine of TS_CHECK_BERKELEY_DB. dnl dnl Check that a new-enough version of Berkeley DB is installed. dnl "New enough" means no older than the version given by MAJOR, dnl MINOR, and PATCH. The result of the test is not cached; no dnl messages are printed. Use HEADER as the header file to include. dnl Use LIBNAME as the library to link against. dnl (e.g. LIBNAME should usually be "db" or "db4".) dnl dnl Set the shell variable `ts_try_berkeley_db' to `yes' if we found dnl an appropriate version installed, or `no' otherwise. dnl dnl This macro uses the Berkeley DB library function `db_version' to dnl find the version. If the library installed doesn't have this dnl function, then this macro assumes it is too old. dnl NOTE: This is pretty messed up. It seems that the FreeBSD port of dnl Berkeley DB 4 puts the header file in /usr/local/include/db4, but the dnl database library in /usr/local/lib, as libdb4.[a|so]. There is no dnl /usr/local/include/db.h. So if you check for /usr/local first, you'll dnl get the old header file from /usr/include, and the new library from dnl /usr/local/lib. Disaster. Thus this test compares the version constants dnl in the db.h header with the ones returned by db_version(). AC_DEFUN([TS_TRY_BERKELEY_DB], [ ts_try_berkeley_db_save_libs="$LIBS" ts_check_berkeley_db_major=$1 ts_check_berkeley_db_minor=$2 ts_check_berkeley_db_patch=$3 ts_try_berkeley_db_header=$4 ts_try_berkeley_db_libname=$5 LIBS="$LIBS -l$ts_try_berkeley_db_libname" AC_TRY_RUN( [ #include #include <$ts_try_berkeley_db_header> main () { int major, minor, patch; db_version(&major, &minor, &patch); /* Sanity check: ensure that db.h constants actually match the db library */ if (major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR || patch != DB_VERSION_PATCH) exit (1); /* Run-time check: ensure the library claims to be the correct version. */ if ($ts_check_berkeley_db_major != -1) { if (major < $ts_check_berkeley_db_major) exit (1); if (major > $ts_check_berkeley_db_major) exit (0); } if ($ts_check_berkeley_db_minor != -1) { if (minor < $ts_check_berkeley_db_minor) exit (1); if (minor > $ts_check_berkeley_db_minor) exit (0); } if ($ts_check_berkeley_db_patch == -1 || patch >= $ts_check_berkeley_db_patch) exit (0); else exit (1); } ], [ts_try_berkeley_db=yes], [ts_try_berkeley_db=no], [ts_try_berkeley_db=yes] ) LIBS="$ts_try_berkeley_db_save_libs" ] ) dnl dnl TS_CHECK_DB1: is DB1 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB1], [ places=$1 if test -z "$places"; then places="$std_dirs" fi TS_CHECK_BERKELEY_DB(1, 0, 0, "$places", "db1/db.h db.h", "db1" ) if test "$ts_have_db" = "1"; then ts_db_version=1 fi ]) dnl dnl TS_CHECK_DB185: is DB1.85 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl dnl NB: BerkelyDB v2 and above can be compiled in 1.85 mode dnl which has a libdb not libdb1 or libdb185 AC_DEFUN([TS_CHECK_DB185], [ places=$1 if test -z "$places"; then places="$std_dirs" fi TS_CHECK_BERKELEY_DB(1, -1, -1, "$places", "db_185.h", "db" ) if test "$ts_have_db" = "1"; then ts_db_version=185 fi ]) dnl dnl TS_CHECK_DB2: is DB2 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB2], [ places=$1 if test -z "$places"; then places="$std_dirs" fi TS_CHECK_BERKELEY_DB(2, -1, -1, "$places", "db2/db.h db.h", "db2 db" ) if test "$ts_have_db" = "1"; then ts_db_version=2 fi ]) dnl dnl TS_CHECK_DB3: is DB3 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB3], [ places=$1 if test -z "$places"; then places="$std_dirs" fi TS_CHECK_BERKELEY_DB(3, -1, -1, "$places", "db3/db.h db.h", "db3 db" ) if test "$ts_have_db" = "1"; then ts_db_version=3 fi ]) dnl dnl TS_CHECK_DB4: is DB4 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB4], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.0" fi TS_CHECK_BERKELEY_DB("4", "0", "-1", "$places", "db4/db.h db.h", "db-4.0 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB41: is DB4.1 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB41], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.1 /boot/home/config" fi TS_CHECK_BERKELEY_DB("4", "1", "-1", "$places", "db41/db.h db4/db.h db.h", "db-4.1 db41 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB42: is DB4.2 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB42], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.2" fi TS_CHECK_BERKELEY_DB("4", "2", "-1", "$places", "db42/db.h db4/db.h db.h", "db-4.2 db42 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB43: is DB4.3 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB43], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.3" fi TS_CHECK_BERKELEY_DB("4", "3", "-1", "$places", "db43/db.h db4/db.h db.h", "db-4.3 db4-4.3 db43 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB44: is DB4.4 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB44], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.4" fi TS_CHECK_BERKELEY_DB("4", "4", "-1", "$places", "db44/db.h db4/db.h db.h", "db-4.4 db4-4.4 db44 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB45: is DB4.5 present? dnl dnl if present: sets ts_db_header, ts_db_lib, and ts_db_version dnl AC_DEFUN([TS_CHECK_DB45], [ places=$1 if test -z "$places"; then places="$std_dirs /usr/local/BerkeleyDB.4.5" fi TS_CHECK_BERKELEY_DB("4", "5", "-1", "$places", "db45/db.h db4/db.h db.h", "db-4.5 db4-4.5 db45 db4 db" ) if test "$ts_have_db" = "1"; then ts_db_version=4 fi ]) dnl dnl TS_CHECK_DB_ALL: Try all Berkeley DB versions dnl AC_DEFUN([TS_CHECK_DB_ALL], [ all_places=$1 TS_CHECK_DB45("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB44("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB43("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB42("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB41("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB4("$all_places") if test "$ts_db_version" != "4"; then TS_CHECK_DB3("$all_places") if test "$ts_db_version" != "3"; then TS_CHECK_DB2("$all_places") if test "$ts_db_version" != "2"; then TS_CHECK_DB1("$all_places") if test "$ts_db_version" != "1"; then TS_CHECK_DB185("$all_places") fi fi fi fi fi fi fi fi fi AC_MSG_CHECKING(for Berkeley DB) if test "$ts_have_db" = "1"; then AC_MSG_RESULT(found db$ts_db_version) else AC_MSG_RESULT(not found) fi ]) dnl dnl TS_FIND_BERKELEY_DB: find the highest version of Berkeley DB available dnl on the system. This is needed for RDFStore. dnl AC_DEFUN([TS_FIND_BERKELEY_DB], [ ts_have_db=0 user_places='' ts_db_header=db.h ts_db_version=0 ts_db_dir='' if test -n "$ts_db_xtra_libs"; then saveddbxtralibs="$LIBS" LIBS="$ts_db_xtra_libs $LIBS" fi AC_MSG_RESULT(Looking for Berkeley DB...) dnl We're going to try to find the highest version of Berkeley DB supported. AC_ARG_WITH([berkeley-db], [ --with-berkeley-db=PATH Find the Berkeley DB header and library in `PATH/include' and `PATH/lib'. If PATH is of the form `HEADER:LIB', then search for header files in HEADER, and the library in LIB. If you omit the `=PATH' part completely, the configure script will search for Berkeley DB in a number of standard places.] , [ user_places="$withval" ]) if test -n "$user_places"; then TS_CHECK_DB_ALL() else TS_CHECK_DB_ALL($user_places) fi if test "$ts_have_db" = "0"; then AC_ERROR(Berkeley DB not found.) fi if test -n "$ts_db_xtra_libs"; then LIBS="$saveddbxtralibs" fi dnl Yes, it'd be nice if we could collate the output in an order dnl so that the AC_MSG_CHECKING would be output before the actual dnl checks, but it isn't happening now. AC_MSG_CHECKING(Berkeley DB version) AC_MSG_RESULT($ts_db_version) AC_SUBST(ts_db_dir) AC_SUBST(ts_db_lib) AC_SUBST(ts_db_version) ])