>From 21ac3c7a026b2b4be04bdbe62e0f7d1b0e1a0245 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Tue, 15 Oct 2013 22:02:26 +0200 Subject: [PATCH] readline: Support libedit. Allow libedit as an alternate source of readline(). Debian and NetBSD benefit from this extension. * m4/readline.m4: Make libedit into a second choice, should libreadline be missing. * modules/readline: Update conditions to accept libedit. --- ChangeLog | 18 +++++++++++++++++ lib/readline.h | 2 ++ m4/readline.m4 | 58 +++++++++++++++++++++++++++++++++++++++++++++++++----- modules/readline | 4 ++-- 4 filer ändrade, 75 tillägg(+), 7 borttagningar(-) diff --git a/ChangeLog b/ChangeLog index c70f1fe..b6a0cb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2013-10-15 Mats Erik Andersson + + readline: Support libedit. + Look for readline() in libedit, if it does not exist + within libreadline. + * lib/readline.h [HAVE_EDITLINE_READLINE_H]: + Include . + * m4/readline.m4 (gl_FUNC_READLINE): Check for libedit, + and headers , . + Check for readline in libedit. + (HAVE_LIBREADLINE, HAVE_LIBEDIT): New macros, stating that + readline exists in libreadline, or in libedit. The macro + HAVE_READLINE still indicates the existence of readline(). + (LIBEDIT, LTLIBEDIT): New local variables. + * modules/readline (Depends-on): Expand condition for `getline' + to also test gl_cv_lib_edit. + (configure.ac): Add test on gl_cv_lib_edit. + 2013-10-14 Paul Eggert acl: allow cross-compilation to Gentoo diff --git a/lib/readline.h b/lib/readline.h index af91e10..f3e0853 100644 --- a/lib/readline.h +++ b/lib/readline.h @@ -23,6 +23,8 @@ itself. */ # include # include +#elif defined HAVE_EDITLINE_READLINE_H +# include #else /* Prints a prompt PROMPT and then reads and returns a single line of text from the user. If PROMPT is NULL or the empty string, no diff --git a/m4/readline.m4 b/m4/readline.m4 index dfc48a0..b734ed1 100644 --- a/m4/readline.m4 +++ b/m4/readline.m4 @@ -1,4 +1,4 @@ -# readline.m4 serial 10 +# readline.m4 serial 11 dnl Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -17,6 +17,14 @@ AC_DEFUN([gl_FUNC_READLINE], dnl INCREADLINE accordingly. AC_LIB_LINKFLAGS_BODY([readline]) + dnl Likewise for libedit. + AC_LIB_LINKFLAGS_BODY([edit]) + + dnl The headers are needed to distinguish alternate + dnl implementations, so check for them now. + AC_CHECK_HEADERS([readline/readline.h readline/history.h \ + editline/readline.h editline/history.h]) + dnl Add $INCREADLINE to CPPFLAGS before performing the following checks, dnl because if the user has installed libreadline and not disabled its use dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE @@ -24,7 +32,7 @@ AC_DEFUN([gl_FUNC_READLINE], am_save_CPPFLAGS="$CPPFLAGS" AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE]) - AC_CACHE_CHECK([for readline], [gl_cv_lib_readline], [ + AC_CACHE_CHECK([for libreadline], [gl_cv_lib_readline], [ gl_cv_lib_readline=no am_save_LIBS="$LIBS" dnl On some systems, -lreadline doesn't link without an additional @@ -53,8 +61,40 @@ AC_DEFUN([gl_FUNC_READLINE], LIBS="$am_save_LIBS" ]) + dnl Check whether libedit exists and works. + dnl The readline emulation comes in two flavours: + dnl + dnl * original by NetBSD offers , + dnl * while Debian's variant uses . + dnl + CPPFLAGS="$am_save_CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCEDIT]) + + AC_CACHE_CHECK([for libedit], [gl_cv_lib_edit], [ + gl_cv_lib_edit=no + am_save_LIBS="$LIBS" + LIBS="$am_save_LIBS $LIBEDIT" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include +#ifdef HAVE_READLINE_READLINE_H +# include +#elif defined HAVE_EDITLINE_READLINE_H +# include +#endif]], + [[readline((char*)0);]])], + [gl_cv_lib_edit="yes"]) + LIBS="$am_save_LIBS" + ]) + + dnl Is the function readline() located by now? + if test "$gl_cv_lib_readline" != no || + test "$gl_cv_lib_edit" != no; then + AC_DEFINE([HAVE_READLINE], [1], [Define if you have the readline function.]) + fi + + dnl Unravel dependency on implementation. Prefer libreadline + dnl over libedit. if test "$gl_cv_lib_readline" != no; then - AC_DEFINE([HAVE_READLINE], [1], [Define if you have the readline library.]) + AC_DEFINE([HAVE_LIBREADLINE], [1], [Define if you have the readline library.]) extra_lib=`echo "$gl_cv_lib_readline" | sed -n -e 's/yes, requires //p'` if test -n "$extra_lib"; then LIBREADLINE="$LIBREADLINE $extra_lib" @@ -62,17 +102,25 @@ AC_DEFUN([gl_FUNC_READLINE], fi AC_MSG_CHECKING([how to link with libreadline]) AC_MSG_RESULT([$LIBREADLINE]) + elif test "$gl_cv_lib_edit" != no; then + AC_DEFINE([HAVE_LIBEDIT], [1], [Define if you have the edit library.]) + + dnl We have a working replacement for libreadline, so use it. + LIBREADLINE="$LIBEDIT" + LTLIBREADLINE="$LTLIBEDIT" + AC_MSG_CHECKING([how to link with libedit]) + AC_MSG_RESULT([$LIBEDIT]) else dnl If $LIBREADLINE didn't lead to a usable library, we don't dnl need $INCREADLINE either. CPPFLAGS="$am_save_CPPFLAGS" LIBREADLINE= LTLIBREADLINE= + LIBEDIT= + LTLIBEDIT= fi AC_SUBST([LIBREADLINE]) AC_SUBST([LTLIBREADLINE]) - - AC_CHECK_HEADERS([readline/readline.h readline/history.h]) ]) # Prerequisites of lib/readline.c. diff --git a/modules/readline b/modules/readline index 9cee3bb..a334c43 100644 --- a/modules/readline +++ b/modules/readline @@ -8,11 +8,11 @@ m4/readline.m4 Depends-on: havelib -getline [test "$gl_cv_lib_readline" = no] +getline [test "$gl_cv_lib_readline" = no && test "$gl_cv_lib_edit" = no] configure.ac: gl_FUNC_READLINE -if test "$gl_cv_lib_readline" = no; then +if test "$gl_cv_lib_readline" = no && test "$gl_cv_lib_edit" = no; then AC_LIBOBJ([readline]) gl_PREREQ_READLINE fi -- 1.7.10.4