2 dnl Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Written by Simon Josefsson, with help from Bruno Haible and Oskar
10 AC_DEFUN([gl_FUNC_READLINE],
12 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
13 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
14 AC_REQUIRE([AC_LIB_RPATH])
16 dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
17 dnl INCREADLINE accordingly.
18 AC_LIB_LINKFLAGS_BODY([readline])
20 dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
21 dnl because if the user has installed libreadline and not disabled its use
22 dnl via --without-libreadline-prefix, he wants to use it. The AC_LINK_IFELSE
23 dnl will then succeed.
24 am_save_CPPFLAGS="$CPPFLAGS"
25 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE])
27 AC_CACHE_CHECK([for readline], [gl_cv_lib_readline], [
30 dnl On some systems, -lreadline doesn't link without an additional
31 dnl -lncurses or -ltermcap.
32 dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
33 dnl by design and obsolete since 1994. Try -lcurses last, because
34 dnl libcurses is unusable on some old Unices.
35 for extra_lib in "" ncurses termcap curses; do
36 LIBS="$am_save_LIBS $LIBREADLINE"
37 if test -n "$extra_lib"; then
38 LIBS="$LIBS -l$extra_lib"
40 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
41 #include <readline/readline.h>]],
42 [[readline((char*)0);]])],
43 [gl_cv_lib_readline=" -l$extra_lib"])
44 if test "$gl_cv_lib_readline" != no; then
51 if test "$gl_cv_lib_readline" != no; then
52 AC_DEFINE([HAVE_READLINE], [1], [Define if you have the readline library.])
53 if test "$gl_cv_lib_readline" != " -l"; then
54 LIBREADLINE="$LIBREADLINE$gl_cv_lib_readline"
55 LTLIBREADLINE="$LTLIBREADLINE$gl_cv_lib_readline"
57 AC_MSG_CHECKING([how to link with libreadline])
58 AC_MSG_RESULT([$LIBREADLINE])
60 dnl If $LIBREADLINE didn't lead to a usable library, we don't
61 dnl need $INCREADLINE either.
62 CPPFLAGS="$am_save_CPPFLAGS"
66 AC_SUBST([LIBREADLINE])
67 AC_SUBST([LTLIBREADLINE])
69 AC_CHECK_HEADERS([readline/readline.h])
71 if test $gl_cv_lib_readline = no; then
77 # Prerequisites of lib/readline.c.
78 AC_DEFUN([gl_PREREQ_READLINE], [