Annotation of freem/m4/m4_ax_path_bdb.m4, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>