Merge pull request #457 from vivien/text-variable
[tig.git] / tools / ax_lib_readline.m4
blobd40d4ca78a74f5d2aec312266050b36a3ddc06e1
1 dnl Copyright (C) 1987-2014 Free Software Foundation, Inc.
2 dnl
3 dnl This program is free software: you can redistribute it and/or modify
4 dnl it under the terms of the GNU General Public License as published by
5 dnl the Free Software Foundation, either version 3 of the License, or
6 dnl (at your option) any later version.
7 dnl
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 dnl GNU General Public License for more details.
12 dnl
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 dnl
16 dnl Taken from http://git.savannah.gnu.org/cgit/readline.git/tree/examples/autoconf/
17 dnl commit 835a39225c6bd4784c0d7f775b0cd44dd7c57f35 (Readline 6.3, version 2.73)
18 dnl
19 dnl Configuration of --with-readline and result check at EOF.
21 AC_DEFUN([BASH_CHECK_LIB_TERMCAP],
23 # save cpp and ld options
24 _save_CFLAGS="$CFLAGS"
25 _save_LDFLAGS="$LDFLAGS"
26 _save_LIBS="$LIBS"
28 if test "X$bash_cv_termcap_lib" = "X"; then
29 _bash_needmsg=yes
30 else
31 AC_MSG_CHECKING(which library has the termcap functions)
32 _bash_needmsg=
34 AC_CACHE_VAL(bash_cv_termcap_lib,
35 [AC_CHECK_FUNC(tgetent, bash_cv_termcap_lib=libc,
36   [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap,
37     [AC_CHECK_LIB(tinfo, tgetent, bash_cv_termcap_lib=libtinfo,
38         bash_cv_termcap_lib=gnutermcap
39 if test "$ax_cv_curses_which" = "ncursesw"; then
40         [AC_CHECK_LIB(ncursesw, tgetent, bash_cv_termcap_lib=libncursesw)]
41 elif test "$ax_cv_curses_which" = "ncurses"; then
42         [AC_CHECK_LIB(ncurses, tgetent, bash_cv_termcap_lib=libncurses)]
43 elif test "$ax_cv_curses_which" = "plaincurses"; then
44         [AC_CHECK_LIB(curses, tgetent, bash_cv_termcap_lib=libcurses)]
46 )])])])
47 if test "X$_bash_needmsg" = "Xyes"; then
48 AC_MSG_CHECKING(which library has the termcap functions)
50 AC_MSG_RESULT(using $bash_cv_termcap_lib)
51 if test $bash_cv_termcap_lib = gnutermcap && test -z "$prefer_curses"; then
52 LDFLAGS="$LDFLAGS -L./lib/termcap"
53 TERMCAP_LIB="./lib/termcap/libtermcap.a"
54 TERMCAP_DEP="./lib/termcap/libtermcap.a"
55 elif test $bash_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then
56 TERMCAP_LIB=-ltermcap
57 TERMCAP_DEP=
58 elif test $bash_cv_termcap_lib = libtinfo; then
59 TERMCAP_LIB=-ltinfo
60 TERMCAP_DEP=
61 elif test $bash_cv_termcap_lib = libncursesw; then
62 TERMCAP_LIB=-lncursesw
63 TERMCAP_DEP=
64 elif test $bash_cv_termcap_lib = libncurses; then
65 TERMCAP_LIB=-lncurses
66 TERMCAP_DEP=
67 elif test $bash_cv_termcap_lib = libc; then
68 TERMCAP_LIB=
69 TERMCAP_DEP=
70 else
71 TERMCAP_LIB=-lcurses
72 TERMCAP_DEP=
75 CFLAGS="$_save_CFLAGS"
76 LDFLAGS="$_save_LDFLAGS"
77 LIBS="$_save_LIBS"
80 AC_DEFUN([RL_LIB_READLINE_VERSION],
82 AC_REQUIRE([BASH_CHECK_LIB_TERMCAP])
84 AC_MSG_CHECKING([version of installed readline library])
86 # What a pain in the ass this is.
88 # save cpp and ld options
89 _save_CFLAGS="$CFLAGS"
90 _save_LDFLAGS="$LDFLAGS"
91 _save_LIBS="$LIBS"
93 # Don't set ac_cv_rl_prefix if the caller has already assigned a value.  This
94 # allows the caller to do something like $_rl_prefix=$withval if the user
95 # specifies --with-installed-readline=PREFIX as an argument to configure
97 if test -z "$ac_cv_rl_prefix"; then
98 test "x$prefix" = xNONE && ac_cv_rl_prefix=$ac_default_prefix || ac_cv_rl_prefix=${prefix}
101 eval ac_cv_rl_includedir=${ac_cv_rl_prefix}/include
102 eval ac_cv_rl_libdir=${ac_cv_rl_prefix}/lib
104 LIBS="$LIBS -lreadline ${TERMCAP_LIB}"
105 CFLAGS="$CFLAGS -I${ac_cv_rl_includedir}"
106 LDFLAGS="$LDFLAGS -L${ac_cv_rl_libdir}"
108 AC_CACHE_VAL(ac_cv_rl_version,
109 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
110 #include <stdio.h>
111 #include <readline/readline.h>
113 extern int rl_gnu_readline_p;
115 main()
117         FILE *fp;
118         fp = fopen("conftest.rlv", "w");
119         if (fp == 0)
120                 exit(1);
121         if (rl_gnu_readline_p != 1)
122                 fprintf(fp, "0.0\n");
123         else
124                 fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0");
125         fclose(fp);
126         exit(0);
128 ]])],
129 ac_cv_rl_version=`cat conftest.rlv`,
130 ac_cv_rl_version='0.0',
131 ac_cv_rl_version='4.2')])
133 CFLAGS="$_save_CFLAGS"
134 LDFLAGS="$_save_LDFLAGS"
135 LIBS="$_save_LIBS"
137 RL_MAJOR=0
138 RL_MINOR=0
140 # (
141 case "$ac_cv_rl_version" in
142 2*|3*|4*|5*|6*|7*|8*|9*)
143         RL_MAJOR=`echo $ac_cv_rl_version | sed 's:\..*$::'`
144         RL_MINOR=`echo $ac_cv_rl_version | sed -e 's:^.*\.::' -e 's:[[a-zA-Z]]*$::'`
145         ;;
146 esac
148 # (((
149 case $RL_MAJOR in
150 [[0-9][0-9]])   _RL_MAJOR=$RL_MAJOR ;;
151 [[0-9]])        _RL_MAJOR=0$RL_MAJOR ;;
152 *)              _RL_MAJOR=00 ;;
153 esac
155 # (((
156 case $RL_MINOR in
157 [[0-9][0-9]])   _RL_MINOR=$RL_MINOR ;;
158 [[0-9]])        _RL_MINOR=0$RL_MINOR ;;
159 *)              _RL_MINOR=00 ;;
160 esac
162 RL_VERSION="0x${_RL_MAJOR}${_RL_MINOR}"
164 # Readline versions greater than 4.2 have these defines in readline.h
166 if test $ac_cv_rl_version = '0.0' ; then
167         AC_MSG_RESULT([none])
168         AC_MSG_WARN([Could not test version of installed readline library.])
169 elif test $RL_MAJOR -gt 4 || { test $RL_MAJOR = 4 && test $RL_MINOR -gt 2 ; } ; then
170         # set these for use by the caller
171         RL_PREFIX=$ac_cv_rl_prefix
172         RL_LIBDIR=$ac_cv_rl_libdir
173         RL_INCLUDEDIR=$ac_cv_rl_includedir
174         AC_MSG_RESULT($ac_cv_rl_version)
175 else
177 AC_DEFINE_UNQUOTED(RL_READLINE_VERSION, $RL_VERSION, [encoded version of the installed readline library])
178 AC_DEFINE_UNQUOTED(RL_VERSION_MAJOR, $RL_MAJOR, [major version of installed readline library])
179 AC_DEFINE_UNQUOTED(RL_VERSION_MINOR, $RL_MINOR, [minor version of installed readline library])
181 AC_SUBST(RL_VERSION)
182 AC_SUBST(RL_MAJOR)
183 AC_SUBST(RL_MINOR)
185 # set these for use by the caller
186 RL_PREFIX=$ac_cv_rl_prefix
187 RL_LIBDIR=$ac_cv_rl_libdir
188 RL_INCLUDEDIR=$ac_cv_rl_includedir
190 AC_MSG_RESULT($ac_cv_rl_version)
195 AC_DEFUN([AX_LIB_READLINE], [
196   RL_VERSION_REQUIRED="$1"
197   RL_MAJOR_REQUIRED="$(echo "$1" | sed -n 's/\([[]0-9[]]*\)[[].[]]\([[]0-9[]]*\)/\1/p')"
198   RL_MINOR_REQUIRED="$(echo "$1" | sed -n 's/\([[]0-9[]]*\)[[].[]]\([[]0-9[]]*\)/\2/p')"
199   RL_MAJOR=0
200   RL_MINOR=0
202   AC_ARG_WITH([readline], [AS_HELP_STRING([--with-readline=DIR],
203         [search for readline in DIR/include and DIR/lib])],
204         [ac_cv_rl_prefix=$with_readline])
206   AC_CHECK_HEADERS([readline/readline.h], [
207     AC_CHECK_HEADERS([readline/history.h], [
208       RL_LIB_READLINE_VERSION
209     ])
210   ])
212   if test $RL_MAJOR -ge $RL_MAJOR_REQUIRED || {
213      test $RL_MAJOR = $RL_MAJOR_REQUIRED && test $RL_MINOR -ge $RL_MINOR_REQUIRED ; } ; then
214     LIBS="$LIBS -lreadline ${TERMCAP_LIB}"
215     CFLAGS="$CFLAGS -I${RL_INCLUDEDIR}"
216     LDFLAGS="$LDFLAGS -L${RL_LIBDIR}"
218     AC_DEFINE(HAVE_READLINE, 1, [Define if you have a GNU readline compatible library])
220   elif test -n "$ac_cv_rl_prefix"; then
221     AC_MSG_WARN([Minimum required version of readline is $RL_VERSION_REQUIRED])
222   fi