1 dnl # Copyright © 2008 Tim Toolan <toolan@ele.uri.edu>
3 dnl # Copying and distribution of this file, with or without modification,
4 dnl # are permitted in any medium without royalty provided the copyright notice
5 dnl # and this notice are preserved.
7 dnl #########################################################################
8 AC_DEFUN([AX_PATH_BDB], [
9 dnl # Used to indicate success or failure of this function.
12 # Add --with-bdb-dir option to configure.
13 AC_ARG_WITH([bdb-dir],
14 [AC_HELP_STRING([--with-bdb-dir=DIR],
15 [Berkeley DB installation directory])])
17 # Check if --with-bdb-dir was specified.
18 if test "x$with_bdb_dir" = "x" ; then
19 # No option specified, so just search the system.
20 AX_PATH_BDB_NO_OPTIONS([$1], [HIGHEST], [
24 # Set --with-bdb-dir option.
25 ax_path_bdb_INC="$with_bdb_dir/include"
26 ax_path_bdb_LIB="$with_bdb_dir/lib"
28 dnl # Save previous environment, and modify with new stuff.
29 ax_path_bdb_save_CPPFLAGS="$CPPFLAGS"
30 CPPFLAGS="-I$ax_path_bdb_INC $CPPFLAGS"
32 ax_path_bdb_save_LDFLAGS=$LDFLAGS
33 LDFLAGS="-L$ax_path_bdb_LIB $LDFLAGS"
35 # Check for specific header file db.h
36 AC_MSG_CHECKING([db.h presence in $ax_path_bdb_INC])
37 if test -f "$ax_path_bdb_INC/db.h" ; then
40 AX_PATH_BDB_NO_OPTIONS([$1], [ENVONLY], [
42 BDB_CPPFLAGS="-I$ax_path_bdb_INC"
43 BDB_LDFLAGS="-L$ax_path_bdb_LIB"
47 AC_MSG_NOTICE([no usable Berkeley DB not found])
50 dnl # Restore the environment.
51 CPPFLAGS="$ax_path_bdb_save_CPPFLAGS"
52 LDFLAGS="$ax_path_bdb_save_LDFLAGS"
56 dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND.
57 if test "$ax_path_bdb_ok" = "yes" ; then
58 m4_ifvaln([$2],[$2],[:])dnl
59 m4_ifvaln([$3],[else $3])dnl
64 dnl #########################################################################
65 dnl Check for berkeley DB of at least MINIMUM-VERSION on system.
67 dnl The OPTION argument determines how the checks occur, and can be one of:
69 dnl HIGHEST - Check both the environment and the default installation
70 dnl directories for Berkeley DB and choose the version that
71 dnl is highest. (default)
72 dnl ENVFIRST - Check the environment first, and if no satisfactory
73 dnl library is found there check the default installation
74 dnl directories for Berkeley DB which is /usr/local/BerkeleyDB*
75 dnl ENVONLY - Check the current environment only.
77 dnl Requires AX_PATH_BDB_PATH_GET_VERSION, AX_PATH_BDB_PATH_FIND_HIGHEST,
78 dnl AX_PATH_BDB_ENV_CONFIRM_LIB, AX_PATH_BDB_ENV_GET_VERSION, and
79 dnl AX_COMPARE_VERSION macros.
81 dnl Result: sets ax_path_bdb_no_options_ok to yes or no
82 dnl sets BDB_LIBS, BDB_CPPFLAGS, BDB_LDFLAGS, BDB_VERSION
84 dnl AX_PATH_BDB_NO_OPTIONS([MINIMUM-VERSION], [OPTION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
85 AC_DEFUN([AX_PATH_BDB_NO_OPTIONS], [
86 dnl # Used to indicate success or failure of this function.
87 ax_path_bdb_no_options_ok=no
89 # Values to add to environment to use Berkeley DB.
95 # Check cross compilation here.
96 if test "x$cross_compiling" = "xyes" ; then
97 # If cross compiling, can't use AC_RUN_IFELSE so do these tests.
98 # The AC_PREPROC_IFELSE confirms that db.h is preprocessable,
99 # and extracts the version number from it.
100 AC_MSG_CHECKING([for db.h])
102 AS_VAR_PUSHDEF([HEADER_VERSION],[ax_path_bdb_no_options_HEADER_VERSION])dnl
107 AX_PATH_BDB_STUFF DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH
110 # Extract version from preprocessor output.
111 HEADER_VERSION=`eval "$ac_cpp conftest.$ac_ext" 2> /dev/null \
112 | grep AX_PATH_BDB_STUFF | sed 's/[[^0-9,]]//g;s/,/./g;1q'`
115 if test "x$HEADER_VERSION" = "x" ; then
118 AC_MSG_RESULT([$HEADER_VERSION])
120 # Check that version is high enough.
121 AX_COMPARE_VERSION([$HEADER_VERSION],[ge],[$1],[
122 # get major and minor version numbers
123 AS_VAR_PUSHDEF([MAJ],[ax_path_bdb_no_options_MAJOR])dnl
124 MAJ=`echo $HEADER_VERSION | sed 's,\..*,,'`
125 AS_VAR_PUSHDEF([MIN],[ax_path_bdb_no_options_MINOR])dnl
126 MIN=`echo $HEADER_VERSION | sed 's,^[[0-9]]*\.,,;s,\.[[0-9]]*$,,'`
129 ax_path_bdb_no_options_save_LIBS="$LIBS"
131 # Check that we can link with the library.
132 AC_SEARCH_LIBS([db_version],
133 [db db-$MAJ.$MIN db$MAJ.$MIN db$MAJ$MIN db-$MAJ db$MAJ],[
134 # Sucessfully found library.
135 ax_path_bdb_no_options_ok=yes
136 BDB_VERSION=$HEADER_VERSION
138 # Extract library from LIBS
139 ax_path_bdb_no_options_LEN=` \
140 echo "x$ax_path_bdb_no_options_save_LIBS" \
141 | awk '{print(length)}'`
142 BDB_LIBS=`echo "x$LIBS " \
143 | sed "s/.\{$ax_path_bdb_no_options_LEN\}\$//;s/^x//;s/ //g"`
147 LIBS="$ax_path_bdb_no_options_save_LIBS"
149 AS_VAR_POPDEF([MAJ])dnl
150 AS_VAR_POPDEF([MIN])dnl
154 AS_VAR_POPDEF([HEADER_VERSION])dnl
156 # Not cross compiling.
157 # Check version of Berkeley DB in the current environment.
158 AX_PATH_BDB_ENV_GET_VERSION([
159 AX_COMPARE_VERSION([$ax_path_bdb_env_get_version_VERSION],[ge],[$1],[
160 # Found acceptable version in current environment.
161 ax_path_bdb_no_options_ok=yes
162 BDB_VERSION="$ax_path_bdb_env_get_version_VERSION"
163 BDB_LIBS="$ax_path_bdb_env_get_version_LIBS"
167 # Determine if we need to search /usr/local/BerkeleyDB*
168 ax_path_bdb_no_options_DONE=no
169 if test "x$2" = "xENVONLY" ; then
170 ax_path_bdb_no_options_DONE=yes
171 elif test "x$2" = "xENVFIRST" ; then
172 ax_path_bdb_no_options_DONE=$ax_path_bdb_no_options_ok
175 if test "$ax_path_bdb_no_options_DONE" = "no" ; then
176 # Check for highest in /usr/local/BerkeleyDB*
177 AX_PATH_BDB_PATH_FIND_HIGHEST([
178 if test "$ax_path_bdb_no_options_ok" = "yes" ; then
179 # If we already have an acceptable version use this if higher.
181 [$ax_path_bdb_path_find_highest_VERSION],[gt],[$BDB_VERSION])
183 # Since we didn't have an acceptable version check if this one is.
185 [$ax_path_bdb_path_find_highest_VERSION],[ge],[$1])
189 dnl # If result from _AX_COMPARE_VERSION is true we want this version.
190 if test "$ax_compare_version" = "true" ; then
191 ax_path_bdb_no_options_ok=yes
193 if test "x$ax_path_bdb_path_find_highest_DIR" != x ; then
194 BDB_CPPFLAGS="-I$ax_path_bdb_path_find_highest_DIR/include"
195 BDB_LDFLAGS="-L$ax_path_bdb_path_find_highest_DIR/lib"
197 BDB_VERSION="$ax_path_bdb_path_find_highest_VERSION"
202 dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND.
203 if test "$ax_path_bdb_no_options_ok" = "yes" ; then
204 AC_MSG_NOTICE([using Berkeley DB version $BDB_VERSION])
205 AC_DEFINE([HAVE_DB_H],[1],
206 [Define to 1 if you have the <db.h> header file.])
207 m4_ifvaln([$3],[$3])dnl
209 AC_MSG_NOTICE([no Berkeley DB version $1 or higher found])
210 m4_ifvaln([$4],[$4])dnl
212 ]) dnl AX_PATH_BDB_NO_OPTIONS
214 dnl #########################################################################
215 dnl Check the default installation directory for Berkeley DB which is
216 dnl of the form /usr/local/BerkeleyDB* for the highest version.
218 dnl Result: sets ax_path_bdb_path_find_highest_ok to yes or no,
219 dnl sets ax_path_bdb_path_find_highest_VERSION to version,
220 dnl sets ax_path_bdb_path_find_highest_DIR to directory.
222 dnl AX_PATH_BDB_PATH_FIND_HIGHEST([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
223 AC_DEFUN([AX_PATH_BDB_PATH_FIND_HIGHEST], [
224 dnl # Used to indicate success or failure of this function.
225 ax_path_bdb_path_find_highest_ok=no
227 AS_VAR_PUSHDEF([VERSION],[ax_path_bdb_path_find_highest_VERSION])dnl
230 ax_path_bdb_path_find_highest_DIR=''
232 # find highest verison in default install directory for Berkeley DB
233 AS_VAR_PUSHDEF([CURDIR],[ax_path_bdb_path_find_highest_CURDIR])dnl
234 AS_VAR_PUSHDEF([CUR_VERSION],[ax_path_bdb_path_get_version_VERSION])dnl
236 for CURDIR in `ls -d /usr/local/BerkeleyDB* 2> /dev/null`
238 AX_PATH_BDB_PATH_GET_VERSION([$CURDIR],[
239 AX_COMPARE_VERSION([$CUR_VERSION],[gt],[$VERSION],[
240 ax_path_bdb_path_find_highest_ok=yes
241 ax_path_bdb_path_find_highest_DIR="$CURDIR"
242 VERSION="$CUR_VERSION"
247 AS_VAR_POPDEF([VERSION])dnl
248 AS_VAR_POPDEF([CUR_VERSION])dnl
249 AS_VAR_POPDEF([CURDIR])dnl
251 dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND.
252 if test "$ax_path_bdb_path_find_highest_ok" = "yes" ; then
253 m4_ifvaln([$1],[$1],[:])dnl
254 m4_ifvaln([$2],[else $2])dnl
257 ]) dnl AX_PATH_BDB_PATH_FIND_HIGHEST
259 dnl #########################################################################
260 dnl Checks for Berkeley DB in specified directory's lib and include
263 dnl Result: sets ax_path_bdb_path_get_version_ok to yes or no,
264 dnl sets ax_path_bdb_path_get_version_VERSION to version.
266 dnl AX_PATH_BDB_PATH_GET_VERSION(BDB-DIR, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
267 AC_DEFUN([AX_PATH_BDB_PATH_GET_VERSION], [
268 dnl # Used to indicate success or failure of this function.
269 ax_path_bdb_path_get_version_ok=no
271 # Indicate status of checking for Berkeley DB header.
272 AC_MSG_CHECKING([in $1/include for db.h])
273 ax_path_bdb_path_get_version_got_header=no
274 test -f "$1/include/db.h" && ax_path_bdb_path_get_version_got_header=yes
275 AC_MSG_RESULT([$ax_path_bdb_path_get_version_got_header])
277 # Indicate status of checking for Berkeley DB library.
278 AC_MSG_CHECKING([in $1/lib for library -ldb])
280 ax_path_bdb_path_get_version_VERSION=''
282 if test -d "$1/include" && test -d "$1/lib" &&
283 test "$ax_path_bdb_path_get_version_got_header" = "yes" ; then
284 dnl # save and modify environment
285 ax_path_bdb_path_get_version_save_CPPFLAGS="$CPPFLAGS"
286 CPPFLAGS="-I$1/include $CPPFLAGS"
288 ax_path_bdb_path_get_version_save_LIBS="$LIBS"
291 ax_path_bdb_path_get_version_save_LDFLAGS="$LDFLAGS"
292 LDFLAGS="-L$1/lib $LDFLAGS"
294 # Compile and run a program that compares the version defined in
295 # the header file with a version defined in the library function
301 int main(int argc,char **argv)
303 int major,minor,patch;
305 db_version(&major,&minor,&patch);
307 printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH);
308 if (DB_VERSION_MAJOR == major && DB_VERSION_MINOR == minor &&
309 DB_VERSION_PATCH == patch)
316 # Program compiled and ran, so get version by adding argument.
317 ax_path_bdb_path_get_version_VERSION=`./conftest$ac_exeext x`
318 ax_path_bdb_path_get_version_ok=yes
321 dnl # restore environment
322 CPPFLAGS="$ax_path_bdb_path_get_version_save_CPPFLAGS"
323 LIBS="$ax_path_bdb_path_get_version_save_LIBS"
324 LDFLAGS="$ax_path_bdb_path_get_version_save_LDFLAGS"
327 dnl # Finally, execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND.
328 if test "$ax_path_bdb_path_get_version_ok" = "yes" ; then
329 AC_MSG_RESULT([$ax_path_bdb_path_get_version_VERSION])
330 m4_ifvaln([$2],[$2])dnl
333 m4_ifvaln([$3],[$3])dnl
335 ]) dnl AX_PATH_BDB_PATH_GET_VERSION
337 #############################################################################
338 dnl Checks if version of library and header match specified version.
339 dnl Only meant to be used by AX_PATH_BDB_ENV_GET_VERSION macro.
341 dnl Requires AX_COMPARE_VERSION macro.
343 dnl Result: sets ax_path_bdb_env_confirm_lib_ok to yes or no.
345 dnl AX_PATH_BDB_ENV_CONFIRM_LIB(VERSION, [LIBNAME])
346 AC_DEFUN([AX_PATH_BDB_ENV_CONFIRM_LIB], [
347 dnl # Used to indicate success or failure of this function.
348 ax_path_bdb_env_confirm_lib_ok=no
350 dnl # save and modify environment to link with library LIBNAME
351 ax_path_bdb_env_confirm_lib_save_LIBS="$LIBS"
354 # Compile and run a program that compares the version defined in
355 # the header file with a version defined in the library function
361 int main(int argc,char **argv)
363 int major,minor,patch;
365 db_version(&major,&minor,&patch);
367 printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH);
368 if (DB_VERSION_MAJOR == major && DB_VERSION_MINOR == minor &&
369 DB_VERSION_PATCH == patch)
376 # Program compiled and ran, so get version by giving an argument,
377 # which will tell the program to print the output.
378 ax_path_bdb_env_confirm_lib_VERSION=`./conftest$ac_exeext x`
380 # If the versions all match up, indicate success.
381 AX_COMPARE_VERSION([$ax_path_bdb_env_confirm_lib_VERSION],[eq],[$1],[
382 ax_path_bdb_env_confirm_lib_ok=yes
386 dnl # restore environment
387 LIBS="$ax_path_bdb_env_confirm_lib_save_LIBS"
389 ]) dnl AX_PATH_BDB_ENV_CONFIRM_LIB
391 #############################################################################
392 dnl Finds the version and library name for Berkeley DB in the
393 dnl current environment. Tries many different names for library.
395 dnl Requires AX_PATH_BDB_ENV_CONFIRM_LIB macro.
397 dnl Result: set ax_path_bdb_env_get_version_ok to yes or no,
398 dnl set ax_path_bdb_env_get_version_VERSION to the version found,
399 dnl and ax_path_bdb_env_get_version_LIBNAME to the library name.
401 dnl AX_PATH_BDB_ENV_GET_VERSION([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
402 AC_DEFUN([AX_PATH_BDB_ENV_GET_VERSION], [
403 dnl # Used to indicate success or failure of this function.
404 ax_path_bdb_env_get_version_ok=no
406 ax_path_bdb_env_get_version_VERSION=''
407 ax_path_bdb_env_get_version_LIBS=''
409 AS_VAR_PUSHDEF([HEADER_VERSION],[ax_path_bdb_env_get_version_HEADER_VERSION])dnl
410 AS_VAR_PUSHDEF([TEST_LIBNAME],[ax_path_bdb_env_get_version_TEST_LIBNAME])dnl
412 # Indicate status of checking for Berkeley DB library.
413 AC_MSG_CHECKING([for db.h])
415 # Compile and run a program that determines the Berkeley DB version
416 # in the header file db.h.
422 int main(int argc,char **argv)
426 printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH);
431 # Program compiled and ran, so get version by adding an argument.
432 HEADER_VERSION=`./conftest$ac_exeext x`
433 AC_MSG_RESULT([$HEADER_VERSION])
434 ],[AC_MSG_RESULT([no])],[AC_MSG_RESULT([no])])
436 # Have header version, so try to find corresponding library.
437 # Looks for library names in the order:
438 # nothing, db, db-X.Y, dbX.Y, dbXY, db-X, dbX
439 # and stops when it finds the first one that matches the version
440 # of the header file.
441 if test "x$HEADER_VERSION" != "x" ; then
442 AC_MSG_CHECKING([for library containing Berkeley DB $HEADER_VERSION])
444 AS_VAR_PUSHDEF([MAJOR],[ax_path_bdb_env_get_version_MAJOR])dnl
445 AS_VAR_PUSHDEF([MINOR],[ax_path_bdb_env_get_version_MINOR])dnl
447 # get major and minor version numbers
448 MAJOR=`echo $HEADER_VERSION | sed 's,\..*,,'`
449 MINOR=`echo $HEADER_VERSION | sed 's,^[[0-9]]*\.,,;s,\.[[0-9]]*$,,'`
451 # see if it is already specified in LIBS
453 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
455 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
458 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
461 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
462 # try format "db-X.Y"
463 TEST_LIBNAME="-ldb-${MAJOR}.$MINOR"
464 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
467 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
469 TEST_LIBNAME="-ldb${MAJOR}.$MINOR"
470 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
473 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
475 TEST_LIBNAME="-ldb$MAJOR$MINOR"
476 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
479 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
481 TEST_LIBNAME="-ldb-$MAJOR"
482 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
485 if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then
487 TEST_LIBNAME="-ldb$MAJOR"
488 AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME])
491 dnl # Found a valid library.
492 if test "$ax_path_bdb_env_confirm_lib_ok" = "yes" ; then
493 if test "x$TEST_LIBNAME" = "x" ; then
494 AC_MSG_RESULT([none required])
496 AC_MSG_RESULT([$TEST_LIBNAME])
498 ax_path_bdb_env_get_version_VERSION="$HEADER_VERSION"
499 ax_path_bdb_env_get_version_LIBS="$TEST_LIBNAME"
500 ax_path_bdb_env_get_version_ok=yes
505 AS_VAR_POPDEF([MAJOR])dnl
506 AS_VAR_POPDEF([MINOR])dnl
509 AS_VAR_POPDEF([HEADER_VERSION])dnl
510 AS_VAR_POPDEF([TEST_LIBNAME])dnl
512 dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND.
513 if test "$ax_path_bdb_env_confirm_lib_ok" = "yes" ; then
514 m4_ifvaln([$1],[$1],[:])dnl
515 m4_ifvaln([$2],[else $2])dnl
518 ]) dnl BDB_ENV_GET_VERSION