| 1 |
dnl Check for readline and dependencies |
| 2 |
dnl Copyright (C) 2004, 2005, 2013, 2014, 2021, 2024, |
| 3 |
dnl Free Software Foundation, Inc. |
| 4 |
dnl |
| 5 |
dnl This file is free software, distributed under the terms of the GNU |
| 6 |
dnl General Public License. As a special exception to the GNU General |
| 7 |
dnl Public License, this file may be distributed as part of a program |
| 8 |
dnl that contains a configuration script generated by Autoconf, under |
| 9 |
dnl the same distribution terms as the rest of that program. |
| 10 |
dnl |
| 11 |
dnl Defines HAVE_LIBREADLINE to 1 if a working readline setup is |
| 12 |
dnl found, and sets @LIBREADLINE@ to the necessary libraries. |
| 13 |
dnl |
| 14 |
dnl Based upon GNUPG_CHECK_READLINE. Many more years into the |
| 15 |
dnl twenty-first century, it is not enough to link a test program |
| 16 |
dnl with the readline library. On several systems, if readline is |
| 17 |
dnl not linked with the curses / termcap / whatever libraries, the |
| 18 |
dnl problem is only discovered at run time. Isn't that special? |
| 19 |
|
| 20 |
AC_DEFUN([GAWK_CHECK_READLINE], |
| 21 |
[ |
| 22 |
AC_ARG_WITH([readline], |
| 23 |
AS_HELP_STRING([--with-readline=DIR], |
| 24 |
[look for the readline library in DIR]), |
| 25 |
[_do_readline=$withval],[_do_readline=yes]) |
| 26 |
|
| 27 |
if test "$_do_readline" != "no" ; then |
| 28 |
if test -d "$withval" ; then |
| 29 |
CPPFLAGS="${CPPFLAGS} -I$withval/include" |
| 30 |
LDFLAGS="${LDFLAGS} -L$withval/lib" |
| 31 |
fi |
| 32 |
|
| 33 |
for _termcap in "" "-ltermcap" "-lcurses" "-lncurses" ; do |
| 34 |
_readline_save_libs=$LIBS |
| 35 |
_combo="-lreadline${_termcap:+ $_termcap}" |
| 36 |
LIBS="$LIBS $_combo" |
| 37 |
|
| 38 |
AC_MSG_CHECKING([whether readline via "$_combo" is present and sane]) |
| 39 |
|
| 40 |
AC_RUN_IFELSE( |
| 41 |
dnl source program: |
| 42 |
[AC_LANG_SOURCE([[#include <stdio.h> |
| 43 |
#include <fcntl.h> |
| 44 |
#include <unistd.h> |
| 45 |
#include <readline/readline.h> |
| 46 |
#include <readline/history.h> |
| 47 |
|
| 48 |
int main(int argc, char **argv) |
| 49 |
{ |
| 50 |
int fd; |
| 51 |
char *line; |
| 52 |
|
| 53 |
close(0); |
| 54 |
close(1); |
| 55 |
fd = open("/dev/null", 2); /* should get fd 0 */ |
| 56 |
dup(fd); |
| 57 |
line = readline("giveittome> "); |
| 58 |
|
| 59 |
/* some printfs don't handle NULL for %s */ |
| 60 |
printf("got <%s>\n", line ? line : "(NULL)"); |
| 61 |
return 0; |
| 62 |
}]])], |
| 63 |
dnl action if true: |
| 64 |
[_found_readline=yes], |
| 65 |
dnl action if false: |
| 66 |
[_found_readline=no], |
| 67 |
dnl action if cross compiling: |
| 68 |
[AC_LINK_IFELSE( |
| 69 |
[AC_LANG_PROGRAM([[#include <stdio.h> |
| 70 |
#include <fcntl.h> |
| 71 |
#include <unistd.h> |
| 72 |
#include <readline/readline.h> |
| 73 |
#include <readline/history.h>]], dnl includes |
| 74 |
dnl function body |
| 75 |
[[ |
| 76 |
int fd; |
| 77 |
char *line; |
| 78 |
|
| 79 |
close(0); |
| 80 |
close(1); |
| 81 |
fd = open("/dev/null", 2); /* should get fd 0 */ |
| 82 |
dup(fd); |
| 83 |
line = readline("giveittome> "); |
| 84 |
|
| 85 |
/* some printfs don't handle NULL for %s */ |
| 86 |
printf("got <%s>\n", line ? line : "(NULL)"); |
| 87 |
]])], |
| 88 |
dnl action if found: |
| 89 |
[_found_readline=yes], |
| 90 |
dnl action if not found: |
| 91 |
[_found_readline=no] |
| 92 |
)] |
| 93 |
) |
| 94 |
|
| 95 |
AC_MSG_RESULT([$_found_readline]) |
| 96 |
|
| 97 |
LIBS=$_readline_save_libs |
| 98 |
|
| 99 |
if test $_found_readline = yes ; then |
| 100 |
case $host_os in |
| 101 |
*bsd* ) AC_CHECK_LIB(termcap, tgetent, _combo="$_combo -ltermcap") |
| 102 |
;; |
| 103 |
esac |
| 104 |
AC_DEFINE(HAVE_LIBREADLINE,1, |
| 105 |
[Define to 1 if you have a fully functional readline library.]) |
| 106 |
AC_SUBST(LIBREADLINE,$_combo) |
| 107 |
|
| 108 |
AC_CHECK_LIB(readline, history_list, |
| 109 |
[AC_DEFINE(HAVE_HISTORY_LIST, 1, [Do we have history_list?])], |
| 110 |
[], |
| 111 |
[$_combo]) |
| 112 |
|
| 113 |
break |
| 114 |
fi |
| 115 |
done |
| 116 |
|
| 117 |
unset _termcap |
| 118 |
unset _readline_save_libs |
| 119 |
unset _combo |
| 120 |
unset _found_readline |
| 121 |
fi |
| 122 |
])dnl |