[libvirt] [PATCH 0/2] Make it easier to disable readline

Previously, disabling readline involved uninstalling the development library, or else configuring with: ac_cv_lib_readline_readline=no ac_cv_search_tgetent=no ac_cv_lib_readline_rl_initialize=no With this series, it is much easier to test that virsh still works without readline support, merely using ./configuire --without-readline. Eric Blake (2): build: move readline check into its own macro build: add configure --without-readline configure.ac | 43 +++---------------------------------------- m4/virt-readline.m4 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 12 ++++++------ 3 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 m4/virt-readline.m4 -- 1.8.3.1

A future patch will allow disabling readline; doing this in an isolated file instead of configure.ac will make the task easier. * configure.ac: Move readline code... * m4/virt-readline.m4: ...here. Signed-off-by: Eric Blake <eblake@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 40e2210..7e357c4 100644 --- a/configure.ac +++ b/configure.ac @@ -237,6 +237,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 @@ -1565,45 +1566,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 @@ -2738,6 +2701,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 @@ -2818,7 +2782,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.3.1

Make it much easier to test a configuration built without readline support, by reusing our existing library probe machinery. It gets a bit tricky with readline, which does not provide a pkg-config snippet, and which on some platforms requires one of several terminal libraries as a prerequiste, but the end result should be the same default behavior but now with the option to disable things. * m4/virt-readline.m4 (LIBVIRT_CHECK_READLINE): Simplify by using LIBVIRT_CHECK_LIB. * tools/virsh.c: Convert USE_READLINE to WITH_READLINE. Signed-off-by: Eric Blake <eblake@redhat.com> --- m4/virt-readline.m4 | 51 ++++++++++++++++++--------------------------------- tools/virsh.c | 12 ++++++------ 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/m4/virt-readline.m4 b/m4/virt-readline.m4 index 8f5a884..775c186 100644 --- a/m4/virt-readline.m4 +++ b/m4/virt-readline.m4 @@ -18,48 +18,33 @@ 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 + extra_LIBS= + lv_saved_libs=$LIBS + if test "x$with_readline" != xno; then + # Linking with -lreadline may require some termcap-related code, e.g., + # from one of the following libraries. Add it to LIBS before using + # canned library checks; then verify later if it was needed. 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]) - ;; + extra_LIBS=$LIBS ;; esac - test $lv_use_readline = no && - AC_MSG_WARN([readline library not found]) - LIBS=$lv_saved_libs + LIBS="$lv_saved_libs $extra_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]) + # The normal library check... + LIBVIRT_CHECK_LIB([READLINE], [readline], [readline], [readline/readline.h]) + + # Touch things up to avoid $extra_LIBS, if possible. Test a second + # function, to ensure we aren't being confused by caching. + LIBS=$lv_saved_libs + AC_CHECK_LIB([readline], [rl_initialize], + [], [READLINE_LIBS="$READLINE_LIBS $extra_LIBS"]) + LIBS=$lv_saved_libs ]) AC_DEFUN([LIBVIRT_RESULT_READLINE],[ - LIBVIRT_RESULT([readline], [$lv_use_readline], - [CFLAGS='$READLINE_CFLAGS' LIBS='$READLINE_LIBS']) + LIBVIRT_RESULT_LIB([READLINE]) ]) diff --git a/tools/virsh.c b/tools/virsh.c index ac354ac..6842ed8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -48,7 +48,7 @@ #include <libxml/xpath.h> #include <libxml/xmlsave.h> -#ifdef HAVE_READLINE_READLINE_H +#if WITH_READLINE # include <readline/readline.h> # include <readline/history.h> #endif @@ -2580,7 +2580,7 @@ vshCloseLogFile(vshControl *ctl) } } -#ifdef USE_READLINE +#if WITH_READLINE /* ----------------- * Readline stuff @@ -2765,7 +2765,7 @@ vshReadline(vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt) return readline(prompt); } -#else /* !USE_READLINE */ +#else /* !WITH_READLINE */ static int vshReadlineInit(vshControl *ctl ATTRIBUTE_UNUSED) @@ -2799,7 +2799,7 @@ vshReadline(vshControl *ctl, const char *prompt) return vshStrdup(ctl, r); } -#endif /* !USE_READLINE */ +#endif /* !WITH_READLINE */ static void vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) @@ -3026,7 +3026,7 @@ vshShowVersion(vshControl *ctl ATTRIBUTE_UNUSED) #ifdef WITH_DTRACE_PROBES vshPrint(ctl, " DTrace"); #endif -#ifdef USE_READLINE +#if WITH_READLINE vshPrint(ctl, " Readline"); #endif #ifdef WITH_DRIVER_MODULES @@ -3316,7 +3316,7 @@ main(int argc, char **argv) if (ctl->cmdstr == NULL) break; /* EOF */ if (*ctl->cmdstr) { -#if USE_READLINE +#if WITH_READLINE add_history(ctl->cmdstr); #endif if (vshCommandStringParse(ctl, ctl->cmdstr)) -- 1.8.3.1

On 04.10.2013 20:26, Eric Blake wrote:
Previously, disabling readline involved uninstalling the development library, or else configuring with:
ac_cv_lib_readline_readline=no ac_cv_search_tgetent=no ac_cv_lib_readline_rl_initialize=no
With this series, it is much easier to test that virsh still works without readline support, merely using ./configuire --without-readline.
Eric Blake (2): build: move readline check into its own macro build: add configure --without-readline
configure.ac | 43 +++---------------------------------------- m4/virt-readline.m4 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 12 ++++++------ 3 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 m4/virt-readline.m4
ACK series. Michal

On 10/07/2013 01:38 AM, Michal Privoznik wrote:
On 04.10.2013 20:26, Eric Blake wrote:
Previously, disabling readline involved uninstalling the development library, or else configuring with:
ac_cv_lib_readline_readline=no ac_cv_search_tgetent=no ac_cv_lib_readline_rl_initialize=no
With this series, it is much easier to test that virsh still works without readline support, merely using ./configuire --without-readline.
Eric Blake (2): build: move readline check into its own macro build: add configure --without-readline
configure.ac | 43 +++---------------------------------------- m4/virt-readline.m4 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 12 ++++++------ 3 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 m4/virt-readline.m4
ACK series.
Thanks; pushed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Michal Privoznik