2 dnl Copyright (C) 2005-2006, 2009-2011 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 [if test -n "$extra_lib"; then
44 gl_cv_lib_readline="yes, requires -l$extra_lib"
46 gl_cv_lib_readline="yes"
49 if test "$gl_cv_lib_readline" != no; then
56 if test "$gl_cv_lib_readline" != no; then
57 AC_DEFINE([HAVE_READLINE], [1], [Define if you have the readline library.])
58 extra_lib=`echo "$gl_cv_lib_readline" | sed -n -e 's/yes, requires //p'`
59 if test -n "$extra_lib"; then
60 LIBREADLINE="$LIBREADLINE $extra_lib"
61 LTLIBREADLINE="$LTLIBREADLINE $extra_lib"
63 AC_MSG_CHECKING([how to link with libreadline])
64 AC_MSG_RESULT([$LIBREADLINE])
66 dnl If $LIBREADLINE didn't lead to a usable library, we don't
67 dnl need $INCREADLINE either.
68 CPPFLAGS="$am_save_CPPFLAGS"
72 AC_SUBST([LIBREADLINE])
73 AC_SUBST([LTLIBREADLINE])
75 AC_CHECK_HEADERS([readline/readline.h])
78 # Prerequisites of lib/readline.c.
79 AC_DEFUN([gl_PREREQ_READLINE], [