diff options
author | Andrei Pavel <andrei@isc.org> | 2021-07-22 12:48:44 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomek@isc.org> | 2021-07-26 12:17:04 +0200 |
commit | 49961203b0b0fc2304dd46943cab7d71f09fd368 (patch) | |
tree | bf4fadcd300cda61d8709eddaab9a050f7b84d5b | |
parent | [#1077] a more generic AX_FIND_LIBRARY (diff) | |
download | kea-49961203b0b0fc2304dd46943cab7d71f09fd368.tar.xz kea-49961203b0b0fc2304dd46943cab7d71f09fd368.zip |
[#1077] autotools: AX_FIND_LIBRARY & AX_SYSREPO
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | configure.ac | 150 | ||||
-rw-r--r-- | m4macros/ax_find_library.m4 | 212 | ||||
-rw-r--r-- | m4macros/ax_sysrepo.m4 | 202 | ||||
-rw-r--r-- | tools/Makefile.am | 2 | ||||
-rwxr-xr-x | tools/sysrepo_config | 108 | ||||
-rwxr-xr-x | tools/sysrepo_config_defines.sh.sample | 13 |
7 files changed, 350 insertions, 338 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1187f589a6..9a4bee84bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,7 +95,6 @@ shellcheck: - SCRIPTS+="tools/path_replacer.sh.in " - SCRIPTS+="tools/print-generated-files.sh " - SCRIPTS+="tools/shellcheck-all.sh " - - SCRIPTS+="tools/sysrepo_config " - SCRIPTS+="tools/tests_in_valgrind.sh " - shellcheck ${SCRIPTS} ${SHELLCHECK_OPTS} diff --git a/configure.ac b/configure.ac index 9865e65dc3..1abb48d203 100644 --- a/configure.ac +++ b/configure.ac @@ -885,134 +885,8 @@ fi # ... and at the shell level, so Makefile.am can take action depending on this. AM_CONDITIONAL(HAVE_CQL, test "$CQL_CONFIG" != "") -DISTCHECK_SYSREPO_CONFIGURE_FLAG= -sysrepo_config="no" -AC_ARG_WITH([sysrepo], - AS_HELP_STRING([--with-sysrepo=PATH], - [path to pkg-config or the Sysrepo 'sysrepo_config' script]), - [sysrepo_config="$withval"]) - -if test "${sysrepo_config}" = "yes" ; then - if test "$PKG_CONFIG" = ""; then - AC_MSG_ERROR([--with-sysrepo specified without any parameter and pkg-config was not found. Either use --with-sysrepo=path or install pkg-config]) - fi - SYSREPO_CONFIG="$PKG_CONFIG" - DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}" -elif test "${sysrepo_config}" != "no" ; then - SYSREPO_CONFIG="${sysrepo_config}" - DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}" -fi -AC_SUBST(DISTCHECK_SYSREPO_CONFIGURE_FLAG) - -if test "$SYSREPO_CONFIG" != "" ; then - if test -d "$SYSREPO_CONFIG" -o ! -x "$SYSREPO_CONFIG" ; then - AC_MSG_ERROR([--with-sysrepo should point to a pkg-config or sysrepo_config program]) - fi - - # Let's get the configuration environment for pure Sysrepo (written in C) first - SYSREPO_INCLUDEDIR=`$SYSREPO_CONFIG --cflags-only-I libsysrepo` - SYSREPO_CPPFLAGS="$SYSREPO_INCLUDEDIR $($SYSREPO_CONFIG --cflags-only-other libsysrepo)" - SYSREPO_LIBS=$($SYSREPO_CONFIG --libs libsysrepo) - SYSREPO_VERSION=$($SYSREPO_CONFIG --modversion libsysrepo) - SYSREPO_REPO=$($SYSREPO_CONFIG --variable=SR_REPOSITORY_LOC libsysrepo) - - # Now get the environment for C++ bindings for Sysrepo. - SYSREPOCPP_INCLUDEDIR=$($SYSREPO_CONFIG --cflags-only-I libsysrepo-cpp) - SYSREPOCPP_CPPFLAGS="$SYSREPO_INCLUDEDIR $($SYSREPO_CONFIG --cflags-only-other libsysrepo-cpp)" - SYSREPOCPP_LIBS=$($SYSREPO_CONFIG --libs libsysrepo-cpp) - SYSREPOCPP_VERSION=$($SYSREPO_CONFIG --modversion libsysrepo-cpp) - - AC_SUBST(SYSREPO_INCLUDEDIR) - AC_SUBST(SYSREPO_CPPFLAGS) - AC_SUBST(SYSREPO_LIBS) - AC_SUBST(SYSREPO_REPO) - - # Check that a simple program using Sysrepo functions can compile and link. - CPPFLAGS_SAVED="$CPPFLAGS" - LIBS_SAVED="$LIBS" - - CPPFLAGS="$SYSREPO_CPPFLAGS $CPPFLAGS" - LIBS="$SYSREPO_LIBS $LIBS" - - AC_MSG_CHECKING([sysrepo]) - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [extern "C" { - #include <sysrepo.h> - }], - [sr_conn_ctx_t *connection; - sr_session_ctx_t *session; - sr_disconnect(connection);])], - [AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no]) - AC_MSG_ERROR([Cannot integrate with Sysrepo's C API. Make sure that the sysrepo.h header and the libsysrepo.so library can be found.])] - ) - - # If include paths are equal, there's no need to include both. But if they're different, - # we need both. - if test "${SYSREPO_INCLUDEDIR}" != "${SYSREPOCPP_INCLUDEDIR}"; then - SYSREPO_INCLUDEDIR="${SYSREPO_INCLUDEDIR} ${SYSREPOCPP_INCLUDEDIR}" - fi - - if test "${SYSREPO_CPPFLAGS}" != "${SYSREPOCPP_CPPFLAGS}"; then - SYSREPO_CPPFLAGS="${SYSREPO_CPPFLAGS} ${SYSREPOCPP_CPPFLAGS}" - fi - - if test "${SYSREPO_LIBS}" != "${SYSREPOCPP_LIBS}"; then - SYSREPO_LIBS="${SYSREPO_LIBS} ${SYSREPOCPP_LIBS}" - fi - - AC_SUBST(SYSREPO_INCLUDEDIR) - AC_SUBST(SYSREPO_CPPFLAGS) - AC_SUBST(SYSREPO_LIBS) - - CPPFLAGS="$SYSREPO_CPPFLAGS $CPPFLAGS" - LIBS="$SYSREPO_LIBS $LIBS" - - AC_MSG_CHECKING([sysrepo-cpp]) - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include <sysrepo-cpp/Session.hpp>], - [])], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include <sysrepo-cpp/Session.hpp>], - [sysrepo::Connection();] - )], - [AC_MSG_RESULT([v1.x]) - AC_DEFINE([HAVE_SYSREPO_V1], [true], [Using sysrepo 1.x])], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include <sysrepo-cpp/Session.hpp>], - [sysrepo::S_Val value; - value->empty();] - )], - [AC_MSG_RESULT([>= v0.7.7]) - AC_MSG_ERROR([Using legacy sysrepo >= 0.7.7 which is no longer supported. Upgrade to the latest version with C++ bindings: 1.4.140.])], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include <sysrepo-cpp/Session.h>], - [Connection("conn-name");])], - [AC_MSG_RESULT([<= v0.7.6]) - AC_MSG_ERROR([Using sysrepo <= 0.7.6 which is no longer supported. Upgrade to the latest version with C++ bindings: 1.4.140.])], - [AC_MSG_RESULT([no]) - AC_MSG_ERROR([Found Sysrepo C++ bindings, but could not identify their version. If you think Kea should support this version of sysrepo, please contact ISC.)])] - )] - )] - )], - [AC_MSG_RESULT([no]) - AC_MSG_ERROR([Count not integrate with Sysrepo C++ bindings. Make sure that the sysrepo-cpp/Session.hpp header and the libsysrepo-cpp.so library can be found.])] - ) - - CPPFLAGS=$CPPFLAGS_SAVED - LIBS=$LIBS_SAVED - - # Note that Sysrepo is present in the config.h file - AC_DEFINE([HAVE_SYSREPO], [true], [SYSREPO is present]) -fi - -# ... and at the shell level, so Makefile.am can take action depending on this. -AM_CONDITIONAL(HAVE_SYSREPO, test "$SYSREPO_CONFIG" != "") +# Check for sysrepo. +AX_SYSREPO # Check for log4cplus DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG= @@ -2132,17 +2006,23 @@ Cassandra CQL: END fi -if test "$SYSREPO_CPPFLAGS" != "" ; then -cat >> config.report << END +if "${HAVE_SYSREPO}"; then + cat >> config.report << END Sysrepo: - SYSREPO_VERSION: ${SYSREPO_VERSION} - SYSREPO_CPPFLAGS: ${SYSREPO_CPPFLAGS} - SYSREPO_LIBS: ${SYSREPO_LIBS} - SYSREPO_REPO: ${SYSREPO_REPO} + LIBYANG_VERSION: ${LIBYANG_VERSION} + LIBYANGCPP_VERSION: ${LIBYANGCPP_VERSION} + LIBYANG_SOVERSION: ${LIBYANG_SOVERSION} + SYSREPO_CPPFLAGS: ${SYSREPO_CPPFLAGS} + SYSREPO_INCLUDEDIR: ${SYSREPO_INCLUDEDIR} + SYSREPO_LIBS: ${SYSREPO_LIBS} + SR_REPO_PATH: ${SR_REPO_PATH} + SRPD_PLUGINS_PATH: ${SRPD_PLUGINS_PATH} + SYSREPO_VERSION: ${SYSREPO_VERSION} + SYSREPOCPP_VERSION: ${SYSREPOCPP_VERSION} END else -cat >> config.report << END + cat >> config.report << END Sysrepo: no diff --git a/m4macros/ax_find_library.m4 b/m4macros/ax_find_library.m4 index a95f53f9cb..11d1c1f4e9 100644 --- a/m4macros/ax_find_library.m4 +++ b/m4macros/ax_find_library.m4 @@ -1,46 +1,43 @@ -AC_DEFUN([AX_FIND_LIBRARY], [ - library="${1}" +######################### public functions ########################## - AC_ARG_WITH([${library}], - AS_HELP_STRING([--with-${library}=PATH], [path to the ${library}.pc file or to the ${library} installation directory]), - [with_library="$withval"]) +# input: +# * value of --with-library +# * list of headers to check +# * list of libraries to check +# * list of variables to retrieve with pkg-config +# * additional parameters to pass to pkg-config, useful e.g. when --with-path +# is needed to point to a dependency of the checked library +# output: +# * LIBRARY_FOUND +# * LIBRARY_CPFFLAGS +# * LIBRARY_INCLUDEDIR +# * LIBRARY_LIBS +# * LIBRARY_PREFIX +AC_DEFUN([AX_FIND_LIBRARY], [ + library=$1 + with_library=$2 + list_of_headers=$3 + list_of_libraries=$4 + list_of_variables=$5 + additional_arguments_to_pkg_config=$6 - library_found=false - if test -n "${with_library}"; then + LIBRARY_FOUND=false + if test "${with_library}" = 'no'; then + : # nothing to do + elif test "${with_library}" != 'yes'; then if test -f "${with_library}"; then + # User has pointed --with-library to a file. + # It might be a .pc file. + AX_FIND_LIBRARY_WITH_PKG_CONFIG(["${with_library}"], ["${list_of_variables}"], ["${additional_arguments_to_pkg_config}"]) - # User has pointed --with-${library} to a file. Let's try parse it with pkg-config. - if test -n "${PKG_CONFIG}"; then - if "${PKG_CONFIG}" "${with_library}"; then - LIBRARY_CPPFLAGS=$("${PKG_CONFIG}" --cflags-only-other "${with_library}") - LIBRARY_INCLUDEDIR=$("${PKG_CONFIG}" --cflags-only-I "${with_library}") - LIBRARY_LIBS=$("${PKG_CONFIG}" --libs "${with_library}") - LIBRARY_REPO=$("${PKG_CONFIG}" --variable=SR_REPO_PATH "${with_library}") - # LIBRARY_INCLUDEDIR="${LIBRARY_INCLUDEDIR} -I${LIBRARY_CONFIG}/include" - # LIBRARY_LIBS="${LIBRARY_LIBS} -Wl,-rpath=${LIBRARY_CONFIG}/lib" - library_found=true - else - AC_MSG_ERROR(["pkg-config ${with_library}" doesn't work properly. It seems like a bad pkg-config file.]) - fi - else - AC_MSG_ERROR([--with-${library} seems to point to a pkg-config file, but pkg-config is not available]) - fi elif test -d "${with_library}"; then - - # User has pointed --with-${library} to a directory. - # Let's try to find a ${library}.pc first. - library_pc="${LIBRARY_CONFIG}/lib/pkgconfig/${library}.pc" + # User has pointed --with-library to a directory. + # Let's try to find a library.pc first inside that directory. + library_pc="${with_library}/lib/pkgconfig/${library}.pc" if test -f "${library_pc}"; then if test -n "${PKG_CONFIG}"; then if "${PKG_CONFIG}" "${library_pc}"; then - LIBRARY_CPPFLAGS=$("${PKG_CONFIG}" --cflags-only-other "${with_library}") - LIBRARY_INCLUDEDIR=$("${PKG_CONFIG}" --cflags-only-I "${with_library}") - LIBRARY_LIBS=$("${PKG_CONFIG}" --libs "${with_library}") - LIBRARY_REPO=$(cat "${with_library}/lib/pkgconfig/${library}.pc" | grep -F 'SR_REPO_PATH=' | cut -d '=' -f 2) - LIBRARY_VERSION=$("${PKG_CONFIG}" --modversion "${with_library}") - # LIBRARY_INCLUDEDIR="${LIBRARY_INCLUDEDIR} -I${LIBRARY_CONFIG}/include" - # LIBRARY_LIBS="${LIBRARY_LIBS} -Wl,-rpath=${LIBRARY_CONFIG}/lib" - library_found=true + AX_FIND_LIBRARY_WITH_PKG_CONFIG("${library_pc}", ["${list_of_variables}"], ["${additional_arguments_to_pkg_config}"]) else AC_MSG_WARN(["pkg-config ${library_pc}" doesn't work properly. It seems like a bad pkg-config file.]) fi @@ -48,64 +45,119 @@ AC_DEFUN([AX_FIND_LIBRARY], [ AC_MSG_WARN([pkg-config file found at ${library_pc}, but pkg-config is not available]) fi else - AC_MSG_WARN([pkg-config file not found at ${library_pc}]) + AC_MSG_WARN([pkg-config file not found at ${library_pc}]) fi else - AC_MSG_ERROR([--with-${library} doesn't point to the sysrepo.pc file or to the sysrepo installation directory]) + AC_MSG_ERROR(["${with_library}" needs to point to a .pc file or to the installation directory, but points to none of those]) fi - else + else # No parameter given. Try pkg-config first. - for i in /usr usr/local; do - if test -n "${PKG_CONFIG}"; then - if test -f "${i}/include/sysrepo.h" && test -f "${i}/lib/libsysrepo.so"; then - LIBRARY_CPPFLAGS= - LIBRARY_INCLUDEDIR="-I${i}/include" - LIBRARY_LIBS="-L${i}/lib -lsysrepo -lsysrepo-cpp" - LIBRARY_REPO=$(cat "${i}/lib/pkgconfig/sysrepo.pc" | grep -F 'SR_REPO_PATH=' | cut -d '=' -f 2) - LIBRARY_VERSION=$(cat "${i}/include/sysrepo/version.h" | grep -F '#define SR_VERSION ' | cut -d '"' -f 2) - library_found=true - break + if test -n "${PKG_CONFIG}"; then + AX_FIND_LIBRARY_WITH_PKG_CONFIG("${library}", ["${list_of_variables}"], ["${additional_arguments_to_pkg_config}"]) + fi + + # If not found, then search in usual paths for a .pc file. + if ! "${LIBRARY_FOUND}"; then + for p in /usr /usr/local; do + library_pc="${p}/lib/pkgconfig/${library}.pc" + if test -f "${library_pc}"; then + AX_FIND_LIBRARY_WITH_PKG_CONFIG("${library_pc}", ["${list_of_variables}"], ["${additional_arguments_to_pkg_config}"]) + if "${LIBRARY_FOUND}"; then + break + fi fi - fi - done + done + fi # If not found, then search in usual paths for header and libraries. - if ! "${library_found}"; then - for i in /usr usr/local; do - if test -f "${i}/include/sysrepo.h" && test -f "${i}/lib/libsysrepo.so"; then + if ! "${LIBRARY_FOUND}"; then + for p in /usr /usr/local; do + headers_found=true + libraries_found=true + for i in ${list_of_headers}; do + if test ! -f "${p}/include/${i}"; then + AC_MSG_WARN(["${library}" headers not found in "${p}"]) + headers_found=false + break + fi + done + if "${headers_found}"; then LIBRARY_CPPFLAGS= - LIBRARY_INCLUDEDIR="-I${i}/include" - LIBRARY_LIBS=$(-L"${i}/lib" -lsysrepo -lsysrepo-cpp) - LIBRARY_REPO=$(cat "${i}/lib/pkgconfig/sysrepo.pc" | grep -F 'SR_REPO_PATH=' | cut -d '=' -f 2) - LIBRARY_VERSION=$(cat "${i}/include/sysrepo/version.h" | grep -F '#define SR_VERSION ' | cut -d '"' -f 2) - library_found=true + LIBRARY_INCLUDEDIR="-I${p}/include" + fi + + LIBRARY_LIBS="-L${i}/lib -Wl,-rpath=${i}/lib" + for i in ${list_of_libraries}; do + if test ! -f "${p}/lib/${i}"; then + AC_MSG_WARN(["${library}" libraries not found in "${p}"]) + libraries_found=false + break + fi + l=$(printf '%s' "${i}" | sed 's/^lib//g;s/.so$//g') + LIBRARY_LIBS="${LIBRARY_LIBS} -l${l}" + done + + if "${headers_found}" && "${libraries_found}"; then + LIBRARY_FOUND=true break - else - AC_MSG_WARN([sysrepo not found in ${i}]) fi + done fi fi - dnl TODO: - dnl Now get the environment for C++ bindings for Sysrepo. - dnl SYSREPOCPP_INCLUDEDIR=$("${LIBRARY_CONFIG}" --cflags-only-I libsysrepo-cpp) - dnl SYSREPOCPP_CPPFLAGS="${LIBRARY_INCLUDEDIR} $("${LIBRARY_CONFIG}" --cflags-only-other libsysrepo-cpp)" - dnl SYSREPOCPP_LIBS=$("${LIBRARY_CONFIG}" --libs libsysrepo-cpp) - dnl SYSREPOCPP_VERSION=$("${LIBRARY_CONFIG}" --modversion libsysrepo-cpp) - - dnl If include paths are equal, there's no need to include both. But if they're different, - dnl we need both. - dnl if test "${LIBRARY_INCLUDEDIR}" != "${SYSREPOCPP_INCLUDEDIR}"; then - dnl LIBRARY_INCLUDEDIR="${LIBRARY_INCLUDEDIR} ${SYSREPOCPP_INCLUDEDIR}" - dnl fi - - dnl if test "${LIBRARY_CPPFLAGS}" != "${SYSREPOCPP_CPPFLAGS}"; then - dnl LIBRARY_CPPFLAGS="${LIBRARY_CPPFLAGS} ${SYSREPOCPP_CPPFLAGS}" - dnl fi - - dnl if test "${LIBRARY_LIBS}" != "${SYSREPOCPP_LIBS}"; then - dnl LIBRARY_LIBS="${LIBRARY_LIBS} ${SYSREPOCPP_LIBS}" - dnl fi + # Remove leading and trailing spaces. + if "${LIBRARY_FOUND}"; then + LIBRARY_CPFFLAGS="$(printf '%s' "${LIBRARY_CPPFLAGS}" | sed 's/^ *//g;s/ *$//g')" + LIBRARY_INCLUDEDIR="$(printf '%s' "${LIBRARY_INCLUDEDIR}" | sed 's/^ *//g;s/ *$//g')" + LIBRARY_LIBS="$(printf '%s' "${LIBRARY_LIBS}" | sed 's/^ *//g;s/ *$//g')" + fi +]) + +######################### private functions ######################### + +# input: +# * value of --with-library +# * list of variables to retrieve with pkg-config +# * additional parameters to pass to pkg-config, useful e.g. when --with-path +# is needed to point to a dependency of the checked library +# output: +# * LIBRARY_FOUND +# * LIBRARY_CPFFLAGS +# * LIBRARY_INCLUDEDIR +# * LIBRARY_LIBS +# * LIBRARY_PREFIX +AC_DEFUN([AX_FIND_LIBRARY_WITH_PKG_CONFIG], [ + library_pc_or_name=$1 + list_of_variables=$2 + additional_arguments_to_pkg_config=$3 + args="${additional_arguments_to_pkg_config}" # Shorten. + + LIBRARY_FOUND=false + # Check that we have pkg-config installed on the system. + if test -n "${PKG_CONFIG}"; then + # Check that pkg-config is able to interpret the file. + if "${PKG_CONFIG}" "${library_pc_or_name}"; then + # Get the flags. + LIBRARY_CPPFLAGS=$("${PKG_CONFIG}" ${args} --cflags-only-other "${library_pc_or_name}") + LIBRARY_INCLUDEDIR=$("${PKG_CONFIG}" ${args} --cflags-only-I "${library_pc_or_name}") + LIBRARY_LIBS=$("${PKG_CONFIG}" ${args} --libs "${library_pc_or_name}") + LIBRARY_VERSION=$("${PKG_CONFIG}" ${args} --modversion "${library_pc_or_name}") + LIBRARY_PREFIX=$("${PKG_CONFIG}" ${args} --variable=prefix "${library_pc_or_name}") + + # Get the variables. + for i in $(printf '%s' "${list_of_variables}" | sed 's/,/ /g'); do + # The export is not strictly required here, but we need a way to + # dynamically assign values to "${i}". And export is nicer than eval. + export "${i}"="$("${PKG_CONFIG}" ${args} --variable="${i}" "${library_pc_or_name}")" + done + + # LIBRARY_INCLUDEDIR="${LIBRARY_INCLUDEDIR} -I${LIBRARY_CONFIG}/include" + # LIBRARY_LIBS="${LIBRARY_LIBS} -Wl,-rpath=${LIBRARY_CONFIG}/lib" + + # Mark that we have the required flags for our library. + LIBRARY_FOUND=true + fi + fi ]) diff --git a/m4macros/ax_sysrepo.m4 b/m4macros/ax_sysrepo.m4 new file mode 100644 index 0000000000..1c378c5602 --- /dev/null +++ b/m4macros/ax_sysrepo.m4 @@ -0,0 +1,202 @@ +AC_DEFUN([AX_SYSREPO], [ + + AC_ARG_WITH([libyang], + AS_HELP_STRING([--with-libyang=PATH], [path to the libyang.pc file, to the libyang-cpp.pc file or to the libyang installation directory]), + [with_library="${withval}"]) + + AC_MSG_CHECKING([libyang]) + AX_FIND_LIBRARY([libyang], ["${with_library}"], [libyang/libyang.h], [libyang.so], [LIBYANG_SOVERSION]) + if "${LIBRARY_FOUND}"; then + LIBYANG_CPPFLAGS="${LIBRARY_CPPFLAGS}" + LIBYANG_INCLUDEDIR="${LIBRARY_INCLUDEDIR}" + LIBYANG_LIBS="${LIBRARY_LIBS}" + LIBYANG_VERSION="${LIBRARY_VERSION}" + LIBYANG_PREFIX="${LIBRARY_PREFIX}" + + libyang_found=true + AC_MSG_RESULT([yes]) + else + libyang_found=false + AC_MSG_RESULT([no]) + fi + + AC_MSG_CHECKING([libyang-cpp]) + AX_FIND_LIBRARY([libyang-cpp], ["${with_library}"], [libyang/Libyang.hpp], [libyang-cpp.so]) + if "${LIBRARY_FOUND}"; then + + # If include paths are equal, there's no need to include both. But if + # they're different, we need both. + if test "${LIBYANG_INCLUDEDIR}" != "${LIBYANGCPP_INCLUDEDIR}"; then + LIBYANG_INCLUDEDIR="${LIBYANG_INCLUDEDIR} ${LIBYANGCPP_INCLUDEDIR}" + fi + + if test "${LIBYANG_CPPFLAGS}" != "${LIBYANGCPP_CPPFLAGS}"; then + LIBYANG_CPPFLAGS="${LIBYANG_CPPFLAGS} ${LIBYANGCPP_CPPFLAGS}" + fi + + if test "${LIBYANG_LIBS}" != "${LIBYANGCPP_LIBS}"; then + LIBYANG_LIBS="${LIBYANG_LIBS} ${LIBYANGCPP_LIBS}" + fi + + LIBYANGCPP_CPPFLAGS="${LIBRARY_CPPFLAGS}" + LIBYANGCPP_INCLUDEDIR="${LIBRARY_INCLUDEDIR}" + LIBYANGCPP_LIBS="${LIBRARY_LIBS}" + LIBYANGCPP_VERSION="${LIBRARY_VERSION}" + LIBYANGCPP_PREFIX="${LIBRARY_PREFIX}" + + libyang_cpp_found=true + AC_MSG_RESULT([yes]) + else + libyang_cpp_found=false + AC_MSG_RESULT([no]) + fi + + AC_ARG_WITH([sysrepo], + AS_HELP_STRING([--with-sysrepo=PATH], [path to the sysrepo.pc file, to the sysrepo-cpp.pc file or to the sysrepo installation directory]), + [with_library="${withval}"]) + + AC_MSG_CHECKING([sysrepo]) + AX_FIND_LIBRARY([sysrepo], ["${with_library}"], [sysrepo.h], [libsysrepo.so], [], [--with-path="${LIBYANG_PREFIX}/lib/pkgconfig"]) + if "${LIBRARY_FOUND}"; then + SYSREPO_CPPFLAGS="${LIBRARY_CPPFLAGS}" + SYSREPO_INCLUDEDIR="${LIBRARY_INCLUDEDIR}" + SYSREPO_LIBS="${LIBRARY_LIBS}" + SYSREPO_VERSION="${LIBRARY_VERSION}" + + sysrepo_found=true + else + sysrepo_found=false + fi + + if "${sysrepo_found}"; then + AC_SUBST(SYSREPO_CPPFLAGS) + AC_SUBST(SYSREPO_INCLUDEDIR) + AC_SUBST(SYSREPO_LIBS) + + # Save flags. + CPPFLAGS_SAVED="${CPPFLAGS}" + LIBS_SAVED="${LIBS}" + + # Provide Sysrepo flags temporarily. + CPPFLAGS="${CPPFLAGS} ${SYSREPO_INCLUDEDIR} ${SYSREPO_CPPFLAGS}" + LIBS="${LIBS} ${SYSREPO_LIBS}" + + # Check that a simple program using Sysrepo C API can compile and link. + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [extern "C" { + #include <sysrepo.h> + }], + [sr_conn_ctx_t *connection; + sr_session_ctx_t *session; + sr_disconnect(connection);])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([Cannot integrate with Sysrepo's C API. Make sure that the sysrepo.h header and the libsysrepo.so library can be found.])] + ) + + # Restore flags. + CPPFLAGS="${CPPFLAGS_SAVED}" + LIBS="${LIBS_SAVED}" + else + AC_MSG_RESULT([no]) + fi + + AC_MSG_CHECKING([sysrepo-cpp]) + + AX_FIND_LIBRARY([sysrepo-cpp], ["${with_library}"], [sysrepo-cpp/Session.hpp], [libsysrepo-cpp.so], [SR_REPO_PATH,SRPD_PLUGINS_PATH], [--with-path="${LIBYANGCPP_PREFIX}/lib/pkgconfig"]) + if "${LIBRARY_FOUND}"; then + SYSREPOCPP_CPPFLAGS="${LIBRARY_CPPFLAGS}" + SYSREPOCPP_INCLUDEDIR="${LIBRARY_INCLUDEDIR}" + SYSREPOCPP_LIBS="${LIBRARY_LIBS}" + SYSREPOCPP_VERSION="${LIBRARY_VERSION}" + + sysrepo_cpp_found=true + else + sysrepo_cpp_found=false + fi + + if "${sysrepo_cpp_found}"; then + # If include paths are equal, there's no need to include both. But if + # they're different, we need both. + if test "${SYSREPO_INCLUDEDIR}" != "${SYSREPOCPP_INCLUDEDIR}"; then + SYSREPO_INCLUDEDIR="${SYSREPO_INCLUDEDIR} ${SYSREPOCPP_INCLUDEDIR}" + fi + + if test "${SYSREPO_CPPFLAGS}" != "${SYSREPOCPP_CPPFLAGS}"; then + SYSREPO_CPPFLAGS="${SYSREPO_CPPFLAGS} ${SYSREPOCPP_CPPFLAGS}" + fi + + if test "${SYSREPO_LIBS}" != "${SYSREPOCPP_LIBS}"; then + SYSREPO_LIBS="${SYSREPO_LIBS} ${SYSREPOCPP_LIBS}" + fi + + AC_SUBST(SYSREPO_INCLUDEDIR) + AC_SUBST(SYSREPO_CPPFLAGS) + AC_SUBST(SYSREPO_LIBS) + + # Save flags. + CPPFLAGS_SAVED="${CPPFLAGS}" + LIBS_SAVED="${LIBS}" + + # Provide Sysrepo flags temporarily. + CPPFLAGS="${CPPFLAGS} ${SYSREPO_INCLUDEDIR} ${SYSREPO_CPPFLAGS}" + LIBS="${LIBS} ${SYSREPO_LIBS}" + + # Check that a simple program using Sysrepo C++ bindings can compile and link. + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include <sysrepo-cpp/Session.hpp>], + [])], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include <sysrepo-cpp/Session.hpp>], + [sysrepo::Connection();] + )], + [AC_MSG_RESULT([v1.x]) + AC_DEFINE([HAVE_SYSREPO_V1], [true], [Using sysrepo 1.x])], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include <sysrepo-cpp/Session.hpp>], + [sysrepo::S_Val value; + value->empty();] + )], + [AC_MSG_RESULT([>= v0.7.7]) + AC_MSG_ERROR([Using legacy sysrepo >= 0.7.7 which is no longer supported. Upgrade to the latest version with C++ bindings: 1.4.140.])], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include <sysrepo-cpp/Session.h>], + [Connection("conn-name");])], + [AC_MSG_RESULT([<= v0.7.6]) + AC_MSG_ERROR([Using sysrepo <= 0.7.6 which is no longer supported. Upgrade to the latest version with C++ bindings: 1.4.140.])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([Found Sysrepo C++ bindings, but could not identify their version. If you think Kea should support this version of sysrepo, please contact ISC.)])] + )] + )] + )], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([Count not integrate with Sysrepo C++ bindings. Make sure that the sysrepo-cpp/Session.hpp header and the libsysrepo-cpp.so library can be found.])] + ) + + # Restore flags. + CPPFLAGS="${CPPFLAGS_SAVED}" + LIBS="${LIBS_SAVED}" + else + AC_MSG_RESULT([no]) + fi + + if "${libyang_found}" && "${libyang_cpp_found}" && "${sysrepo_found}" && "${sysrepo_cpp_found}"; then + HAVE_SYSREPO=true + else + HAVE_SYSREPO=false + fi + AM_CONDITIONAL(HAVE_SYSREPO, "${HAVE_SYSREPO}") + AC_SUBST(HAVE_SYSREPO) + AC_SUBST(SYSREPO_CPPFLAGS) + AC_SUBST(SYSREPO_INCLUDEDIR) + AC_SUBST(SYSREPO_LIBS) + AC_SUBST(SR_REPO_PATH) + AC_SUBST(SRPD_PLUGINS_PATH) + AC_SUBST(SYSREPO_VERSION) + AC_SUBST(SYSREPOCPP_VERSION) +]) diff --git a/tools/Makefile.am b/tools/Makefile.am index d99f93cb59..15b11d1db6 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -17,6 +17,6 @@ if GENERATE_DOCS # Scripts for sysrepo are also included. If users do not want to install # the sysrepo libraries and binaries in the default system tree and prefer # a custom path, these scripts can be used. -EXTRA_DIST = cql_config cql_config_defines.sh.sample sysrepo_config sysrepo_config_defines.sh.sample +EXTRA_DIST = cql_config cql_config_defines.sh.sample endif diff --git a/tools/sysrepo_config b/tools/sysrepo_config deleted file mode 100755 index 248ab75513..0000000000 --- a/tools/sysrepo_config +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# This is keactrl script responsible for starting up Kea processes. -# This script is used to run Kea from installation directory, -# as well as for running tests. - -# Exit with error if commands exit with non-zero and if undefined variables are -# used. -set -eu - -if [ "$(uname -s)" = "Darwin" ]; then - DIR=$(stat -f %N "$0" | xargs dirname) -else - DIR=$(readlink -f "$0" | xargs dirname) -fi - -if ! [ -f "${DIR}/sysrepo_config_defines.sh" ] || ! [ -x "${DIR}/sysrepo_config_defines.sh" ]; then - echo "missing path configuration file for Sysrepo (sysrepo_config_defines.sh)" - exit 0 -fi - -# Shellcheck tries to follow this link and gets confused about not being able -# to find the file. -# shellcheck disable=SC1090 -. "${DIR}/sysrepo_config_defines.sh" - -if [ $# -ne 1 ] && [ $# -ne 2 ]; then - echo "run: \`$0 --help\` for more help" - exit 0 -fi - -if [ "$1" = "--help" ]; then - echo "sysrepo_config 'option' ['library']" - echo "options:" - echo "--help" - echo " print this help message" - echo "--cflags-only-other" - echo " get cpp compilation flags" - echo "--cflags-only-I" - echo " get include path" - echo "--libs" - echo " get lib path" - echo "--modversion" - echo " get version" - echo "--variable=SR_REPOSITORY_LOC" - echo " get repo path" - echo "libraries:" - echo " libsysrepo" - echo " libsysrepo-cpp" - exit 0 -fi - -if [ $# -ne 2 ]; then - echo "Incorrect number of parameters specified" - echo "run: \`$0 --help\` for more help" - exit 0 -elif [ "$2" != "libsysrepo" ] && [ "$2" != "libsysrepo-cpp" ]; then - echo "library $2 not supported" - echo "run: \`$0 --help\` for more help" - exit 0 -fi - -if [ "$1" = "--cflags-only-other" ]; then - exit 0 -fi - -if [ "$1" = "--cflags-only-I" ]; then - echo "-I${LIBYANG_PATH}/include/ -I${SYSREPO_PATH}/include/" - exit 0 -fi - -if [ "$1" = "--libs" ]; then - printf '%s' "-L${LIBYANG_PATH}/lib/ -L${SYSREPO_PATH}/lib/" - - if [ "$2" = "libsysrepo" ]; then - printf '%s' ' -lyang -lsysrepo' - fi - - if [ "$2" = "libsysrepo-cpp" ]; then - printf '%s' ' -lyang-cpp -lsysrepo-cpp' - fi - - printf '\n' - exit 0 -fi - -if [ "$1" = "--modversion" ]; then - "${SYSREPO_PATH}/bin/sysrepoctl" -V | grep -Eo 'libsysrepo v[0-9\.]*' | \ - cut -d ' ' -f 2 - exit 0 -fi - -if [ "$1" = "--variable=SR_REPOSITORY_LOC" ]; then - "${SYSREPO_PATH}/bin/sysrepoctl" -l | head -n 1 | cut -d ':' -f 2- | \ - cut -d ' ' -f 2- - exit 0 -fi - -echo "wrong parameter" -echo "run: \`$0 --help\` for more help" - -exit 1 diff --git a/tools/sysrepo_config_defines.sh.sample b/tools/sysrepo_config_defines.sh.sample deleted file mode 100755 index 34d649b3d9..0000000000 --- a/tools/sysrepo_config_defines.sh.sample +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -# Variables should point to the installation directories of libyang and sysrepo. -# You can download libyang sources from https://github.com/CESNET/libyang.git. -# You can download sysrepo sources from https://github.com/sysrepo/sysrepo.git. -export LIBYANG_PATH="/please/specify/path/to/libyang/in/sysrepo_config_defines.sh" -export SYSREPO_PATH="/please/specify/path/to/sysrepo/in/sysrepo_config_defines.sh" |