Readline fix to be robust against platforms where readline has its own
authorDavid Shaw <dshaw@jabberwocky.com>
Sat, 18 Dec 2004 22:23:49 +0000 (22:23 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Sat, 18 Dec 2004 22:23:49 +0000 (22:23 +0000)
dependencies.  We play guess-the-depedency for a while, and try termcap,
curses, and ncurses.

g10/ChangeLog
g10/Makefile.am
g10/signal.c
m4/ChangeLog
m4/readline.m4 [new file with mode: 0644]
tools/ChangeLog
tools/Makefile.am
util/ChangeLog
util/ttyio.c

index a6b092b..1e0b08a 100644 (file)
@@ -1,3 +1,10 @@
+2004-12-18  David Shaw  <dshaw@jabberwocky.com>
+
+       * signal.c: Use only HAVE_LIBREADLINE to detect readline
+       availability.
+
+       * Makefile.am: Link with readline where necessary.
+
 2004-12-17  Werner Koch  <wk@g10code.com>
 
        * passphrase.c (agent_get_passphrase): Define NREAD locally as
index a3f2ff6..3e7e0e1 100644 (file)
@@ -132,7 +132,7 @@ gpgv_SOURCES = gpgv.c           \
 #             ks-db.h \
 #             $(common_source)
 
-LDADD =  $(needed_libs) $(other_libs) @ZLIBS@ @W32LIBS@
+LDADD =  $(needed_libs) $(other_libs) @ZLIBS@ @W32LIBS@ @LIBREADLINE@
 gpg_LDADD = $(LDADD) @DLLIBS@ @NETLIBS@ @LIBUSB_LIBS@
 
 $(PROGRAMS): $(needed_libs)
index 0f904ed..7f91070 100644 (file)
@@ -27,7 +27,7 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
-#ifdef HAVE_READLINE_READLINE_H
+#ifdef HAVE_LIBREADLINE
 #include <readline/readline.h>
 #include <readline/history.h>
 #endif
@@ -83,7 +83,7 @@ got_fatal_signal( int sig )
 
     secmem_term();
 
-#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE)
+#ifdef HAVE_LIBREADLINE
     rl_free_line_state ();
     rl_cleanup_after_signal ();
 #endif
index ef3e43c..9095322 100644 (file)
@@ -1,3 +1,7 @@
+2004-12-18  David Shaw  <dshaw@jabberwocky.com>
+
+       * readline.m4: New.
+
 2004-07-27  gettextize  <bug-gnu-gettext@gnu.org>
 
        * gettext.m4: Upgrade to gettext-0.14.1.
diff --git a/m4/readline.m4 b/m4/readline.m4
new file mode 100644 (file)
index 0000000..ba55b66
--- /dev/null
@@ -0,0 +1,56 @@
+dnl Check for readline and dependencies
+dnl Copyright (C) 2004 Free Software Foundation, Inc.
+dnl
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License.  As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+dnl
+dnl Defines HAVE_LIBREADLINE to 1 if a working readline setup is
+dnl found, and sets @LIBREADLINE@ to the necessary libraries.
+
+AC_DEFUN([GNUPG_CHECK_READLINE],
+[
+  AC_ARG_WITH(readline,
+     AC_HELP_STRING([--with-readline=DIR],
+       [look for the readline library in DIR]),
+     [_do_readline=$withval],[_do_readline=yes])
+
+  if test "$_do_readline" != "no" ; then
+     if test -d "$withval" ; then
+        CPPFLAGS="${CPPFLAGS} -I$withval/include"
+        LDFLAGS="${LDFLAGS} -L$withval/lib"
+     fi
+
+     for _termcap in "" "-ltermcap" "-lcurses" "-lncurses" ; do
+        _readline_save_libs=$LIBS
+        _combo="-lreadline${_termcap:+ $_termcap}"
+        LIBS="$LIBS $_combo"
+
+        AC_MSG_CHECKING([whether readline via \"$_combo\" is present and sane])
+
+        AC_LINK_IFELSE(AC_LANG_PROGRAM([
+#include <stdio.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+],[add_history("foobar");]),_found_readline=yes,_found_readline=no)
+
+        AC_MSG_RESULT([$_found_readline])
+
+        LIBS=$_readline_save_libs
+
+        if test $_found_readline = yes ; then
+           AC_DEFINE(HAVE_LIBREADLINE,1,
+             [Define to 1 if you have a fully functional readline library.])
+           AC_SUBST(LIBREADLINE,$_combo)
+           break
+        fi
+     done
+
+     unset _termcap
+     unset _readline_save_libs
+     unset _combo
+     unset _found_readline
+  fi
+])dnl
index 186ac9a..3d56d7b 100644 (file)
@@ -1,3 +1,7 @@
+2004-12-18  David Shaw  <dshaw@jabberwocky.com>
+
+       * Makefile.am: Link with readline where needed.
+
 2004-10-28  Werner Koch  <wk@g10code.com>
 
        * Makefile.am (other_libs): New.  Also include LIBICONV.  Noted by
index 4cb7e74..4292981 100644 (file)
@@ -1,4 +1,5 @@
-# Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1998, 1999, 2000, 2001, 2003,
+#               2004  Free Software Foundation, Inc.
 #
 # This file is part of GnuPG.
 #
@@ -28,7 +29,7 @@ noinst_PROGRAMS = mpicalc bftest clean-sat mk-tdata shmtest
 
 gpgsplit_LDADD  = $(needed_libs) $(other_libs) @ZLIBS@
 mpicalc_LDADD   = $(needed_libs) $(other_libs) @W32LIBS@
-bftest_LDADD    = $(needed_libs) $(other_libs) @W32LIBS@ @DLLIBS@ @NETLIBS@
-shmtest_LDADD   = $(needed_libs) $(other_libs)
+bftest_LDADD    = $(needed_libs) $(other_libs) @W32LIBS@ @DLLIBS@ @NETLIBS@ @LIBREADLINE@
+shmtest_LDADD   = $(needed_libs) $(other_libs) @LIBREADLINE@
 
 gpgsplit mpicalc bftest shmtest: $(needed_libs)
index c4a2315..6784de7 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-18  David Shaw  <dshaw@jabberwocky.com>
+
+       * ttyio.c: Use only HAVE_LIBREADLINE to detect readline
+       availability.
+
 2004-12-16  David Shaw  <dshaw@jabberwocky.com>
 
        * srv.h: Don't include arpa/nameser.h unless we have it.  Include
index f5b761f..b7dd471 100644 (file)
@@ -46,7 +46,7 @@
 #endif
 #include <errno.h>
 #include <ctype.h>
-#ifdef HAVE_READLINE_READLINE_H
+#ifdef HAVE_LIBREADLINE
 #include <readline/readline.h>
 #include <readline/history.h>
 #endif
@@ -162,7 +162,7 @@ init_ttyfp(void)
                   tty_get_ttyname (), strerror(errno) );
        exit(2);
     }
-#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE)
+#ifdef HAVE_LIBREADLINE
     rl_catch_signals = 0;
     rl_instream = rl_outstream = ttyfp;
 #endif
@@ -512,7 +512,7 @@ do_get( const char *prompt, int hidden )
 char *
 tty_get( const char *prompt )
 {
-#if defined(HAVE_READLINE_READLINE_H) && defined(HAVE_LIBREADLINE)
+#ifdef HAVE_LIBREADLINE
     if (!batchmode && !no_terminal) {
       char *line;
       char *buf;
@@ -544,7 +544,7 @@ tty_get( const char *prompt )
       return buf;
     }
     else
-#endif /* HAVE_READLINE_READLINE_H && HAVE_LIBREADLINE */
+#endif /* HAVE_LIBREADLINE */
       return do_get( prompt, 0 );
 }