| 1 | dnl @synopsis AX_PATH_BDB([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|---|
| 2 | dnl |
|---|
| 3 | dnl This macro finds the latest version of Berkeley DB on the system, |
|---|
| 4 | dnl and ensures that the header file and library versions match. If |
|---|
| 5 | dnl MINIMUM-VERSION is specified, it will ensure that the library found |
|---|
| 6 | dnl is at least that version. |
|---|
| 7 | dnl |
|---|
| 8 | dnl It determines the name of the library as well as the path to the |
|---|
| 9 | dnl header file and library. It will check both the default environment |
|---|
| 10 | dnl as well as the default Berkeley DB install location. When found, it |
|---|
| 11 | dnl sets BDB_LIBS, BDB_CPPFLAGS, and BDB_LDFLAGS to the necessary |
|---|
| 12 | dnl values to add to LIBS, CPPFLAGS, and LDFLAGS, as well as setting |
|---|
| 13 | dnl BDB_VERSION to the version found. HAVE_DB_H is defined also. |
|---|
| 14 | dnl |
|---|
| 15 | dnl The options --with-bdb-headers=DIR and --with-bdb-lib=DIR can be |
|---|
| 16 | dnl used to specify a specific Berkeley DB installation to use. |
|---|
| 17 | dnl |
|---|
| 18 | dnl An example of its use is: |
|---|
| 19 | dnl |
|---|
| 20 | dnl AX_PATH_BDB([3],[ |
|---|
| 21 | dnl LIBS="$BDB_LIBS $LIBS" |
|---|
| 22 | dnl LDFLAGS="$BDB_LDFLAGS $LDFLAGS" |
|---|
| 23 | dnl CPPFLAGS="$CPPFLAGS $BDB_CPPFLAGS" |
|---|
| 24 | dnl ]) |
|---|
| 25 | dnl |
|---|
| 26 | dnl which will locate the latest version of Berkeley DB on the system, |
|---|
| 27 | dnl and ensure that it is version 3.0 or higher. |
|---|
| 28 | dnl |
|---|
| 29 | dnl Details: This macro does not use either AC_CHECK_HEADERS or |
|---|
| 30 | dnl AC_CHECK_LIB because, first, the functions inside the library are |
|---|
| 31 | dnl sometimes renamed to contain a version code that is only available |
|---|
| 32 | dnl from the db.h on the system, and second, because it is common to |
|---|
| 33 | dnl have multiple db.h and libdb files on a system it is important to |
|---|
| 34 | dnl make sure the ones being used correspond to the same version. |
|---|
| 35 | dnl Additionally, there are many different possible names for libdb |
|---|
| 36 | dnl when installed by an OS distribution, and these need to be checked |
|---|
| 37 | dnl if db.h does not correspond to libdb. |
|---|
| 38 | dnl |
|---|
| 39 | dnl When cross compiling, only header versions are verified since it |
|---|
| 40 | dnl would be difficult to check the library version. Additionally the |
|---|
| 41 | dnl default Berkeley DB installation locations /usr/local/BerkeleyDB* |
|---|
| 42 | dnl are not searched for higher versions of the library. |
|---|
| 43 | dnl |
|---|
| 44 | dnl The format for the list of library names to search came from the |
|---|
| 45 | dnl Cyrus IMAP distribution, although they are generated dynamically |
|---|
| 46 | dnl here, and only for the version found in db.h. |
|---|
| 47 | dnl |
|---|
| 48 | dnl The macro AX_COMPARE_VERSION is required to use this macro, and |
|---|
| 49 | dnl should be available from the Autoconf Macro Archive. |
|---|
| 50 | dnl |
|---|
| 51 | dnl The author would like to acknowledge the generous and valuable |
|---|
| 52 | dnl feedback from Guido Draheim, without which this macro would be far |
|---|
| 53 | dnl less robust, and have poor and inconsistent cross compilation |
|---|
| 54 | dnl support. |
|---|
| 55 | dnl |
|---|
| 56 | dnl Changes: |
|---|
| 57 | dnl |
|---|
| 58 | dnl 1/5/05 applied patch from Rafa Rzepecki to eliminate compiler |
|---|
| 59 | dnl warning about unused variable, argv |
|---|
| 60 | dnl 1/7/07 Add --with-bdb-headers and --with-bdb-lib options |
|---|
| 61 | dnl (James O'Gorman, james@netinertia.co.uk) |
|---|
| 62 | dnl |
|---|
| 63 | dnl @category InstalledPackages |
|---|
| 64 | dnl @author Tim Toolan <toolan@ele.uri.edu> |
|---|
| 65 | dnl @version 2005-01-17 |
|---|
| 66 | dnl @license GPLWithACException |
|---|
| 67 | |
|---|
| 68 | dnl ######################################################################### |
|---|
| 69 | AC_DEFUN([AX_PATH_BDB], [ |
|---|
| 70 | dnl # Used to indicate success or failure of this function. |
|---|
| 71 | ax_path_bdb_ok=no |
|---|
| 72 | |
|---|
| 73 | # Add --with-bdb-headers and --with-bdb-lib options |
|---|
| 74 | AC_ARG_WITH([bdb-headers], |
|---|
| 75 | [AC_HELP_STRING([--with-bdb-headers=DIR], |
|---|
| 76 | [Berkeley DB include files location])]) |
|---|
| 77 | |
|---|
| 78 | AC_ARG_WITH([bdb-lib], |
|---|
| 79 | [AC_HELP_STRING([--with-bdb-lib=DIR], |
|---|
| 80 | [Berkeley DB library location])]) |
|---|
| 81 | |
|---|
| 82 | # Check if --with-bdb-dir was specified. |
|---|
| 83 | if test "x$with_bdb_headers" = "x" -a "x$with_bdb_lib" = "x"; then |
|---|
| 84 | # No option specified, so just search the system. |
|---|
| 85 | AX_PATH_BDB_NO_OPTIONS([$1], [HIGHEST], [ |
|---|
| 86 | ax_path_bdb_ok=yes |
|---|
| 87 | ]) |
|---|
| 88 | else |
|---|
| 89 | ax_path_bdb_INC="$with_bdb_headers" |
|---|
| 90 | ax_path_bdb_LIB="$with_bdb_lib" |
|---|
| 91 | |
|---|
| 92 | dnl # Save previous environment, and modify with new stuff. |
|---|
| 93 | ax_path_bdb_save_CPPFLAGS="$CPPFLAGS" |
|---|
| 94 | CPPFLAGS="-I$ax_path_bdb_INC $CPPFLAGS" |
|---|
| 95 | |
|---|
| 96 | ax_path_bdb_save_LDFLAGS=$LDFLAGS |
|---|
| 97 | LDFLAGS="-L$ax_path_bdb_LIB $LDFLAGS" |
|---|
| 98 | |
|---|
| 99 | # Check for specific header file db.h |
|---|
| 100 | AC_MSG_CHECKING([db.h presence in $ax_path_bdb_INC]) |
|---|
| 101 | if test -f "$ax_path_bdb_INC/db.h" ; then |
|---|
| 102 | AC_MSG_RESULT([yes]) |
|---|
| 103 | # Check for library |
|---|
| 104 | AX_PATH_BDB_NO_OPTIONS([$1], [ENVONLY], [ |
|---|
| 105 | ax_path_bdb_ok=yes |
|---|
| 106 | BDB_CPPFLAGS="-I$ax_path_bdb_INC" |
|---|
| 107 | BDB_LDFLAGS="-L$ax_path_bdb_LIB" |
|---|
| 108 | ]) |
|---|
| 109 | else |
|---|
| 110 | AC_MSG_RESULT([no]) |
|---|
| 111 | AC_MSG_NOTICE([no usable Berkeley DB not found]) |
|---|
| 112 | fi |
|---|
| 113 | |
|---|
| 114 | dnl # Restore the environment. |
|---|
| 115 | CPPFLAGS="$ax_path_bdb_save_CPPFLAGS" |
|---|
| 116 | LDFLAGS="$ax_path_bdb_save_LDFLAGS" |
|---|
| 117 | |
|---|
| 118 | fi |
|---|
| 119 | |
|---|
| 120 | dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND. |
|---|
| 121 | if test "$ax_path_bdb_ok" = "yes" ; then |
|---|
| 122 | m4_ifvaln([$2],[$2],[:])dnl |
|---|
| 123 | m4_ifvaln([$3],[else $3])dnl |
|---|
| 124 | fi |
|---|
| 125 | |
|---|
| 126 | ]) dnl AX_PATH_BDB |
|---|
| 127 | |
|---|
| 128 | dnl ######################################################################### |
|---|
| 129 | dnl Check for berkeley DB of at least MINIMUM-VERSION on system. |
|---|
| 130 | dnl |
|---|
| 131 | dnl The OPTION argument determines how the checks occur, and can be one of: |
|---|
| 132 | dnl |
|---|
| 133 | dnl HIGHEST - Check both the environment and the default installation |
|---|
| 134 | dnl directories for Berkeley DB and choose the version that |
|---|
| 135 | dnl is highest. (default) |
|---|
| 136 | dnl ENVFIRST - Check the environment first, and if no satisfactory |
|---|
| 137 | dnl library is found there check the default installation |
|---|
| 138 | dnl directories for Berkeley DB which is /usr/local/BerkeleyDB* |
|---|
| 139 | dnl ENVONLY - Check the current environment only. |
|---|
| 140 | dnl |
|---|
| 141 | dnl Requires AX_PATH_BDB_PATH_GET_VERSION, AX_PATH_BDB_PATH_FIND_HIGHEST, |
|---|
| 142 | dnl AX_PATH_BDB_ENV_CONFIRM_LIB, AX_PATH_BDB_ENV_GET_VERSION, and |
|---|
| 143 | dnl AX_COMPARE_VERSION macros. |
|---|
| 144 | dnl |
|---|
| 145 | dnl Result: sets ax_path_bdb_no_options_ok to yes or no |
|---|
| 146 | dnl sets BDB_LIBS, BDB_CPPFLAGS, BDB_LDFLAGS, BDB_VERSION |
|---|
| 147 | dnl |
|---|
| 148 | dnl AX_PATH_BDB_NO_OPTIONS([MINIMUM-VERSION], [OPTION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|---|
| 149 | AC_DEFUN([AX_PATH_BDB_NO_OPTIONS], [ |
|---|
| 150 | dnl # Used to indicate success or failure of this function. |
|---|
| 151 | ax_path_bdb_no_options_ok=no |
|---|
| 152 | |
|---|
| 153 | # Values to add to environment to use Berkeley DB. |
|---|
| 154 | BDB_VERSION='' |
|---|
| 155 | BDB_LIBS='' |
|---|
| 156 | BDB_CPPFLAGS='' |
|---|
| 157 | BDB_LDFLAGS='' |
|---|
| 158 | |
|---|
| 159 | # Check cross compilation here. |
|---|
| 160 | if test "x$cross_compiling" = "xyes" ; then |
|---|
| 161 | # If cross compiling, can't use AC_RUN_IFELSE so do these tests. |
|---|
| 162 | # The AC_PREPROC_IFELSE confirms that db.h is preprocessable, |
|---|
| 163 | # and extracts the version number from it. |
|---|
| 164 | AC_MSG_CHECKING([for db.h]) |
|---|
| 165 | |
|---|
| 166 | AS_VAR_PUSHDEF([HEADER_VERSION],[ax_path_bdb_no_options_HEADER_VERSION])dnl |
|---|
| 167 | HEADER_VERSION='' |
|---|
| 168 | AC_PREPROC_IFELSE([ |
|---|
| 169 | AC_LANG_SOURCE([[ |
|---|
| 170 | #include <db.h> |
|---|
| 171 | #ifdef DB_VERSION_MAJOR |
|---|
| 172 | AX_PATH_BDB_STUFF DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH |
|---|
| 173 | #else |
|---|
| 174 | AX_PATH_BDB_STUFF 1,0,0 |
|---|
| 175 | #endif |
|---|
| 176 | ]]) |
|---|
| 177 | ],[ |
|---|
| 178 | # Extract version from preprocessor output. |
|---|
| 179 | HEADER_VERSION=`eval "$ac_cpp conftest.$ac_ext" 2> /dev/null \ |
|---|
| 180 | | grep AX_PATH_BDB_STUFF | sed 's/[[^0-9,]]//g;s/,/./g;1q'` |
|---|
| 181 | ],[]) |
|---|
| 182 | |
|---|
| 183 | if test "x$HEADER_VERSION" = "x" ; then |
|---|
| 184 | AC_MSG_RESULT([no]) |
|---|
| 185 | else |
|---|
| 186 | AC_MSG_RESULT([$HEADER_VERSION]) |
|---|
| 187 | |
|---|
| 188 | # Check that version is high enough. |
|---|
| 189 | AX_COMPARE_VERSION([$HEADER_VERSION],[ge],[$1],[ |
|---|
| 190 | # get major and minor version numbers |
|---|
| 191 | AS_VAR_PUSHDEF([MAJ],[ax_path_bdb_no_options_MAJOR])dnl |
|---|
| 192 | MAJ=`echo $HEADER_VERSION | sed 's,\..*,,'` |
|---|
| 193 | AS_VAR_PUSHDEF([MIN],[ax_path_bdb_no_options_MINOR])dnl |
|---|
| 194 | MIN=`echo $HEADER_VERSION | sed 's,^[[0-9]]*\.,,;s,\.[[0-9]]*$,,'` |
|---|
| 195 | |
|---|
| 196 | dnl # Save LIBS. |
|---|
| 197 | ax_path_bdb_no_options_save_LIBS="$LIBS" |
|---|
| 198 | |
|---|
| 199 | # Check that we can link with the library. |
|---|
| 200 | AC_SEARCH_LIBS([db_version], |
|---|
| 201 | [db db-$MAJ.$MIN db$MAJ.$MIN db$MAJ$MIN db-$MAJ db$MAJ],[ |
|---|
| 202 | # Sucessfully found library. |
|---|
| 203 | ax_path_bdb_no_options_ok=yes |
|---|
| 204 | BDB_VERSION=$HEADER_VERSION |
|---|
| 205 | |
|---|
| 206 | # Extract library from LIBS |
|---|
| 207 | ax_path_bdb_no_options_LEN=` \ |
|---|
| 208 | echo "x$ax_path_bdb_no_options_save_LIBS" \ |
|---|
| 209 | | awk '{print(length)}'` |
|---|
| 210 | BDB_LIBS=`echo "x$LIBS " \ |
|---|
| 211 | | sed "s/.\{$ax_path_bdb_no_options_LEN\}\$//;s/^x//;s/ //g"` |
|---|
| 212 | ],[]) |
|---|
| 213 | |
|---|
| 214 | dnl # Restore LIBS |
|---|
| 215 | LIBS="$ax_path_bdb_no_options_save_LIBS" |
|---|
| 216 | |
|---|
| 217 | AS_VAR_POPDEF([MAJ])dnl |
|---|
| 218 | AS_VAR_POPDEF([MIN])dnl |
|---|
| 219 | ]) |
|---|
| 220 | fi |
|---|
| 221 | |
|---|
| 222 | AS_VAR_POPDEF([HEADER_VERSION])dnl |
|---|
| 223 | else |
|---|
| 224 | # Not cross compiling. |
|---|
| 225 | # Check version of Berkeley DB in the current environment. |
|---|
| 226 | AX_PATH_BDB_ENV_GET_VERSION([ |
|---|
| 227 | AX_COMPARE_VERSION([$ax_path_bdb_env_get_version_VERSION],[ge],[$1],[ |
|---|
| 228 | # Found acceptable version in current environment. |
|---|
| 229 | ax_path_bdb_no_options_ok=yes |
|---|
| 230 | BDB_VERSION="$ax_path_bdb_env_get_version_VERSION" |
|---|
| 231 | BDB_LIBS="$ax_path_bdb_env_get_version_LIBS" |
|---|
| 232 | ]) |
|---|
| 233 | ]) |
|---|
| 234 | |
|---|
| 235 | # Determine if we need to search /usr/local/BerkeleyDB* |
|---|
| 236 | ax_path_bdb_no_options_DONE=no |
|---|
| 237 | if test "x$2" = "xENVONLY" ; then |
|---|
| 238 | ax_path_bdb_no_options_DONE=yes |
|---|
| 239 | elif test "x$2" = "xENVFIRST" ; then |
|---|
| 240 | ax_path_bdb_no_options_DONE=$ax_path_bdb_no_options_ok |
|---|
| 241 | fi |
|---|
| 242 | |
|---|
| 243 | if test "$ax_path_bdb_no_options_DONE" = "no" ; then |
|---|
| 244 | ax_compare_version=false |
|---|
| 245 | # Check for highest in /usr/local/BerkeleyDB* |
|---|
| 246 | AX_PATH_BDB_PATH_FIND_HIGHEST([ |
|---|
| 247 | if test "$ax_path_bdb_no_options_ok" = "yes" ; then |
|---|
| 248 | # If we already have an acceptable version use this if higher. |
|---|
| 249 | AX_COMPARE_VERSION( |
|---|
| 250 | [$ax_path_bdb_path_find_highest_VERSION],[gt],[$BDB_VERSION]) |
|---|
| 251 | else |
|---|
| 252 | # Since we didn't have an acceptable version check if this one is. |
|---|
| 253 | AX_COMPARE_VERSION( |
|---|
| 254 | [$ax_path_bdb_path_find_highest_VERSION],[ge],[$1]) |
|---|
| 255 | fi |
|---|
| 256 | ]) |
|---|
| 257 | |
|---|
| 258 | dnl # If result from _AX_COMPARE_VERSION is true we want this version. |
|---|
| 259 | if test "$ax_compare_version" = "true" ; then |
|---|
| 260 | ax_path_bdb_no_options_ok=yes |
|---|
| 261 | BDB_LIBS="-ldb" |
|---|
| 262 | if test "x$ax_path_bdb_path_find_highest_DIR" != x ; then |
|---|
| 263 | BDB_CPPFLAGS="-I$ax_path_bdb_path_find_highest_DIR/include" |
|---|
| 264 | BDB_LDFLAGS="-L$ax_path_bdb_path_find_highest_DIR/lib" |
|---|
| 265 | fi |
|---|
| 266 | BDB_VERSION="$ax_path_bdb_path_find_highest_VERSION" |
|---|
| 267 | fi |
|---|
| 268 | fi |
|---|
| 269 | fi |
|---|
| 270 | |
|---|
| 271 | dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND. |
|---|
| 272 | if test "$ax_path_bdb_no_options_ok" = "yes" ; then |
|---|
| 273 | AC_MSG_NOTICE([using Berkeley DB version $BDB_VERSION]) |
|---|
| 274 | AC_DEFINE([HAVE_DB_H],[1], |
|---|
| 275 | [Define to 1 if you have the <db.h> header file.]) |
|---|
| 276 | m4_ifvaln([$3],[$3])dnl |
|---|
| 277 | else |
|---|
| 278 | AC_MSG_NOTICE([no Berkeley DB version $1 or higher found]) |
|---|
| 279 | m4_ifvaln([$4],[$4])dnl |
|---|
| 280 | fi |
|---|
| 281 | ]) dnl AX_PATH_BDB_NO_OPTIONS |
|---|
| 282 | |
|---|
| 283 | dnl ######################################################################### |
|---|
| 284 | dnl Check the default installation directory for Berkeley DB which is |
|---|
| 285 | dnl of the form /usr/local/BerkeleyDB* for the highest version. |
|---|
| 286 | dnl |
|---|
| 287 | dnl Result: sets ax_path_bdb_path_find_highest_ok to yes or no, |
|---|
| 288 | dnl sets ax_path_bdb_path_find_highest_VERSION to version, |
|---|
| 289 | dnl sets ax_path_bdb_path_find_highest_DIR to directory. |
|---|
| 290 | dnl |
|---|
| 291 | dnl AX_PATH_BDB_PATH_FIND_HIGHEST([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|---|
| 292 | AC_DEFUN([AX_PATH_BDB_PATH_FIND_HIGHEST], [ |
|---|
| 293 | dnl # Used to indicate success or failure of this function. |
|---|
| 294 | ax_path_bdb_path_find_highest_ok=no |
|---|
| 295 | |
|---|
| 296 | AS_VAR_PUSHDEF([VERSION],[ax_path_bdb_path_find_highest_VERSION])dnl |
|---|
| 297 | VERSION='' |
|---|
| 298 | |
|---|
| 299 | ax_path_bdb_path_find_highest_DIR='' |
|---|
| 300 | |
|---|
| 301 | # find highest verison in default install directory for Berkeley DB |
|---|
| 302 | AS_VAR_PUSHDEF([CURDIR],[ax_path_bdb_path_find_highest_CURDIR])dnl |
|---|
| 303 | AS_VAR_PUSHDEF([CUR_VERSION],[ax_path_bdb_path_get_version_VERSION])dnl |
|---|
| 304 | |
|---|
| 305 | for CURDIR in `ls -d /usr/local/BerkeleyDB* 2> /dev/null` |
|---|
| 306 | do |
|---|
| 307 | AX_PATH_BDB_PATH_GET_VERSION([$CURDIR],[ |
|---|
| 308 | AX_COMPARE_VERSION([$CUR_VERSION],[gt],[$VERSION],[ |
|---|
| 309 | ax_path_bdb_path_find_highest_ok=yes |
|---|
| 310 | ax_path_bdb_path_find_highest_DIR="$CURDIR" |
|---|
| 311 | VERSION="$CUR_VERSION" |
|---|
| 312 | ]) |
|---|
| 313 | ]) |
|---|
| 314 | done |
|---|
| 315 | |
|---|
| 316 | AS_VAR_POPDEF([VERSION])dnl |
|---|
| 317 | AS_VAR_POPDEF([CUR_VERSION])dnl |
|---|
| 318 | AS_VAR_POPDEF([CURDIR])dnl |
|---|
| 319 | |
|---|
| 320 | dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND. |
|---|
| 321 | if test "$ax_path_bdb_path_find_highest_ok" = "yes" ; then |
|---|
| 322 | m4_ifvaln([$1],[$1],[:])dnl |
|---|
| 323 | m4_ifvaln([$2],[else $2])dnl |
|---|
| 324 | fi |
|---|
| 325 | |
|---|
| 326 | ]) dnl AX_PATH_BDB_PATH_FIND_HIGHEST |
|---|
| 327 | |
|---|
| 328 | dnl ######################################################################### |
|---|
| 329 | dnl Checks for Berkeley DB in specified directory's lib and include |
|---|
| 330 | dnl subdirectories. |
|---|
| 331 | dnl |
|---|
| 332 | dnl Result: sets ax_path_bdb_path_get_version_ok to yes or no, |
|---|
| 333 | dnl sets ax_path_bdb_path_get_version_VERSION to version. |
|---|
| 334 | dnl |
|---|
| 335 | dnl AX_PATH_BDB_PATH_GET_VERSION(BDB-DIR, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|---|
| 336 | AC_DEFUN([AX_PATH_BDB_PATH_GET_VERSION], [ |
|---|
| 337 | dnl # Used to indicate success or failure of this function. |
|---|
| 338 | ax_path_bdb_path_get_version_ok=no |
|---|
| 339 | |
|---|
| 340 | # Indicate status of checking for Berkeley DB header. |
|---|
| 341 | AC_MSG_CHECKING([in $1/include for db.h]) |
|---|
| 342 | ax_path_bdb_path_get_version_got_header=no |
|---|
| 343 | test -f "$1/include/db.h" && ax_path_bdb_path_get_version_got_header=yes |
|---|
| 344 | AC_MSG_RESULT([$ax_path_bdb_path_get_version_got_header]) |
|---|
| 345 | |
|---|
| 346 | # Indicate status of checking for Berkeley DB library. |
|---|
| 347 | AC_MSG_CHECKING([in $1/lib for library -ldb]) |
|---|
| 348 | |
|---|
| 349 | ax_path_bdb_path_get_version_VERSION='' |
|---|
| 350 | |
|---|
| 351 | if test -d "$1/include" && test -d "$1/lib" && |
|---|
| 352 | test "$ax_path_bdb_path_get_version_got_header" = "yes" ; then |
|---|
| 353 | dnl # save and modify environment |
|---|
| 354 | ax_path_bdb_path_get_version_save_CPPFLAGS="$CPPFLAGS" |
|---|
| 355 | CPPFLAGS="-I$1/include $CPPFLAGS" |
|---|
| 356 | |
|---|
| 357 | ax_path_bdb_path_get_version_save_LIBS="$LIBS" |
|---|
| 358 | LIBS="$LIBS -ldb" |
|---|
| 359 | |
|---|
| 360 | ax_path_bdb_path_get_version_save_LDFLAGS="$LDFLAGS" |
|---|
| 361 | LDFLAGS="-L$1/lib $LDFLAGS" |
|---|
| 362 | |
|---|
| 363 | # Compile and run a program that compares the version defined in |
|---|
| 364 | # the header file with a version defined in the library function |
|---|
| 365 | # db_version. |
|---|
| 366 | AC_RUN_IFELSE([ |
|---|
| 367 | AC_LANG_SOURCE([[ |
|---|
| 368 | #include <stdio.h> |
|---|
| 369 | #include <db.h> |
|---|
| 370 | int main(int argc,char **argv) |
|---|
| 371 | { |
|---|
| 372 | (void) argv; |
|---|
| 373 | #ifdef DB_VERSION_MAJOR |
|---|
| 374 | int major,minor,patch; |
|---|
| 375 | db_version(&major,&minor,&patch); |
|---|
| 376 | if (argc > 1) |
|---|
| 377 | printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH); |
|---|
| 378 | if (DB_VERSION_MAJOR == major && DB_VERSION_MINOR == minor && |
|---|
| 379 | DB_VERSION_PATCH == patch) |
|---|
| 380 | return 0; |
|---|
| 381 | else |
|---|
| 382 | return 1; |
|---|
| 383 | #else |
|---|
| 384 | DB *dbp = dbopen(0, 0, 0, DB_HASH, 0); |
|---|
| 385 | if(dbp) dbp->close(dbp); |
|---|
| 386 | if (argc > 1) |
|---|
| 387 | printf("1.0.0\n"); |
|---|
| 388 | if (dbp) |
|---|
| 389 | return 0; |
|---|
| 390 | else |
|---|
| 391 | return 1; |
|---|
| 392 | #endif |
|---|
| 393 | } |
|---|
| 394 | ]]) |
|---|
| 395 | ],[ |
|---|
| 396 | # Program compiled and ran, so get version by adding argument. |
|---|
| 397 | ax_path_bdb_path_get_version_VERSION=`./conftest$ac_exeext x` |
|---|
| 398 | ax_path_bdb_path_get_version_ok=yes |
|---|
| 399 | ],[],[]) |
|---|
| 400 | |
|---|
| 401 | dnl # restore environment |
|---|
| 402 | CPPFLAGS="$ax_path_bdb_path_get_version_save_CPPFLAGS" |
|---|
| 403 | LIBS="$ax_path_bdb_path_get_version_save_LIBS" |
|---|
| 404 | LDFLAGS="$ax_path_bdb_path_get_version_save_LDFLAGS" |
|---|
| 405 | fi |
|---|
| 406 | |
|---|
| 407 | dnl # Finally, execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND. |
|---|
| 408 | if test "$ax_path_bdb_path_get_version_ok" = "yes" ; then |
|---|
| 409 | AC_MSG_RESULT([$ax_path_bdb_path_get_version_VERSION]) |
|---|
| 410 | m4_ifvaln([$2],[$2])dnl |
|---|
| 411 | else |
|---|
| 412 | AC_MSG_RESULT([no]) |
|---|
| 413 | m4_ifvaln([$3],[$3])dnl |
|---|
| 414 | fi |
|---|
| 415 | ]) dnl AX_PATH_BDB_PATH_GET_VERSION |
|---|
| 416 | |
|---|
| 417 | ############################################################################# |
|---|
| 418 | dnl Checks if version of library and header match specified version. |
|---|
| 419 | dnl Only meant to be used by AX_PATH_BDB_ENV_GET_VERSION macro. |
|---|
| 420 | dnl |
|---|
| 421 | dnl Requires AX_COMPARE_VERSION macro. |
|---|
| 422 | dnl |
|---|
| 423 | dnl Result: sets ax_path_bdb_env_confirm_lib_ok to yes or no. |
|---|
| 424 | dnl |
|---|
| 425 | dnl AX_PATH_BDB_ENV_CONFIRM_LIB(VERSION, [LIBNAME]) |
|---|
| 426 | AC_DEFUN([AX_PATH_BDB_ENV_CONFIRM_LIB], [ |
|---|
| 427 | dnl # Used to indicate success or failure of this function. |
|---|
| 428 | ax_path_bdb_env_confirm_lib_ok=no |
|---|
| 429 | |
|---|
| 430 | dnl # save and modify environment to link with library LIBNAME |
|---|
| 431 | ax_path_bdb_env_confirm_lib_save_LIBS="$LIBS" |
|---|
| 432 | LIBS="$LIBS $2" |
|---|
| 433 | |
|---|
| 434 | # Compile and run a program that compares the version defined in |
|---|
| 435 | # the header file with a version defined in the library function |
|---|
| 436 | # db_version. |
|---|
| 437 | AC_RUN_IFELSE([ |
|---|
| 438 | AC_LANG_SOURCE([[ |
|---|
| 439 | #include <stdio.h> |
|---|
| 440 | #include <db.h> |
|---|
| 441 | int main(int argc,char **argv) |
|---|
| 442 | { |
|---|
| 443 | (void) argv; |
|---|
| 444 | #ifdef DB_VERSION_MAJOR |
|---|
| 445 | int major,minor,patch; |
|---|
| 446 | db_version(&major,&minor,&patch); |
|---|
| 447 | if (argc > 1) |
|---|
| 448 | printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH); |
|---|
| 449 | if (DB_VERSION_MAJOR == major && DB_VERSION_MINOR == minor && |
|---|
| 450 | DB_VERSION_PATCH == patch) |
|---|
| 451 | return 0; |
|---|
| 452 | else |
|---|
| 453 | return 1; |
|---|
| 454 | #else |
|---|
| 455 | DB *dbp = dbopen(0, 0, 0, DB_HASH, 0); |
|---|
| 456 | if(dbp) dbp->close(dbp); |
|---|
| 457 | if (argc > 1) |
|---|
| 458 | printf("1.0.0\n"); |
|---|
| 459 | if (dbp) |
|---|
| 460 | return 0; |
|---|
| 461 | else |
|---|
| 462 | return 1; |
|---|
| 463 | #endif |
|---|
| 464 | } |
|---|
| 465 | ]]) |
|---|
| 466 | ],[ |
|---|
| 467 | # Program compiled and ran, so get version by giving an argument, |
|---|
| 468 | # which will tell the program to print the output. |
|---|
| 469 | ax_path_bdb_env_confirm_lib_VERSION=`./conftest$ac_exeext x` |
|---|
| 470 | |
|---|
| 471 | # If the versions all match up, indicate success. |
|---|
| 472 | AX_COMPARE_VERSION([$ax_path_bdb_env_confirm_lib_VERSION],[eq],[$1],[ |
|---|
| 473 | ax_path_bdb_env_confirm_lib_ok=yes |
|---|
| 474 | ]) |
|---|
| 475 | ],[],[]) |
|---|
| 476 | |
|---|
| 477 | dnl # restore environment |
|---|
| 478 | LIBS="$ax_path_bdb_env_confirm_lib_save_LIBS" |
|---|
| 479 | |
|---|
| 480 | ]) dnl AX_PATH_BDB_ENV_CONFIRM_LIB |
|---|
| 481 | |
|---|
| 482 | ############################################################################# |
|---|
| 483 | dnl Finds the version and library name for Berkeley DB in the |
|---|
| 484 | dnl current environment. Tries many different names for library. |
|---|
| 485 | dnl |
|---|
| 486 | dnl Requires AX_PATH_BDB_ENV_CONFIRM_LIB macro. |
|---|
| 487 | dnl |
|---|
| 488 | dnl Result: set ax_path_bdb_env_get_version_ok to yes or no, |
|---|
| 489 | dnl set ax_path_bdb_env_get_version_VERSION to the version found, |
|---|
| 490 | dnl and ax_path_bdb_env_get_version_LIBNAME to the library name. |
|---|
| 491 | dnl |
|---|
| 492 | dnl AX_PATH_BDB_ENV_GET_VERSION([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
|---|
| 493 | AC_DEFUN([AX_PATH_BDB_ENV_GET_VERSION], [ |
|---|
| 494 | dnl # Used to indicate success or failure of this function. |
|---|
| 495 | ax_path_bdb_env_get_version_ok=no |
|---|
| 496 | |
|---|
| 497 | ax_path_bdb_env_get_version_VERSION='' |
|---|
| 498 | ax_path_bdb_env_get_version_LIBS='' |
|---|
| 499 | |
|---|
| 500 | AS_VAR_PUSHDEF([HEADER_VERSION],[ax_path_bdb_env_get_version_HEADER_VERSION])dnl |
|---|
| 501 | AS_VAR_PUSHDEF([TEST_LIBNAME],[ax_path_bdb_env_get_version_TEST_LIBNAME])dnl |
|---|
| 502 | |
|---|
| 503 | # Indicate status of checking for Berkeley DB library. |
|---|
| 504 | AC_MSG_CHECKING([for db.h]) |
|---|
| 505 | |
|---|
| 506 | # Compile and run a program that determines the Berkeley DB version |
|---|
| 507 | # in the header file db.h. |
|---|
| 508 | HEADER_VERSION='' |
|---|
| 509 | AC_RUN_IFELSE([ |
|---|
| 510 | AC_LANG_SOURCE([[ |
|---|
| 511 | #include <stdio.h> |
|---|
| 512 | #include <db.h> |
|---|
| 513 | int main(int argc,char **argv) |
|---|
| 514 | { |
|---|
| 515 | (void) argv; |
|---|
| 516 | if (argc > 1) |
|---|
| 517 | #ifdef DB_VERSION_MAJOR |
|---|
| 518 | printf("%d.%d.%d\n",DB_VERSION_MAJOR,DB_VERSION_MINOR,DB_VERSION_PATCH); |
|---|
| 519 | #else |
|---|
| 520 | printf("1.0.0\n"); |
|---|
| 521 | #endif |
|---|
| 522 | return 0; |
|---|
| 523 | } |
|---|
| 524 | ]]) |
|---|
| 525 | ],[ |
|---|
| 526 | # Program compiled and ran, so get version by adding an argument. |
|---|
| 527 | HEADER_VERSION=`./conftest$ac_exeext x` |
|---|
| 528 | AC_MSG_RESULT([$HEADER_VERSION]) |
|---|
| 529 | ],[AC_MSG_RESULT([no])],[AC_MSG_RESULT([no])]) |
|---|
| 530 | |
|---|
| 531 | # Have header version, so try to find corresponding library. |
|---|
| 532 | # Looks for library names in the order: |
|---|
| 533 | # nothing, db, db-X.Y, dbX.Y, dbXY, db-X, dbX |
|---|
| 534 | # and stops when it finds the first one that matches the version |
|---|
| 535 | # of the header file. |
|---|
| 536 | if test "x$HEADER_VERSION" != "x" ; then |
|---|
| 537 | AC_MSG_CHECKING([for library containing Berkeley DB $HEADER_VERSION]) |
|---|
| 538 | |
|---|
| 539 | AS_VAR_PUSHDEF([MAJOR],[ax_path_bdb_env_get_version_MAJOR])dnl |
|---|
| 540 | AS_VAR_PUSHDEF([MINOR],[ax_path_bdb_env_get_version_MINOR])dnl |
|---|
| 541 | |
|---|
| 542 | # get major and minor version numbers |
|---|
| 543 | MAJOR=`echo $HEADER_VERSION | sed 's,\..*,,'` |
|---|
| 544 | MINOR=`echo $HEADER_VERSION | sed 's,^[[0-9]]*\.,,;s,\.[[0-9]]*$,,'` |
|---|
| 545 | |
|---|
| 546 | # see if it is already specified in LIBS |
|---|
| 547 | TEST_LIBNAME='' |
|---|
| 548 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 549 | |
|---|
| 550 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 551 | # try format "db" |
|---|
| 552 | TEST_LIBNAME='-ldb' |
|---|
| 553 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 554 | fi |
|---|
| 555 | |
|---|
| 556 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 557 | # try format "db-X.Y" |
|---|
| 558 | TEST_LIBNAME="-ldb-${MAJOR}.$MINOR" |
|---|
| 559 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 560 | fi |
|---|
| 561 | |
|---|
| 562 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 563 | # try format "dbX.Y" |
|---|
| 564 | TEST_LIBNAME="-ldb${MAJOR}.$MINOR" |
|---|
| 565 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 566 | fi |
|---|
| 567 | |
|---|
| 568 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 569 | # try format "dbXY" |
|---|
| 570 | TEST_LIBNAME="-ldb$MAJOR$MINOR" |
|---|
| 571 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 572 | fi |
|---|
| 573 | |
|---|
| 574 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 575 | # try format "db-X" |
|---|
| 576 | TEST_LIBNAME="-ldb-$MAJOR" |
|---|
| 577 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 578 | fi |
|---|
| 579 | |
|---|
| 580 | if test "$ax_path_bdb_env_confirm_lib_ok" = "no" ; then |
|---|
| 581 | # try format "dbX" |
|---|
| 582 | TEST_LIBNAME="-ldb$MAJOR" |
|---|
| 583 | AX_PATH_BDB_ENV_CONFIRM_LIB([$HEADER_VERSION], [$TEST_LIBNAME]) |
|---|
| 584 | fi |
|---|
| 585 | |
|---|
| 586 | dnl # Found a valid library. |
|---|
| 587 | if test "$ax_path_bdb_env_confirm_lib_ok" = "yes" ; then |
|---|
| 588 | if test "x$TEST_LIBNAME" = "x" ; then |
|---|
| 589 | AC_MSG_RESULT([none required]) |
|---|
| 590 | else |
|---|
| 591 | AC_MSG_RESULT([$TEST_LIBNAME]) |
|---|
| 592 | fi |
|---|
| 593 | ax_path_bdb_env_get_version_VERSION="$HEADER_VERSION" |
|---|
| 594 | ax_path_bdb_env_get_version_LIBS="$TEST_LIBNAME" |
|---|
| 595 | ax_path_bdb_env_get_version_ok=yes |
|---|
| 596 | else |
|---|
| 597 | AC_MSG_RESULT([no]) |
|---|
| 598 | fi |
|---|
| 599 | |
|---|
| 600 | AS_VAR_POPDEF([MAJOR])dnl |
|---|
| 601 | AS_VAR_POPDEF([MINOR])dnl |
|---|
| 602 | fi |
|---|
| 603 | |
|---|
| 604 | AS_VAR_POPDEF([HEADER_VERSION])dnl |
|---|
| 605 | AS_VAR_POPDEF([TEST_LIBNAME])dnl |
|---|
| 606 | |
|---|
| 607 | dnl # Execute ACTION-IF-FOUND / ACTION-IF-NOT-FOUND. |
|---|
| 608 | if test "$ax_path_bdb_env_confirm_lib_ok" = "yes" ; then |
|---|
| 609 | m4_ifvaln([$1],[$1],[:])dnl |
|---|
| 610 | m4_ifvaln([$2],[else $2])dnl |
|---|
| 611 | fi |
|---|
| 612 | |
|---|
| 613 | ]) dnl BDB_ENV_GET_VERSION |
|---|
| 614 | |
|---|
| 615 | ############################################################################# |
|---|