readline.m4 3.55 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
26
27
28
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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';
dnl otherwise set it to the empty string.

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
ac_save_CFLAGS=$CFLAGS
ac_save_LIBS=$LIBS

READLINE_CFLAGS=""
READLINE_LIBS="-lreadline"

if test "x$with_readline" = xno; then
  # The user explicitly disabled readline
  have_readline=disabled
else
  have_readline=no

  if test "x$readline_includes" != xno; then
    READLINE_CFLAGS="-I$readline_includes"
    CFLAGS="$CFLAGS $READLINE_CFLAGS"
  fi

  # Check for readline headers
  AC_CHECK_HEADER([readline/readline.h],
    [
      if test "x$readline_library" != xno; then
	READLINE_LIBS="-L$readline_library $READLINE_LIBS"
      fi

      # Search for libraries on which readline may depends
      # FIXME: might become AC_CHECK_TERMCAP
      AC_CHECK_LIB(termcap, tgetent,
        termcap_library=termcap,
        [
          AC_CHECK_LIB(curses, tgetent,
	    termcap_library=curses,
	    [
              AC_CHECK_LIB(ncurses, tgetent,
                termcap_library=ncurses,
                termcap_library=no)
          ])
        ])
      if test temcap_library != no; then
        READLINE_LIBS="$READLINE_LIBS -l$termcap_library"
      fi
      LIBS="$LIBS $READLINE_LIBS"

      # Check for readline library presence and usability
      AC_CHECK_LIB(readline, readline,
        [have_readline=yes])
    ])
fi


## -- Epilogue

# Display readline check status
AC_MSG_CHECKING([for readline])
AC_MSG_RESULT([$have_readline])

# Set or reset environment variables
no_readline=""
if test "$have_readline" != yes; then
  CFLAGS=$ac_save_CFLAGS
  LIBS=$ac_save_LIBS

  no_readline=yes
fi

# Substitute readline flags
AC_SUBST(READLINE_CFLAGS)
AC_SUBST(READLINE_LIBS)

])