Annotation of freem/m4/ax_lib_readline.m4, revision 1.1.1.1

1.1       snw         1: # ===========================================================================
                      2: #     https://www.gnu.org/software/autoconf-archive/ax_lib_readline.html
                      3: # ===========================================================================
                      4: #
                      5: # SYNOPSIS
                      6: #
                      7: #   AX_LIB_READLINE
                      8: #
                      9: # DESCRIPTION
                     10: #
                     11: #   Searches for a readline compatible library. If found, defines
                     12: #   `HAVE_LIBREADLINE'. If the found library has the `add_history' function,
                     13: #   sets also `HAVE_READLINE_HISTORY'. Also checks for the locations of the
                     14: #   necessary include files and sets `HAVE_READLINE_H' or
                     15: #   `HAVE_READLINE_READLINE_H' and `HAVE_READLINE_HISTORY_H' or
                     16: #   'HAVE_HISTORY_H' if the corresponding include files exists.
                     17: #
                     18: #   The libraries that may be readline compatible are `libedit',
                     19: #   `libeditline' and `libreadline'. Sometimes we need to link a termcap
                     20: #   library for readline to work, this macro tests these cases too by trying
                     21: #   to link with `libtermcap', `libcurses' or `libncurses' before giving up.
                     22: #
                     23: #   Here is an example of how to use the information provided by this macro
                     24: #   to perform the necessary includes or declarations in a C file:
                     25: #
                     26: #     #ifdef HAVE_LIBREADLINE
                     27: #     #  if defined(HAVE_READLINE_READLINE_H)
                     28: #     #    include <readline/readline.h>
                     29: #     #  elif defined(HAVE_READLINE_H)
                     30: #     #    include <readline.h>
                     31: #     #  else /* !defined(HAVE_READLINE_H) */
                     32: #     extern char *readline ();
                     33: #     #  endif /* !defined(HAVE_READLINE_H) */
                     34: #     char *cmdline = NULL;
                     35: #     #else /* !defined(HAVE_READLINE_READLINE_H) */
                     36: #       /* no readline */
                     37: #     #endif /* HAVE_LIBREADLINE */
                     38: #
                     39: #     #ifdef HAVE_READLINE_HISTORY
                     40: #     #  if defined(HAVE_READLINE_HISTORY_H)
                     41: #     #    include <readline/history.h>
                     42: #     #  elif defined(HAVE_HISTORY_H)
                     43: #     #    include <history.h>
                     44: #     #  else /* !defined(HAVE_HISTORY_H) */
                     45: #     extern void add_history ();
                     46: #     extern int write_history ();
                     47: #     extern int read_history ();
                     48: #     #  endif /* defined(HAVE_READLINE_HISTORY_H) */
                     49: #       /* no history */
                     50: #     #endif /* HAVE_READLINE_HISTORY */
                     51: #
                     52: # LICENSE
                     53: #
                     54: #   Copyright (c) 2008 Ville Laurikari <vl@iki.fi>
                     55: #
                     56: #   Copying and distribution of this file, with or without modification, are
                     57: #   permitted in any medium without royalty provided the copyright notice
                     58: #   and this notice are preserved. This file is offered as-is, without any
                     59: #   warranty.
                     60: 
                     61: #serial 8
                     62: 
                     63: AU_ALIAS([VL_LIB_READLINE], [AX_LIB_READLINE])
                     64: AC_DEFUN([AX_LIB_READLINE], [
                     65:   AC_CACHE_CHECK([for a readline compatible library],
                     66:                  ax_cv_lib_readline, [
                     67:     ORIG_LIBS="$LIBS"
                     68:     for readline_lib in readline edit editline; do
                     69:       for termcap_lib in "" termcap curses ncurses; do
                     70:         if test -z "$termcap_lib"; then
                     71:           TRY_LIB="-l$readline_lib"
                     72:         else
                     73:           TRY_LIB="-l$readline_lib -l$termcap_lib"
                     74:         fi
                     75:         LIBS="$ORIG_LIBS $TRY_LIB"
                     76:         AC_LINK_IFELSE([AC_LANG_CALL([], [readline])], [ax_cv_lib_readline="$TRY_LIB"])
                     77:         if test -n "$ax_cv_lib_readline"; then
                     78:           break
                     79:         fi
                     80:       done
                     81:       if test -n "$ax_cv_lib_readline"; then
                     82:         break
                     83:       fi
                     84:     done
                     85:     if test -z "$ax_cv_lib_readline"; then
                     86:       ax_cv_lib_readline="no"
                     87:     fi
                     88:     LIBS="$ORIG_LIBS"
                     89:   ])
                     90: 
                     91:   if test "$ax_cv_lib_readline" != "no"; then
                     92:     LIBS="$LIBS $ax_cv_lib_readline"
                     93:     AC_DEFINE(HAVE_LIBREADLINE, 1,
                     94:               [Define if you have a readline compatible library])
                     95:     AC_CHECK_HEADERS(readline.h readline/readline.h)
                     96:     AC_CACHE_CHECK([whether readline supports history],
                     97:                    ax_cv_lib_readline_history, [
                     98:       ax_cv_lib_readline_history="no"
                     99:       AC_LINK_IFELSE([AC_LANG_CALL([], [add_history])], [ax_cv_lib_readline_history="yes"])
                    100:     ])
                    101:     if test "$ax_cv_lib_readline_history" = "yes"; then
                    102:       AC_DEFINE(HAVE_READLINE_HISTORY, 1,
                    103:                 [Define if your readline library has \`add_history'])
                    104:       AC_CHECK_HEADERS(history.h readline/history.h)
                    105:     fi
                    106:   fi
                    107: ])dnl

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>