Blame m4/readline.m4

Packit 575503
dnl Check for readline and dependencies
Packit 575503
dnl Copyright (C) 2004, 2005, 2013, 2014 Free Software Foundation, Inc.
Packit 575503
dnl
Packit 575503
dnl This file is free software, distributed under the terms of the GNU
Packit 575503
dnl General Public License.  As a special exception to the GNU General
Packit 575503
dnl Public License, this file may be distributed as part of a program
Packit 575503
dnl that contains a configuration script generated by Autoconf, under
Packit 575503
dnl the same distribution terms as the rest of that program.
Packit 575503
dnl
Packit 575503
dnl Defines HAVE_LIBREADLINE to 1 if a working readline setup is
Packit 575503
dnl found, and sets @LIBREADLINE@ to the necessary libraries.
Packit 575503
dnl
Packit 575503
dnl Based upon GNUPG_CHECK_READLINE.  Many more years into the
Packit 575503
dnl twenty-first century, it is not enough to link a test program
Packit 575503
dnl with the readline library. On several systems, if readline is
Packit 575503
dnl not linked with the curses / termcap / whatever libraries, the
Packit 575503
dnl problem is only discovered at run time.  Isn't that special?
Packit 575503
Packit 575503
AC_DEFUN([GAWK_CHECK_READLINE],
Packit 575503
[
Packit 575503
  AC_ARG_WITH([readline],
Packit 575503
     AC_HELP_STRING([--with-readline=DIR],
Packit 575503
	[look for the readline library in DIR]),
Packit 575503
     [_do_readline=$withval],[_do_readline=yes])
Packit 575503
Packit 575503
  if test "$_do_readline" != "no" ; then
Packit 575503
     if test -d "$withval" ; then
Packit 575503
        CPPFLAGS="${CPPFLAGS} -I$withval/include"
Packit 575503
        LDFLAGS="${LDFLAGS} -L$withval/lib"
Packit 575503
     fi
Packit 575503
Packit 575503
     for _termcap in "" "-ltermcap" "-lcurses" "-lncurses" ; do
Packit 575503
        _readline_save_libs=$LIBS
Packit 575503
        _combo="-lreadline${_termcap:+ $_termcap}"
Packit 575503
        LIBS="$LIBS $_combo"
Packit 575503
Packit 575503
        AC_MSG_CHECKING([whether readline via \"$_combo\" is present and sane])
Packit 575503
Packit 575503
	AC_TRY_RUN(
Packit 575503
dnl source program:
Packit 575503
AC_LANG_SOURCE([[#include <stdio.h>
Packit 575503
#include <readline/readline.h>
Packit 575503
#include <readline/history.h>
Packit 575503
Packit 575503
int main(int argc, char **argv)
Packit 575503
{
Packit 575503
	int fd;
Packit 575503
	char *line;
Packit 575503
Packit 575503
	close(0);
Packit 575503
	close(1);
Packit 575503
	fd = open("/dev/null", 2);	/* should get fd 0 */
Packit 575503
	dup(fd);
Packit 575503
	line = readline("giveittome> ");
Packit 575503
Packit 575503
	/* some printfs don't handle NULL for %s */
Packit 575503
	printf("got <%s>\n", line ? line : "(NULL)");
Packit 575503
	return 0;
Packit 575503
}]]),
Packit 575503
dnl action if true:
Packit 575503
            [_found_readline=yes],
Packit 575503
dnl action if false:
Packit 575503
            [_found_readline=no],
Packit 575503
dnl action if cross compiling:
Packit 575503
		AC_TRY_LINK([#include <stdio.h>
Packit 575503
#include <readline/readline.h>
Packit 575503
#include <readline/history.h>],		dnl includes
Packit 575503
			dnl function body
Packit 575503
			[
Packit 575503
	int fd;
Packit 575503
	char *line;
Packit 575503
Packit 575503
	close(0);
Packit 575503
	close(1);
Packit 575503
	fd = open("/dev/null", 2);	/* should get fd 0 */
Packit 575503
	dup(fd);
Packit 575503
	line = readline("giveittome> ");
Packit 575503
Packit 575503
	/* some printfs don't handle NULL for %s */
Packit 575503
	printf("got <%s>\n", line ? line : "(NULL)");
Packit 575503
],
Packit 575503
dnl action if found:
Packit 575503
			[_found_readline=yes],
Packit 575503
dnl action if not found:
Packit 575503
			[_found_readline=no]
Packit 575503
		)
Packit 575503
	)
Packit 575503
Packit 575503
        AC_MSG_RESULT([$_found_readline])
Packit 575503
Packit 575503
        LIBS=$_readline_save_libs
Packit 575503
Packit 575503
        if test $_found_readline = yes ; then
Packit 575503
	   case $host_os in
Packit 575503
	   *bsd* )	AC_CHECK_LIB(termcap, tgetent, _combo="$_combo -ltermcap")
Packit 575503
	  	 ;;
Packit 575503
	   esac
Packit 575503
           AC_DEFINE(HAVE_LIBREADLINE,1,
Packit 575503
	      [Define to 1 if you have a fully functional readline library.])
Packit 575503
           AC_SUBST(LIBREADLINE,$_combo)
Packit 575503
Packit 575503
	   AC_CHECK_LIB(readline, history_list,
Packit 575503
		[AC_DEFINE(HAVE_HISTORY_LIST, 1, [Do we have history_list?])],
Packit 575503
		[],
Packit 575503
		[$_combo])
Packit 575503
Packit 575503
           break
Packit 575503
        fi
Packit 575503
     done
Packit 575503
Packit 575503
     unset _termcap
Packit 575503
     unset _readline_save_libs
Packit 575503
     unset _combo
Packit 575503
     unset _found_readline
Packit 575503
  fi
Packit 575503
])dnl