From fe855686044aff02d3c231921c6a6fc9bd62d4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 10 Mar 2020 12:37:25 +0100 Subject: [PATCH] Convert lmdb check to m4 macro --- aclocal.m4 | 1 + config.h.in | 2 +- configure | 377 +++++++++++++++++++++++++++++++++++++++------- configure.ac | 99 +++++------- m4/ax_lib_lmdb.m4 | 58 +++++++ 5 files changed, 423 insertions(+), 114 deletions(-) create mode 100644 m4/ax_lib_lmdb.m4 diff --git a/aclocal.m4 b/aclocal.m4 index 167140bbeb..fa9e0bf9fb 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -376,6 +376,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) m4_include([m4/ax_check_compile_flag.m4]) m4_include([m4/ax_check_openssl.m4]) +m4_include([m4/ax_lib_lmdb.m4]) m4_include([m4/ax_posix_shell.m4]) m4_include([m4/ax_pthread.m4]) m4_include([m4/ax_restore_flags.m4]) diff --git a/config.h.in b/config.h.in index 463841adbc..449ce58765 100644 --- a/config.h.in +++ b/config.h.in @@ -261,7 +261,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_RTNETLINK_H -/* Define if lmdb was found */ +/* Use lmdb library */ #undef HAVE_LMDB /* Define to 1 if you have the header file. */ diff --git a/configure b/configure index 063b660622..69ed062df3 100755 --- a/configure +++ b/configure @@ -733,6 +733,9 @@ LIBXML2_CFLAGS NZDTARGETS NZDSRCS NZD_TOOLS +LMDB_LDFLAGS +LMDB_LIBS +LMDB_CFLAGS DNS_CRYPTO_LIBS DNS_GSSAPI_LIBS DST_GSSAPI_INC @@ -970,6 +973,8 @@ LIBUV_CFLAGS LIBUV_LIBS OPENSSL_CFLAGS OPENSSL_LIBS +LMDB_CFLAGS +LMDB_LIBS LIBXML2_CFLAGS LIBXML2_LIBS JSON_C_CFLAGS @@ -1663,7 +1668,8 @@ Optional Packages: --with-gssapi=PATH|/path/krb5-config Specify path for system-supplied GSSAPI [default=auto] - --with-lmdb=PATH build with LMDB library [yes|no|path] + --with-lmdb=[PATH] use LMDB library [default=auto], optionally specify + the prefix for lmdb library --with-libxml2 build with libxml2 library [yes|no|auto] (default is auto) --with-libjson deprecated, use --with-json-c @@ -1732,6 +1738,8 @@ Some influential environment variables: C compiler flags for OPENSSL, overriding pkg-config OPENSSL_LIBS linker flags for OPENSSL, overriding pkg-config + LMDB_CFLAGS C compiler flags for LMDB, overriding pkg-config + LMDB_LIBS linker flags for LMDB, overriding pkg-config LIBXML2_CFLAGS C compiler flags for LIBXML2, overriding pkg-config LIBXML2_LIBS @@ -17514,53 +17522,96 @@ DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS" # # was --with-lmdb specified? # -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lmdb library" >&5 -$as_echo_n "checking for lmdb library... " >&6; } + # Check whether --with-lmdb was given. if test "${with_lmdb+set}" = set; then : - withval=$with_lmdb; use_lmdb="$withval" + withval=$with_lmdb; : else - use_lmdb="auto" + with_lmdb="auto" fi -have_lmdb="" -case "$use_lmdb" in - no) - lmdb_libs="" - ;; - auto|yes) - for d in /usr /usr/local /opt/local - do - if test -f "${d}/include/lmdb.h" - then - if test ${d} != /usr - then - lmdb_cflags="-I ${d}/include" - LIBS="$LIBS -L${d}/lib" - fi - have_lmdb="yes" - fi - done - ;; - *) - if test -f "${use_lmdb}/include/lmdb.h" - then - lmdb_cflags="-I${use_lmdb}/include" - LIBS="$LIBS -L${use_lmdb}/lib" - have_lmdb="yes" - else - as_fn_error $? "$use_lmdb/include/lmdb.h not found." "$LINENO" 5 - fi - ;; -esac +ac_lib_lmdb_found=no +case $with_lmdb in #( + no) : + ;; #( + auto|yes) : -if test "X${have_lmdb}" != "X" -then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lmdb" >&5 +$as_echo_n "checking for lmdb... " >&6; } + +if test -n "$LMDB_CFLAGS"; then + pkg_cv_LMDB_CFLAGS="$LMDB_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lmdb\""; } >&5 + ($PKG_CONFIG --exists --print-errors "lmdb") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LMDB_CFLAGS=`$PKG_CONFIG --cflags "lmdb" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LMDB_LIBS"; then + pkg_cv_LMDB_LIBS="$LMDB_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"lmdb\""; } >&5 + ($PKG_CONFIG --exists --print-errors "lmdb") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LMDB_LIBS=`$PKG_CONFIG --libs "lmdb" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LMDB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "lmdb" 2>&1` + else + LMDB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "lmdb" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LMDB_PKG_ERRORS" >&5 + + for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do + if test -z "$ac_lib_lmdb_path"; then : + as_fn_error $? "Path cannot be empty" "$LINENO" 5 +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lmdb header in $ac_lib_lmdb_path" >&5 +$as_echo_n "checking for lmdb header in $ac_lib_lmdb_path... " >&6; } + if test -r "$ac_lib_lmdb_path/include/lmdb.h"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mdb_env_create" >&5 + LMDB_CFLAGS="-I$ac_lib_lmdb_path/include" + LMDB_LIBS="-L$ac_lib_lmdb_path/lib" + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS $LMDB_CFLAGS" + LIBS="$LIBS $LMDB_LIBS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mdb_env_create" >&5 $as_echo_n "checking for library containing mdb_env_create... " >&6; } if ${ac_cv_search_mdb_env_create+:} false; then : $as_echo_n "(cached) " >&6 @@ -17613,32 +17664,250 @@ $as_echo "$ac_cv_search_mdb_env_create" >&6; } ac_res=$ac_cv_search_mdb_env_create if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create" + + + ac_lib_lmdb_found=yes + break else - as_fn_error $? "found lmdb include but not library." "$LINENO" 5 - have_lmdb="" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + LMDB_CFLAGS="" + LMDB_LIBS="" + + fi -elif test "X$use_lmdb" = Xyes -then - as_fn_error $? "include/lmdb.h not found." "$LINENO" 5 + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi + done -NZD_TOOLS="" -NZDSRCS= -NZDTARGETS= -if test "X${have_lmdb}" != "X" -then - CFLAGS="$CFLAGS $lmdb_cflags" +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do + if test -z "$ac_lib_lmdb_path"; then : + as_fn_error $? "Path cannot be empty" "$LINENO" 5 +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lmdb header in $ac_lib_lmdb_path" >&5 +$as_echo_n "checking for lmdb header in $ac_lib_lmdb_path... " >&6; } + if test -r "$ac_lib_lmdb_path/include/lmdb.h"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + LMDB_CFLAGS="-I$ac_lib_lmdb_path/include" + LMDB_LIBS="-L$ac_lib_lmdb_path/lib" + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS $LMDB_CFLAGS" + LIBS="$LIBS $LMDB_LIBS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mdb_env_create" >&5 +$as_echo_n "checking for library containing mdb_env_create... " >&6; } +if ${ac_cv_search_mdb_env_create+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char mdb_env_create (); +int +main () +{ +return mdb_env_create (); + ; + return 0; +} +_ACEOF +for ac_lib in '' lmdb; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_mdb_env_create=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_mdb_env_create+:} false; then : + break +fi +done +if ${ac_cv_search_mdb_env_create+:} false; then : + +else + ac_cv_search_mdb_env_create=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_mdb_env_create" >&5 +$as_echo "$ac_cv_search_mdb_env_create" >&6; } +ac_res=$ac_cv_search_mdb_env_create +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create" + + + ac_lib_lmdb_found=yes + break + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + LMDB_CFLAGS="" + LMDB_LIBS="" + + +fi + + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + done + +else + LMDB_CFLAGS=$pkg_cv_LMDB_CFLAGS + LMDB_LIBS=$pkg_cv_LMDB_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + ac_lib_lmdb_found=yes +fi ;; #( + *) : + if test -z "$with_lmdb"; then : + as_fn_error $? "Path cannot be empty" "$LINENO" 5 +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lmdb header in $with_lmdb" >&5 +$as_echo_n "checking for lmdb header in $with_lmdb... " >&6; } + if test -r "$with_lmdb/include/lmdb.h"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + LMDB_CFLAGS="-I$with_lmdb/include" + LMDB_LIBS="-L$with_lmdb/lib" + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS $LMDB_CFLAGS" + LIBS="$LIBS $LMDB_LIBS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mdb_env_create" >&5 +$as_echo_n "checking for library containing mdb_env_create... " >&6; } +if ${ac_cv_search_mdb_env_create+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char mdb_env_create (); +int +main () +{ +return mdb_env_create (); + ; + return 0; +} +_ACEOF +for ac_lib in '' lmdb; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_mdb_env_create=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_mdb_env_create+:} false; then : + break +fi +done +if ${ac_cv_search_mdb_env_create+:} false; then : + +else + ac_cv_search_mdb_env_create=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_mdb_env_create" >&5 +$as_echo "$ac_cv_search_mdb_env_create" >&6; } +ac_res=$ac_cv_search_mdb_env_create +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create" + + + ac_lib_lmdb_found=yes + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + LMDB_CFLAGS="" + LMDB_LIBS="" + + +fi + + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi ;; +esac + +# don't fail when in automatic mode +if test "$with_lmdb" = "auto" && test "$ac_lib_lmdb_found" = "no"; then : + with_lmdb=no +fi + +# hard fail when LMDB requested, but not found +if test "$with_lmdb" != "no" && test "$ac_lib_lmdb_found" != "yes"; then : + as_fn_error $? "LMDB requested, but not found" "$LINENO" 5 +fi + +if test "$ac_lib_lmdb_found" = "yes"; then : $as_echo "#define HAVE_LMDB 1" >>confdefs.h - NZD_TOOLS="nzd" - NZDSRCS='${NZDSRCS}' - NZDTARGETS='${NZDTARGETS}' +fi + + + +#AM_CONDITIONAL([HAVE_LMDB], [test "$ac_lib_lmdb_found" = "yes"]) + +NZD_TOOLS= +NZDSRCS= +NZDTARGETS= +if test -n "$LMDB_LIBS"; then : + NZD_TOOLS="nzd" + NZDSRCS='${NZDSRCS}' + NZDTARGETS='${NZDTARGETS}' fi diff --git a/configure.ac b/configure.ac index 0f051587b4..d2a94e1c0a 100644 --- a/configure.ac +++ b/configure.ac @@ -1168,70 +1168,51 @@ AC_SUBST(DNS_CRYPTO_LIBS) # # was --with-lmdb specified? # -AC_MSG_CHECKING(for lmdb library) -AC_ARG_WITH(lmdb, - AS_HELP_STRING([--with-lmdb[=PATH]], - [build with LMDB library [yes|no|path]]), - use_lmdb="$withval", use_lmdb="auto") -have_lmdb="" -case "$use_lmdb" in - no) - lmdb_libs="" - ;; - auto|yes) - for d in /usr /usr/local /opt/local - do - if test -f "${d}/include/lmdb.h" - then - if test ${d} != /usr - then - lmdb_cflags="-I ${d}/include" - LIBS="$LIBS -L${d}/lib" - fi - have_lmdb="yes" - fi - done - ;; - *) - if test -f "${use_lmdb}/include/lmdb.h" - then - lmdb_cflags="-I${use_lmdb}/include" - LIBS="$LIBS -L${use_lmdb}/lib" - have_lmdb="yes" - else - AC_MSG_ERROR([$use_lmdb/include/lmdb.h not found.]) - fi - ;; -esac +AC_ARG_WITH([lmdb], + [AS_HELP_STRING([--with-lmdb=@<:@PATH@:>@], + [use LMDB library @<:@default=auto@:>@, optionally specify the prefix for lmdb library])], + [:], + [with_lmdb="auto"]) -if test "X${have_lmdb}" != "X" -then - AC_MSG_RESULT(yes) - AC_SEARCH_LIBS([mdb_env_create], [lmdb], [], - [AC_MSG_ERROR([found lmdb include but not library.]) - have_lmdb=""]) -elif test "X$use_lmdb" = Xyes -then - AC_MSG_ERROR([include/lmdb.h not found.]) -else - AC_MSG_RESULT(no) -fi +ac_lib_lmdb_found=no +AS_CASE([$with_lmdb], + [no],[], + [auto|yes], [PKG_CHECK_MODULES([LMDB], [lmdb], + [ac_lib_lmdb_found=yes], + [for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do + AX_LIB_LMDB([$ac_lib_lmdb_path], + [ac_lib_lmdb_found=yes + break]) + done + ])], + [AX_LIB_LMDB([$with_lmdb],[ac_lib_lmdb_found=yes])]) -NZD_TOOLS="" +# don't fail when in automatic mode +AS_IF([test "$with_lmdb" = "auto" && test "$ac_lib_lmdb_found" = "no"], + [with_lmdb=no]) + +# hard fail when LMDB requested, but not found +AS_IF([test "$with_lmdb" != "no" && test "$ac_lib_lmdb_found" != "yes"], + [AC_MSG_ERROR([LMDB requested, but not found])]) + +AS_IF([test "$ac_lib_lmdb_found" = "yes"], + [AC_DEFINE([HAVE_LMDB], [1], [Use lmdb library])]) + +AC_SUBST([LMDB_CFLAGS]) +AC_SUBST([LMDB_LIBS]) +#AM_CONDITIONAL([HAVE_LMDB], [test "$ac_lib_lmdb_found" = "yes"]) + +NZD_TOOLS= NZDSRCS= NZDTARGETS= -if test "X${have_lmdb}" != "X" -then - CFLAGS="$CFLAGS $lmdb_cflags" - AC_DEFINE(HAVE_LMDB, 1, [Define if lmdb was found]) - NZD_TOOLS="nzd" - NZDSRCS='${NZDSRCS}' - NZDTARGETS='${NZDTARGETS}' -fi -AC_SUBST(NZD_TOOLS) -AC_SUBST(NZDSRCS) -AC_SUBST(NZDTARGETS) +AS_IF([test -n "$LMDB_LIBS"], + [NZD_TOOLS="nzd" + NZDSRCS='${NZDSRCS}' + NZDTARGETS='${NZDTARGETS}']) +AC_SUBST([NZD_TOOLS]) +AC_SUBST([NZDSRCS]) +AC_SUBST([NZDTARGETS]) # # was --with-libxml2 specified? diff --git a/m4/ax_lib_lmdb.m4 b/m4/ax_lib_lmdb.m4 new file mode 100644 index 0000000000..0895a9d269 --- /dev/null +++ b/m4/ax_lib_lmdb.m4 @@ -0,0 +1,58 @@ +# =========================================================================== +# https://gitlab.isc.org/isc-projects/autoconf-archive/ax_lib_lmdb.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LIB_LMDB(PATH[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# Test for the LMDB library in a path +# +# This macro takes only one argument, a path to the lmdb headers and library. +# +# This macro calls: +# +# AC_SUBST(LMDB_CFLAGS) +# AC_SUBST(LMDB_LDFLAGS) +# +# LICENSE +# +# Copyright (c) 2020 Internet Systems Consortium +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 19 + +# +AC_DEFUN([AX_LIB_LMDB], + [AS_IF([test -z "$1"], + [AC_MSG_ERROR([Path cannot be empty])]) + AC_MSG_CHECKING([for lmdb header in $1]) + AS_IF([test -r "$1/include/lmdb.h"], + [AC_MSG_RESULT([yes]) + LMDB_CFLAGS="-I$1/include" + LMDB_LIBS="-L$1/lib" + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS $LMDB_CFLAGS" + LIBS="$LIBS $LMDB_LIBS" + AC_SEARCH_LIBS([mdb_env_create], [lmdb], + [LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create" + AC_SUBST([LMDB_CFLAGS]) + AC_SUBST([LMDB_LDFLAGS]) + $2 + ], + [AC_MSG_RESULT([no]) + LMDB_CFLAGS="" + LMDB_LIBS="" + $3 + ]) + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + ], + [AC_MSG_RESULT([no])])])