Portability to BSD/OS 4.2.
[gnulib.git] / m4 / readline.m4
1 # readline.m4 serial 4
2 dnl Copyright (C) 2005, 2006 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     dnl On some systems, -lreadline doesn't link without an additional
33     dnl -lncurses or -ltermcap.
34     dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
35     dnl by design and obsolete since 1994. Try -lcurses last, because
36     dnl libcurses is unusable on some old Unices.
37     for extra_lib in "" ncurses termcap curses; do
38       LIBS="$am_save_LIBS $LIBREADLINE"
39       if test -n "$extra_lib"; then
40         LIBS="$LIBS -l$extra_lib"
41       fi
42       AC_TRY_LINK([#include <stdio.h>
43 #include <readline/readline.h>],
44         [readline((char*)0);],
45         [gl_cv_lib_readline=" -l$extra_lib"])
46       if test "$gl_cv_lib_readline" != no; then
47         break
48       fi
49     done
50     LIBS="$am_save_LIBS"
51   ])
52
53   if test "$gl_cv_lib_readline" != no; then
54     AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
55     if test "$gl_cv_lib_readline" != " -l"; then
56       LIBREADLINE="$LIBREADLINE$gl_cv_lib_readline"
57       LTLIBREADLINE="$LTLIBREADLINE$gl_cv_lib_readline"
58     fi
59     AC_MSG_CHECKING([how to link with libreadline])
60     AC_MSG_RESULT([$LIBREADLINE])
61   else
62     dnl If $LIBREADLINE didn't lead to a usable library, we don't
63     dnl need $INCREADLINE either.
64     CPPFLAGS="$am_save_CPPFLAGS"
65     LIBREADLINE=
66     LTLIBREADLINE=
67   fi
68   AC_SUBST(LIBREADLINE)
69   AC_SUBST(LTLIBREADLINE)
70
71   AC_CHECK_HEADERS(readline/readline.h)
72
73   if test $gl_cv_lib_readline = no; then
74     AC_LIBOBJ(readline)
75     gl_PREREQ_READLINE
76   fi
77 ])
78
79 # Prerequisites of lib/readline.c.
80 AC_DEFUN([gl_PREREQ_READLINE], [
81   :
82 ])