readline.m4 3.9 KB
Newer Older
Benoit Perrot's avatar
Benoit Perrot committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Check readline presence and usability.		    -*-Autoconf-*-
#
# Copyright (C) 2004 Benoit Perrot
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307  USA

dnl AC_CHECK_READLINE
dnl Check readline libraries and includes usability. If the user gave
dnl the command line options `--with-readline-includes=dir' and 
dnl `--with-readline-library=dir', use those directories. If readline is not
dnl found or cannot be used, or the user gave the command line option 
dnl `--without-readline', set the shell variable no_readline to `yes';
Benoit Perrot's avatar
Benoit Perrot committed
26
27
28
dnl otherwise set it to the empty string. Set the variables READLINE_CPPFLAGS, 
dnl READLINE_LIBS and READLINE_LDFLAGS to their correct content if
dnl readline is found, to the empty string else.
Benoit Perrot's avatar
Benoit Perrot committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

AC_DEFUN([AC_CHECK_READLINE], [

## -- Prologue

# Allow the user to disable readline
AC_ARG_WITH([readline],
            [AC_HELP_STRING([--without-readline],
                            [do not use readline (default is YES)])])

# Let the user precise includes and library paths
AC_ARG_WITH([readline-includes],
            [AC_HELP_STRING([--with-readline-includes=DIR],
                            [use DIR to look for readline includes])],
	    [readline_includes=$withval],
	    [readline_includes=no]
	    )
AC_ARG_WITH([readline-library],
            [AC_HELP_STRING([--with-readline-library=DIR],
                            [use DIR to look for readline library])],
	    [readline_library=$withval],
	    [readline_library=no]
	    )

## -- Engine

# Save current compilation flags to restore them if something goes wrong
Benoit Perrot's avatar
Benoit Perrot committed
56
57
58
ac_cv_saved_CPPFLAGS=$CPPFLAGS
ac_cv_saved_LDFLAGS=$LDFLAGS
ac_cv_saved_LIBS=$LIBS
Benoit Perrot's avatar
Benoit Perrot committed
59

Benoit Perrot's avatar
Benoit Perrot committed
60
61
62
63
# Reset READLINE strings and prepare their substitution
AC_SUBST([READLINE_CPPFLAGS], [""])
AC_SUBST([READLINE_LDFLAGS], [""])
AC_SUBST([READLINE_LIBS], [""])
Benoit Perrot's avatar
Benoit Perrot committed
64

Benoit Perrot's avatar
Benoit Perrot committed
65
66
no_readline="yes"
if test "x$with_readline" != xno; then
Benoit Perrot's avatar
Benoit Perrot committed
67
68

  if test "x$readline_includes" != xno; then
Benoit Perrot's avatar
Benoit Perrot committed
69
70
    READLINE_CPPFLAGS="-I$readline_includes"
    CPPFLAGS="$CPPFLAGS $READLINE_CPPFLAGS"
Benoit Perrot's avatar
Benoit Perrot committed
71
72
73
74
75
76
  fi

  # Check for readline headers
  AC_CHECK_HEADER([readline/readline.h],
    [
      if test "x$readline_library" != xno; then
Benoit Perrot's avatar
Benoit Perrot committed
77
78
	READLINE_LDFLAGS="-L$readline_library"
	LDFLAGS="$LDFLAGS $READLINE_LDFLAGS"
Benoit Perrot's avatar
Benoit Perrot committed
79
80
      fi

Benoit Perrot's avatar
Benoit Perrot committed
81
82
83
84
85
86
87
88
89
      # Search for tgetent function, on which readline may depends
      AC_SEARCH_LIBS([tgetent],
		     [readline termcap curses ncurses],
		     [TERMCAP_LIBS=$ac_cv_search_tgetent])

      READLINE_LIBS="-lreadline"
      if test "$TERMCAP_LIBS" != "-lreadline"; then
	READLINE_LIBS="$READLINE_LIBS $TERMCAP_LIBS"
	# TERMCAP_LIBS was automaticaly added to LIBS by AC_SEARCH_LIBS
Benoit Perrot's avatar
Benoit Perrot committed
90
91
92
      fi

      # Check for readline library presence and usability
Benoit Perrot's avatar
Benoit Perrot committed
93
      AC_CHECK_LIB([readline], [readline], [no_readline=""])
Benoit Perrot's avatar
Benoit Perrot committed
94
95
    ])

Benoit Perrot's avatar
Benoit Perrot committed
96
  ## -- Epilogue
Benoit Perrot's avatar
Benoit Perrot committed
97

Benoit Perrot's avatar
Benoit Perrot committed
98
99
  # Display readline check status
  AC_MSG_CHECKING([for readline])
Benoit Perrot's avatar
Benoit Perrot committed
100

Benoit Perrot's avatar
Benoit Perrot committed
101
102
103
104
105
  if test "$no_readline"; then
    # Restore environment variables
    READLINE_CPPFLAGS=""
    READLINE_LDFLAGS=""
    READLINE_LIBS=""
Benoit Perrot's avatar
Benoit Perrot committed
106

Benoit Perrot's avatar
Benoit Perrot committed
107
108
109
110
111
112
113
114
115
116
117
    AC_MSG_RESULT([no])
  else
    AC_DEFINE([HAVE_LIBREADLINE],
	      [1],
	      [Define to 1 if you have the readline library.])
    AC_DEFINE([HAVE_READLINE_READLINE_H],
	      [1],
	      [Define to 1 if you have the <readline/readline.h> header file.])

    AC_MSG_RESULT([yes])
  fi
Benoit Perrot's avatar
Benoit Perrot committed
118
119
120

fi

Benoit Perrot's avatar
Benoit Perrot committed
121
122
123
CPPFLAGS=$ac_cv_saved_CPPFLAGS
LDFLAGS=$ac_cv_saved_LDFLAGS
LIBS=$ac_cv_saved_LIBS
Benoit Perrot's avatar
Benoit Perrot committed
124
125

])