1 dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc.
2 dnl This file is free software; the Free Software Foundation
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
6 dnl Check for readline and history libraries.
8 dnl Modified for PSPP by Ben Pfaff, based on readline.m4 serial 3 from
9 dnl gnulib, which was written by Simon Josefsson, with help from Bruno
10 dnl Haible and Oskar Liljeblad.
12 AC_DEFUN([PSPP_READLINE],
14 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
15 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
16 AC_REQUIRE([AC_LIB_RPATH])
18 dnl Search for libreadline and define LIBREADLINE, LTLIBREADLINE and
19 dnl INCREADLINE accordingly.
20 AC_LIB_LINKFLAGS_BODY([readline])
21 AC_LIB_LINKFLAGS_BODY([history])
23 dnl Add $INCREADLINE to CPPFLAGS before performing the following checks,
24 dnl because if the user has installed libreadline and not disabled its use
25 dnl via --without-libreadline-prefix, he wants to use it. The AC_TRY_LINK
26 dnl will then succeed.
27 am_save_CPPFLAGS="$CPPFLAGS"
28 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCREADLINE $INCHISTORY])
30 AC_CACHE_CHECK(for readline, gl_cv_lib_readline, [
33 dnl On some systems, -lreadline doesn't link without an additional
34 dnl -lncurses or -ltermcap.
35 dnl Try -lncurses before -ltermcap, because libtermcap is unsecure
36 dnl by design and obsolete since 1994. Try -lcurses last, because
37 dnl libcurses is unusable on some old Unices.
38 for extra_lib in "" ncurses termcap curses; do
39 LIBS="$am_save_LIBS $LIBREADLINE $LIBHISTORY"
40 if test -n "$extra_lib"; then
41 LIBS="$LIBS -l$extra_lib"
43 AC_TRY_LINK([#include <stdio.h>
44 #include <readline/readline.h>
45 #include <readline/history.h>],
46 [readline((char*)0); add_history((char*)0);],
47 gl_cv_lib_readline=yes)
48 if test "$gl_cv_lib_readline" = yes; then
49 if test -n "$extra_lib"; then
50 LIBREADLINE="$LIBREADLINE $LIBHISTORY -l$extra_lib"
51 LTLIBREADLINE="$LTLIBREADLINE $LTLIBHISTORY -l$extra_lib"
59 if test "$gl_cv_lib_readline" = yes; then
60 AC_DEFINE(HAVE_READLINE, 1, [Define if you have the readline library.])
63 if test "$gl_cv_lib_readline" = yes; then
64 AC_MSG_CHECKING([how to link with libreadline])
65 AC_MSG_RESULT([$LIBREADLINE])
67 dnl If $LIBREADLINE didn't lead to a usable library, we don't
68 dnl need $INCREADLINE either.
69 CPPFLAGS="$am_save_CPPFLAGS"
76 AC_SUBST(LTLIBREADLINE)
79 dnl aclocal.m4 ends here