1 dnl Find the compiler and linker flags for libcdb.
3 dnl Finds the compiler and linker flags for linking with the libcdb library.
4 dnl Provides the --with-libcdb, --with-libcdb-lib, and --with-libcdb-include
5 dnl configure options to specify non-standard paths to libcdb libraries.
7 dnl Provides the macros RRA_LIB_CDB and RRA_LIB_CDB_OPTIONAL and sets the
8 dnl substitution variables CDB_CPPFLAGS, CDB_LDFLAGS, and CDB_LIBS. Also
9 dnl provides RRA_LIB_CDB_SWITCH to set CPPFLAGS, LDFLAGS, and LIBS to include
10 dnl the TinyCDB libraries, saving the current values, and RRA_LIB_CDB_RESTORE
11 dnl to restore those settings to before the last RRA_LIB_CDB_SWITCH. Defines
12 dnl HAVE_CDB and sets rra_use_CDB to true if the library is found.
14 dnl Depends on the lib-helper.m4 framework.
16 dnl The canonical version of this file is maintained in the rra-c-util
17 dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
19 dnl Written by Russ Allbery <eagle@eyrie.org>
21 dnl The Board of Trustees of the Leland Stanford Junior University
23 dnl This file is free software; the authors give unlimited permission to copy
24 dnl and/or distribute it, with or without modifications, as long as this
25 dnl notice is preserved.
27 dnl SPDX-License-Identifier: FSFULLR
29 dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
30 dnl versions that include the TinyCDB flags. Used as a wrapper, with
31 dnl RRA_LIB_CDB_RESTORE, around tests.
32 AC_DEFUN([RRA_LIB_CDB_SWITCH], [RRA_LIB_HELPER_SWITCH([CDB])])
34 dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
35 dnl RRA_LIB_CDB_SWITCH was called).
36 AC_DEFUN([RRA_LIB_CDB_RESTORE], [RRA_LIB_HELPER_RESTORE([CDB])])
38 dnl Checks if the libcdb library is present. The single argument, if "true",
39 dnl says to fail if the libcdb library could not be found.
40 AC_DEFUN([_RRA_LIB_CDB_INTERNAL],
41 [RRA_LIB_HELPER_PATHS([CDB])
43 AC_CHECK_LIB([cdb], [cdb_init], [CDB_LIBS=-lcdb],
44 [AS_IF([test x"$1" = xtrue],
45 [AC_MSG_ERROR([cannot find usable TinyCDB library])])])
46 AC_CHECK_HEADERS([cdb.h])
49 dnl The main macro for packages with mandatory TinyCDB support.
50 AC_DEFUN([RRA_LIB_CDB],
51 [RRA_LIB_HELPER_VAR_INIT([CDB])
52 RRA_LIB_HELPER_WITH([tinycdb], [TinyCDB], [CDB])
53 _RRA_LIB_CDB_INTERNAL([true])
55 AC_DEFINE([HAVE_CDB], 1, [Define if libcdb is available.])])
57 dnl The main macro for packages with optional TinyCDB support.
58 AC_DEFUN([RRA_LIB_CDB_OPTIONAL],
59 [RRA_LIB_HELPER_VAR_INIT([CDB])
60 RRA_LIB_HELPER_WITH_OPTIONAL([tinycdb], [TinyCDB], [CDB])
61 AS_IF([test x"$rra_use_CDB" != xfalse],
62 [AS_IF([test x"$rra_use_CDB" = xtrue],
63 [_RRA_LIB_CDB_INTERNAL([true])],
64 [_RRA_LIB_CDB_INTERNAL([false])])])
65 AS_IF([test x"$CDB_LIBS" != x],
67 AC_DEFINE([HAVE_CDB], 1, [Define if libcdb is available.])])])