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