* readline.m4: Look for termcap, curses or ncurses if required.
[gnulib.git] / m4 / readline.m4
1 # readline.m4 serial 2
2 dnl Copyright (C) 2005 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.
6
7 dnl Written by Simon Josefsson, with help from Bruno Haible and Oskar
8 dnl Liljeblad.
9
10 AC_DEFUN([gl_FUNC_READLINE],
11 [
12   AC_LIBSOURCES([readline.c, readline.h])
13
14   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
15   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
16   AC_REQUIRE([AC_LIB_RPATH])
17
18   dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
19   dnl INCREADLINE accordingly.
20   AC_LIB_LINKFLAGS_BODY([readline])
21
22   dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
23   dnl because if the user has installed libreadline and not disabled its use
24   dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK
25   dnl will then succeed.
26   am_save_CPPFLAGS="$CPPFLAGS"
27   AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE])
28
29   AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
30     gl_cv_lib_readline=no
31     am_save_LIBS="$LIBS"
32     for extra_lib in "" termcap curses ncurses; do
33       LIBS="$am_save_LIBS $LIBREADLINE"
34       if test -n "$extra_lib"; then
35         LIBS="$LIBS -l$extra_lib"
36       fi
37       AC_TRY_LINK([#include <stdio.h>
38 #include <readline/readline.h>],
39         [readline((char*)0);],
40         gl_cv_lib_readline=yes)
41       if test "$gl_cv_lib_readline" = yes; then
42         LIBREADLINE="$LIBREADLINE -l$extra_lib"
43         LTLIBREADLINE="$LTLIBREADLINE -l$extra_lib"
44         break
45       fi
46     done
47     LIBS="$am_save_LIBS"
48   ])
49
50   if test "$gl_cv_lib_readline" = yes; then
51     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
52   fi
53
54   if test "$gl_cv_lib_readline" = yes; then
55     AC_MSG_CHECKING([how to link with libreadline])
56     AC_MSG_RESULT([$LIBREADLINE])
57   else
58     dnl If $LIBREADLINE didn't lead to a usable library, we don't
59     dnl need $INCREADLINE either.
60     CPPFLAGS="$am_save_CPPFLAGS"
61     LIBREADLINE=
62     LTLIBREADLINE=
63   fi
64   AC_SUBST(LIBREADLINE)
65   AC_SUBST(LTLIBREADLINE)
66
67   AC_CHECK_HEADERS(readline/readline.h)
68
69   if test $gl_cv_lib_readline = no; then
70     AC_LIBOBJ(readline)
71     gl_PREREQ_READLINE
72   fi
73 ])
74
75 # Prerequisites of lib/readline.c.
76 AC_DEFUN([gl_PREREQ_READLINE], [
77   :
78 ])