[libvirt] [PATCH 1/3] build: move readline check into its own macro

Eric Blake eblake at redhat.com
Thu May 2 04:26:31 UTC 2013


Future patches will allow the use of editline in place of readline;
doing this in an isolated file instead of configure.ac will make
the task easier.

We can't quite use LIBVIRT_CHECK_LIB, since we do a double probe
based on what other libraries might be needed for successful linking;
as such, I also didn't modernize the C code conditionals (these
days, we would have prefered 'WITH_READLINE' in config.h instead
of '-DUSE_READLINE' on the command line).  It may be worth cleaning
this up in a future patch.

* configure.ac: Move readline code...
* m4/virt-readline.m4: ...here.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 configure.ac        | 43 +++--------------------------------
 m4/virt-readline.m4 | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 40 deletions(-)
 create mode 100644 m4/virt-readline.m4

diff --git a/configure.ac b/configure.ac
index 229b3f7..8331184 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,6 +162,7 @@ LIBVIRT_CHECK_NETCF
 LIBVIRT_CHECK_NUMACTL
 LIBVIRT_CHECK_OPENWSMAN
 LIBVIRT_CHECK_PCIACCESS
+LIBVIRT_CHECK_READLINE
 LIBVIRT_CHECK_SANLOCK
 LIBVIRT_CHECK_SASL
 LIBVIRT_CHECK_SELINUX
@@ -1404,45 +1405,7 @@ fi
 AM_CONDITIONAL([WITH_PHYP],[test "$with_phyp" = "yes"])

 dnl virsh libraries
-AC_CHECK_HEADERS([readline/readline.h])
-
-# Check for readline.
-AC_CHECK_LIB([readline], [readline],
-	[lv_use_readline=yes; VIRSH_LIBS="$VIRSH_LIBS -lreadline"],
-	[lv_use_readline=no])
-
-# If the above test failed, it may simply be that -lreadline requires
-# some termcap-related code, e.g., from one of the following libraries.
-# See if adding one of them to LIBS helps.
-if test $lv_use_readline = no; then
-    lv_saved_libs=$LIBS
-    LIBS=
-    AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib])
-    case $LIBS in
-      no*) ;;  # handle "no" and "none required"
-      *) # anything else is a -lLIBRARY
-	# Now, check for -lreadline again, also using $LIBS.
-	# Note: this time we use a different function, so that
-	# we don't get a cached "no" result.
-	AC_CHECK_LIB([readline], [rl_initialize],
-		[lv_use_readline=yes
-		 VIRSH_LIBS="$VIRSH_LIBS -lreadline $LIBS"],,
-		[$LIBS])
-	;;
-    esac
-    test $lv_use_readline = no &&
-	AC_MSG_WARN([readline library not found])
-    LIBS=$lv_saved_libs
-fi
-
-if test $lv_use_readline = yes; then
-    AC_DEFINE_UNQUOTED([USE_READLINE], 1,
-		       [whether virsh can use readline])
-    READLINE_CFLAGS=-DUSE_READLINE
-else
-    READLINE_CFLAGS=
-fi
-AC_SUBST([READLINE_CFLAGS])
+VIRSH_LIBS="$VIRSH_LIBS $READLINE_LIBS"
 AC_SUBST([VIRSH_LIBS])

 dnl check if the network driver should be compiled
@@ -2491,6 +2454,7 @@ LIBVIRT_RESULT_NETCF
 LIBVIRT_RESULT_NUMACTL
 LIBVIRT_RESULT_OPENWSMAN
 LIBVIRT_RESULT_PCIACCESS
+LIBVIRT_RESULT_READLINE
 LIBVIRT_RESULT_SANLOCK
 LIBVIRT_RESULT_SASL
 LIBVIRT_RESULT_SELINUX
@@ -2571,7 +2535,6 @@ AC_MSG_NOTICE([])
 AC_MSG_NOTICE([            Debug: $enable_debug])
 AC_MSG_NOTICE([      Use -Werror: $set_werror])
 AC_MSG_NOTICE([    Warning Flags: $WARN_CFLAGS])
-AC_MSG_NOTICE([         Readline: $lv_use_readline])
 AC_MSG_NOTICE([           Python: $with_python])
 AC_MSG_NOTICE([           DTrace: $with_dtrace])
 AC_MSG_NOTICE([            numad: $with_numad])
diff --git a/m4/virt-readline.m4 b/m4/virt-readline.m4
new file mode 100644
index 0000000..8f5a884
--- /dev/null
+++ b/m4/virt-readline.m4
@@ -0,0 +1,65 @@
+dnl The readline library
+dnl
+dnl Copyright (C) 2005-2013 Red Hat, Inc.
+dnl
+dnl This library is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU Lesser General Public
+dnl License as published by the Free Software Foundation; either
+dnl version 2.1 of the License, or (at your option) any later version.
+dnl
+dnl This library is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl Lesser General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU Lesser General Public
+dnl License along with this library.  If not, see
+dnl <http://www.gnu.org/licenses/>.
+dnl
+
+AC_DEFUN([LIBVIRT_CHECK_READLINE],[
+  READLINE_LIBS=
+  AC_CHECK_HEADERS([readline/readline.h])
+
+  AC_CHECK_LIB([readline], [readline],
+	[lv_use_readline=yes; READLINE_LIBS=-lreadline],
+	[lv_use_readline=no])
+
+  # If the above test failed, it may simply be that -lreadline requires
+  # some termcap-related code, e.g., from one of the following libraries.
+  # See if adding one of them to LIBS helps.
+  if test $lv_use_readline = no; then
+    lv_saved_libs=$LIBS
+    LIBS=
+    AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib])
+    case $LIBS in
+      no*) ;;  # handle "no" and "none required"
+      *) # anything else is a -lLIBRARY
+	# Now, check for -lreadline again, also using $LIBS.
+	# Note: this time we use a different function, so that
+	# we don't get a cached "no" result.
+	AC_CHECK_LIB([readline], [rl_initialize],
+		[lv_use_readline=yes
+		 READLINE_LIBS="-lreadline $LIBS"],,
+		[$LIBS])
+	;;
+    esac
+    test $lv_use_readline = no &&
+	AC_MSG_WARN([readline library not found])
+    LIBS=$lv_saved_libs
+  fi
+
+  if test $lv_use_readline = yes; then
+    AC_DEFINE_UNQUOTED([USE_READLINE], 1,
+		       [whether virsh can use readline])
+    READLINE_CFLAGS=-DUSE_READLINE
+  else
+    READLINE_CFLAGS=
+  fi
+  AC_SUBST([READLINE_CFLAGS])
+])
+
+AC_DEFUN([LIBVIRT_RESULT_READLINE],[
+  LIBVIRT_RESULT([readline], [$lv_use_readline],
+     [CFLAGS='$READLINE_CFLAGS' LIBS='$READLINE_LIBS'])
+])
-- 
1.8.1.4




More information about the libvir-list mailing list