[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/4] Add a simple macro to check in which library dlopen() is, and use it.



Since on not all systems dlopen() is in libdl, add a very simple macro that
allows to search for it and sets a DLOPEN_LIBS variable with its value to
be used.

Use the macro instead of hardcoding -ldl for the drivers-as-modules case.
---
 configure.ac |    4 ++--
 m4/libdl.m4  |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 m4/libdl.m4

diff --git a/configure.ac b/configure.ac
index 5b1eb5f..4a848cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1705,7 +1705,7 @@ if test "x$with_driver_modules" = "xyes" ; then
   old_libs="$LIBS"
   fail=0
   AC_CHECK_HEADER([dlfcn.h],[],[fail=1])
-  AC_CHECK_LIB([dl], [dlopen],[],[fail=1])
+  AFX_LIB_DLOPEN([], [fail=1])
   test $fail = 1 &&
       AC_MSG_ERROR([You must have dlfcn.h / dlopen() support to build driver modules])
 
@@ -1714,7 +1714,7 @@ if test "x$with_driver_modules" = "xyes" ; then
 fi
 if test "$with_driver_modules" = "yes"; then
   DRIVER_MODULES_CFLAGS="-export-dynamic"
-  DRIVER_MODULES_LIBS="-ldl"
+  DRIVER_MODULES_LIBS="$DLOPEN_LIBS"
   AC_DEFINE_UNQUOTED([WITH_DRIVER_MODULES], 1, [whether to build drivers as modules])
 fi
 AM_CONDITIONAL([WITH_DRIVER_MODULES], [test "$with_driver_modules" != "no"])
diff --git a/m4/libdl.m4 b/m4/libdl.m4
new file mode 100644
index 0000000..84b6a2c
--- /dev/null
+++ b/m4/libdl.m4
@@ -0,0 +1,44 @@
+dnl Copyright (c) 2010 Diego Elio Pettenò <flameeyes gmail com>
+dnl
+dnl Permission is hereby granted, free of charge, to any person
+dnl obtaining a copy of this software and associated documentation
+dnl files (the "Software"), to deal in the Software without
+dnl restriction, including without limitation the rights to use,
+dnl copy, modify, merge, publish, distribute, sublicense, and/or sell
+dnl copies of the Software, and to permit persons to whom the
+dnl Software is furnished to do so, subject to the following
+dnl conditions:
+dnl
+dnl The above copyright notice and this permission notice shall be
+dnl included in all copies or substantial portions of the Software.
+dnl
+dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+dnl EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+dnl OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+dnl NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+dnl HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+dnl WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+dnl OTHER DEALINGS IN THE SOFTWARE.
+
+dnl AFX to get a unique namespace before it is submitted somewhere
+dnl (like autoconf-archive).
+AC_DEFUN([AFX_LIB_DLOPEN], [
+  DLOPEN_LIBS=
+
+m4_pushdef([action_if_not_found],
+           [m4_default([$2],
+                       [AC_MSG_ERROR([Unable to find the dlopen() function])]
+                      )
+           ])
+
+  old_libs=$LIBS
+  AC_SEARCH_LIBS([dlopen], [dl],
+    [DLOPEN_LIBS=${LIBS#${old_libs}}
+     $1], action_if_not_found)
+  LIBS=$old_libs
+
+m4_popdef([action_if_not_found])
+
+  AC_SUBST([DLOPEN_LIBS])
+])
-- 
1.7.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]