[libvirt] [PATCH] Update LIBVIRT_CHECK_LIB and LIBVIRT_CHECK_LIB_ALT to use pkg-config

For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed. We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- m4/virt-lib.m4 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/m4/virt-lib.m4 b/m4/virt-lib.m4 index 75b9b1d..2401034 100644 --- a/m4/virt-lib.m4 +++ b/m4/virt-lib.m4 @@ -78,6 +78,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var" @@ -211,6 +213,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB_ALT],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var" -- 2.0.4

On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 12/04/2014 09:41 PM, Eric Blake wrote:
On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD?
Hi, it will use the pkg-config everywhere. I don't know the exact reason why yajl and sasl don't use the LIBVIRT_CHECK_PKG but it seems that it's because we support two different major versions of yajl and the have some changes in API and ABI so we have to check which version is installed in the system and define appropriate macros. See the 'src/util/virjson.c' that we have "WITH_YAJL" and "WITH_YAJL2". The LIBVIRT_CHECK_PKG doesn't count with the possibility of alternative versions of libraries. In this case the "PKG_CHECK_MODULES" will just set for yajl "YAJL_CFLAGS" and "YAJL_LIBS" with correct path only if pkg-config is able to find that information otherwise it will leave them empty and ends without exiting with error message. It's used there only as helper to get the correct paths for libraries where we for some reason what to use "AC_CHECK_LIB" and "AC_CHECK_HEADER" instead of "PKG_CHECK_MODULES". Pavel

On 12/04/2014 03:36 PM, Pavel Hrdina wrote:
On 12/04/2014 09:41 PM, Eric Blake wrote:
On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD?
Hi, it will use the pkg-config everywhere. I don't know the exact reason why yajl and sasl don't use the LIBVIRT_CHECK_PKG but it seems that it's because we support two different major versions of yajl and the have some changes in API and ABI so we have to check which version is installed in the system and define appropriate macros.
See the 'src/util/virjson.c' that we have "WITH_YAJL" and "WITH_YAJL2". The LIBVIRT_CHECK_PKG doesn't count with the possibility of alternative versions of libraries.
Hmm, I wonder if we can reuse some of the logic currently in configure.ac that probes whether gnutls is at version 2.x or 3.x by directly probing '$PKG_CONFIG --exists ...', and then going on to PKG_CHECK_MODULES once we know which of the two library flavors we are dealing with. That is, I still think we are better off patching virt/m4-yajl.m4 (the one library where we know we have pkg_config information, but aren't using it right) than changing virt/m4-lib.m4 to affect all libraries (where we aren't sure the libraries are using pkg_config to begin with). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 12/04/2014 11:59 PM, Eric Blake wrote:
On 12/04/2014 03:36 PM, Pavel Hrdina wrote:
On 12/04/2014 09:41 PM, Eric Blake wrote:
On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD?
Hi, it will use the pkg-config everywhere. I don't know the exact reason why yajl and sasl don't use the LIBVIRT_CHECK_PKG but it seems that it's because we support two different major versions of yajl and the have some changes in API and ABI so we have to check which version is installed in the system and define appropriate macros.
See the 'src/util/virjson.c' that we have "WITH_YAJL" and "WITH_YAJL2". The LIBVIRT_CHECK_PKG doesn't count with the possibility of alternative versions of libraries.
Hmm, I wonder if we can reuse some of the logic currently in configure.ac that probes whether gnutls is at version 2.x or 3.x by directly probing '$PKG_CONFIG --exists ...', and then going on to PKG_CHECK_MODULES once we know which of the two library flavors we are dealing with. That is, I still think we are better off patching virt/m4-yajl.m4 (the one library where we know we have pkg_config information, but aren't using it right) than changing virt/m4-lib.m4 to affect all libraries (where we aren't sure the libraries are using pkg_config to begin with).
In that case we know that "audit, libcap-ng, libsasl2, libselinux and yajl" supports the pkg-config. It means that we can rewrite all of the to use LIBVIRT_CHECK_PKG and for the yajl ans libsasl2 we will have to create a new macro called "LIBVIRT_CHECK_PKG_ALT". Pavel
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Dec 04, 2014 at 01:41:10PM -0700, Eric Blake wrote:
On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD?
I'm not sure that older versions of yajl actually use pkg-config - if they did I'm sure I would have used PKG_CHECK_MODULES in the first place. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 12/05/2014 11:07 AM, Daniel P. Berrange wrote:
On Thu, Dec 04, 2014 at 01:41:10PM -0700, Eric Blake wrote:
On 12/04/2014 01:30 PM, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
This feels a bit awkward. Shouldn't we instead be fixing m4/virt-yajl.m4 to use LIBVIRT_CHECK_PKG? That is, shouldn't yajl be using pkg-config everywhere, and not just on FreeBSD?
I'm not sure that older versions of yajl actually use pkg-config - if they did I'm sure I would have used PKG_CHECK_MODULES in the first place.
Regards, Daniel
I didn't thought about that and you are right. At least on rhel-6 there is yajl-1 and it doesn't use pkg-config. But this patch will work with that, except that it won't find the path to yajl or any other library that doesn't support pkg-config. It will set the _CFLAGS and _LIBS only in case the pkg-config is able to find that information. There will be error message about missing pkg-config only in the config.log for libraries which don't support the pkg-config. Pavel

On Thu, Dec 04, 2014 at 09:30:54PM +0100, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- m4/virt-lib.m4 | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/m4/virt-lib.m4 b/m4/virt-lib.m4 index 75b9b1d..2401034 100644 --- a/m4/virt-lib.m4 +++ b/m4/virt-lib.m4 @@ -78,6 +78,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var" @@ -211,6 +213,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB_ALT],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var"
These CHECK_LIB* functions are the non-pkg-config codepath, so it is really wrong to put PKG_CHECK_MODULE calls in here IMHO. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 12/05/2014 11:09 AM, Daniel P. Berrange wrote:
On Thu, Dec 04, 2014 at 09:30:54PM +0100, Pavel Hrdina wrote:
For example on FreeBSD the "yajl" library is located at "/usr/local/lib" and it's not in default LIBS and therefore the configure fails that "yajl" not installed.
We can use the "PKG_CHECK_MODULES" to get the correct library path in case the library provides pkg-config file definition, otherwise the old approach is used.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- m4/virt-lib.m4 | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/m4/virt-lib.m4 b/m4/virt-lib.m4 index 75b9b1d..2401034 100644 --- a/m4/virt-lib.m4 +++ b/m4/virt-lib.m4 @@ -78,6 +78,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var" @@ -211,6 +213,8 @@ AC_DEFUN([LIBVIRT_CHECK_LIB_ALT],[ if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then cflags_var="-I$with_var/include" libs_var="-L$with_var/lib" + else + PKG_CHECK_MODULES(check_name, library_name, [], [true]) fi CFLAGS="$CFLAGS $cflags_var" LIBS="$LIBS $libs_var"
These CHECK_LIB* functions are the non-pkg-config codepath, so it is really wrong to put PKG_CHECK_MODULE calls in here IMHO.
Regards, Daniel
I know that those macros are the non-pkg-config codepath and it seems to be wrong using the PKG_CHECK_MODULE there but it will work even if pkg-config isn't installed in the system or if library in question doesn't support pkg-config. If you still disagree with this solution, then the users of systems where some libraries are not in the default LIBS path will have to set the correct path manually for those libraries. However I think that it would be nice to autodetect as much as possible. I'll try to come up with more suitable patch for this issue. Pavel
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Pavel Hrdina