build: add configure --without-readline

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>
This commit is contained in:
Eric Blake 2013-10-04 11:51:41 -06:00
parent d6eac3f377
commit e5f46105a1
2 changed files with 24 additions and 39 deletions

View File

@ -18,48 +18,33 @@ dnl <http://www.gnu.org/licenses/>.
dnl dnl
AC_DEFUN([LIBVIRT_CHECK_READLINE],[ AC_DEFUN([LIBVIRT_CHECK_READLINE],[
READLINE_LIBS= extra_LIBS=
AC_CHECK_HEADERS([readline/readline.h]) lv_saved_libs=$LIBS
if test "x$with_readline" != xno; then
AC_CHECK_LIB([readline], [readline], # Linking with -lreadline may require some termcap-related code, e.g.,
[lv_use_readline=yes; READLINE_LIBS=-lreadline], # from one of the following libraries. Add it to LIBS before using
[lv_use_readline=no]) # canned library checks; then verify later if it was needed.
# 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= LIBS=
AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib]) AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib])
case $LIBS in case $LIBS in
no*) ;; # handle "no" and "none required" no*) ;; # handle "no" and "none required"
*) # anything else is a -lLIBRARY *) # anything else is a -lLIBRARY
# Now, check for -lreadline again, also using $LIBS. extra_LIBS=$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 esac
test $lv_use_readline = no && LIBS="$lv_saved_libs $extra_LIBS"
AC_MSG_WARN([readline library not found])
LIBS=$lv_saved_libs
fi fi
if test $lv_use_readline = yes; then # The normal library check...
AC_DEFINE_UNQUOTED([USE_READLINE], 1, LIBVIRT_CHECK_LIB([READLINE], [readline], [readline], [readline/readline.h])
[whether virsh can use readline])
READLINE_CFLAGS=-DUSE_READLINE # Touch things up to avoid $extra_LIBS, if possible. Test a second
else # function, to ensure we aren't being confused by caching.
READLINE_CFLAGS= LIBS=$lv_saved_libs
fi AC_CHECK_LIB([readline], [rl_initialize],
AC_SUBST([READLINE_CFLAGS]) [], [READLINE_LIBS="$READLINE_LIBS $extra_LIBS"])
LIBS=$lv_saved_libs
]) ])
AC_DEFUN([LIBVIRT_RESULT_READLINE],[ AC_DEFUN([LIBVIRT_RESULT_READLINE],[
LIBVIRT_RESULT([readline], [$lv_use_readline], LIBVIRT_RESULT_LIB([READLINE])
[CFLAGS='$READLINE_CFLAGS' LIBS='$READLINE_LIBS'])
]) ])

View File

@ -48,7 +48,7 @@
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <libxml/xmlsave.h> #include <libxml/xmlsave.h>
#ifdef HAVE_READLINE_READLINE_H #if WITH_READLINE
# include <readline/readline.h> # include <readline/readline.h>
# include <readline/history.h> # include <readline/history.h>
#endif #endif
@ -2580,7 +2580,7 @@ vshCloseLogFile(vshControl *ctl)
} }
} }
#ifdef USE_READLINE #if WITH_READLINE
/* ----------------- /* -----------------
* Readline stuff * Readline stuff
@ -2765,7 +2765,7 @@ vshReadline(vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt)
return readline(prompt); return readline(prompt);
} }
#else /* !USE_READLINE */ #else /* !WITH_READLINE */
static int static int
vshReadlineInit(vshControl *ctl ATTRIBUTE_UNUSED) vshReadlineInit(vshControl *ctl ATTRIBUTE_UNUSED)
@ -2799,7 +2799,7 @@ vshReadline(vshControl *ctl, const char *prompt)
return vshStrdup(ctl, r); return vshStrdup(ctl, r);
} }
#endif /* !USE_READLINE */ #endif /* !WITH_READLINE */
static void static void
vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
@ -3026,7 +3026,7 @@ vshShowVersion(vshControl *ctl ATTRIBUTE_UNUSED)
#ifdef WITH_DTRACE_PROBES #ifdef WITH_DTRACE_PROBES
vshPrint(ctl, " DTrace"); vshPrint(ctl, " DTrace");
#endif #endif
#ifdef USE_READLINE #if WITH_READLINE
vshPrint(ctl, " Readline"); vshPrint(ctl, " Readline");
#endif #endif
#ifdef WITH_DRIVER_MODULES #ifdef WITH_DRIVER_MODULES
@ -3316,7 +3316,7 @@ main(int argc, char **argv)
if (ctl->cmdstr == NULL) if (ctl->cmdstr == NULL)
break; /* EOF */ break; /* EOF */
if (*ctl->cmdstr) { if (*ctl->cmdstr) {
#if USE_READLINE #if WITH_READLINE
add_history(ctl->cmdstr); add_history(ctl->cmdstr);
#endif #endif
if (vshCommandStringParse(ctl, ctl->cmdstr)) if (vshCommandStringParse(ctl, ctl->cmdstr))