From: Andrei Pavel Date: Thu, 15 Jul 2021 11:57:13 +0000 (+0300) Subject: [#1077] make autotools work with sysrepo 1.4 X-Git-Tag: Kea-1.9.10~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9942b35e41cbd8cb5d320ffb23c2fc59c16f0e37;p=thirdparty%2Fkea.git [#1077] make autotools work with sysrepo 1.4 --- diff --git a/configure.ac b/configure.ac index 6e77decc05..ae99e57c4e 100644 --- a/configure.ac +++ b/configure.ac @@ -917,10 +917,36 @@ if test "$SYSREPO_CONFIG" != "" ; then 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) + 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 + }], + [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. @@ -939,57 +965,50 @@ if test "$SYSREPO_CONFIG" != "" ; then 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-cpp]) AC_LINK_IFELSE( - [AC_LANG_PROGRAM([extern "C" { - #include - }], - [sr_conn_ctx_t *connection = NULL; - sr_session_ctx_t *session = NULL; - sr_connect("configure_test", SR_CONN_DEFAULT, &connection); - sr_disconnect(connection);])], - [AC_MSG_RESULT([checking for Sysrepo headers and library... yes])], - [AC_MSG_RESULT([checking for Sysrepo headers and library... no]) - AC_MSG_ERROR([Needs Sysrepo library])] - ) - - AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include ], + [])], + [AC_LINK_IFELSE( [AC_LANG_PROGRAM( - [#include ], - [sysrepo::Connection("conn-name");])], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [#include ], - [auto is_empty = [[]](sysrepo::S_Val v){ - return (v->empty()); }; - ])], - [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library, new]) - AC_DEFINE([HAVE_POST_0_7_7_SYSREPO], [1], [Using sysrepo > 0.7.7])], - [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library, yes])])], + [#include ], + [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::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 ], - [Connection("conn-name");])], - [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... old]) - AC_DEFINE([HAVE_PRE_0_7_6_SYSREPO], [1], [Using sysrepo < 0.7.6])], - [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... no]) - AC_MSG_ERROR([Needs Sysrepo C++ bindings (unable to find Sysrepo-ccp library. To get it, you need to compile sysrepo with -DGEN_CPP_BINDINGS=ON.)])] + [#include ], + [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], [1], [SYSREPO is present]) + AC_DEFINE([HAVE_SYSREPO], [true], [SYSREPO is present]) fi # ... and at the shell level, so Makefile.am can take action depending on this. diff --git a/tools/sysrepo_config b/tools/sysrepo_config index 79c45ca01c..248ab75513 100755 --- a/tools/sysrepo_config +++ b/tools/sysrepo_config @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +# 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 @@ -52,7 +52,7 @@ if [ "$1" = "--help" ]; then echo " get repo path" echo "libraries:" echo " libsysrepo" - echo " libSysrepo-cpp" + echo " libsysrepo-cpp" exit 0 fi @@ -60,7 +60,7 @@ 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 +elif [ "$2" != "libsysrepo" ] && [ "$2" != "libsysrepo-cpp" ]; then echo "library $2 not supported" echo "run: \`$0 --help\` for more help" exit 0 @@ -71,24 +71,34 @@ if [ "$1" = "--cflags-only-other" ]; then fi if [ "$1" = "--cflags-only-I" ]; then - echo "-I${SYSREPO_PATH}/include/" + echo "-I${LIBYANG_PATH}/include/ -I${SYSREPO_PATH}/include/" exit 0 fi if [ "$1" = "--libs" ]; then - # Earlier versions also required -lprotobuf, but it is no longer needed. - echo "-L${LIBYANG_PATH}/lib/ -L${SYSREPO_PATH}/lib/ -lsysrepo -lSysrepo-cpp -lyang -pthread -lpcre -lev -lavl -lprotobuf-c" + 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 - VERSION=$(sysrepoctl -v | tr -s " " | cut -d " " -f 7) - echo "${VERSION}" + "${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 - echo "${SYSREPO_PATH}/build/repository" + "${SYSREPO_PATH}/bin/sysrepoctl" -l | head -n 1 | cut -d ':' -f 2- | \ + cut -d ' ' -f 2- exit 0 fi diff --git a/tools/sysrepo_config_defines.sh.sample b/tools/sysrepo_config_defines.sh.sample index 04de5e1055..34d649b3d9 100755 --- a/tools/sysrepo_config_defines.sh.sample +++ b/tools/sysrepo_config_defines.sh.sample @@ -1,10 +1,13 @@ #!/bin/sh -# This auxiliary script is considered temporary in nature. It will not be -# necessary once the DataStax cpp-driver project accepts proper cql_config -# script. +# 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 variable should point to the directory where sysrepo is compiled. -# You can download sysrepo sources from https://github.com/sysrepo/sysrepo.git +# 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"