Dear all, I would like to propose a modification to the M4 file for the module `readline', which provides a functional detection also for NetBSD. The main obstacle is that NetBSD uses the library `editline', and offer readline functionality as a wrapper based on said library. The present state of the Gnulib module is not able to detect this properly.
We have been using a somewhat similar local script in GNU Inetutils, successfully since four months, but I still had to introduce changes in order to cope with caching issues. I found that AC_CACHE_CHECK must be performed prior to AC_LIB_LINKFLAGS_BODY, since `-lreadline' is no longer the basis. Also, the string `, requires ...' must be removed to avoid duplicates; removed once applied, that is. (Visible in OpenBSD.) There ought to be more room for better caching, but this is a functional starter. It behaves correctly for GNU/Linux with and without `<readline/readline.h>'. Best regards, Mats Erik Andersson, for GNU Inetutils diff --git a/m4/readline.m4 b/m4/readline.m4 index 903886d..e2c12cc 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-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,18 +13,18 @@ AC_DEFUN([gl_FUNC_READLINE], AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) - dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and - dnl INCREADLINE accordingly. - AC_LIB_LINKFLAGS_BODY([readline]) + AC_CACHE_CHECK([for readline], [gl_cv_lib_readline], [ + dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and + dnl INCREADLINE accordingly. + AC_LIB_LINKFLAGS_BODY([readline]) - 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 - dnl will then succeed. - am_save_CPPFLAGS="$CPPFLAGS" - AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE]) + 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 + dnl will then succeed. + am_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE]) - AC_CACHE_CHECK([for readline], [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,12 +53,31 @@ AC_DEFUN([gl_FUNC_READLINE], LIBS="$am_save_LIBS" ]) + dnl In case of failure, examine whether libedit can act + dnl as replacement. Small NetBSD systems use editline + dnl as wrapper for readline. + if test "$gl_cv_lib_readline" = no; then + am_save_LIBS="$LIBS" + LIBS="$am_save_LIBS -ledit -ltermcap" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> +#include <readline/readline.h>]], + [[readline((char*)0);]])], + [gl_cv_lib_readline="yes"]) + LIBS="$am_save_LIBS" + dnl This wrapper does not reference libreadline at all. + dnl Set the correct linking according to editline(3). + LIBREADLINE='-ledit -ltermcap' + LTLIBREADLINE='-ledit -ltermcap' + fi + if test "$gl_cv_lib_readline" != no; then AC_DEFINE([HAVE_READLINE], [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" LTLIBREADLINE="$LTLIBREADLINE $extra_lib" + # Prevent duplicates next time around. + gl_cv_lib_readline=`echo "$gl_cv_lib_readline" | sed -e 's/\(yes\).*/\1/'` fi AC_MSG_CHECKING([how to link with libreadline]) AC_MSG_RESULT([$LIBREADLINE])