]> git.ipfire.org Git - thirdparty/lldpd.git/blame - m4/ax_lib_readline.m4
build: better find system libnl3
[thirdparty/lldpd.git] / m4 / ax_lib_readline.m4
CommitLineData
23e7fa38
VB
1# ===========================================================================
2# http://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 ();
35f6f4fb 33# extern int rl_insert_text(const char*);
35f6f4fb
VB
34# extern void rl_forced_update_display(void);
35# extern int rl_bind_key(int, int(*f)(int, int));
23e7fa38
VB
36# # endif /* !defined(HAVE_READLINE_H) */
37# char *cmdline = NULL;
38# #else /* !defined(HAVE_READLINE_READLINE_H) */
39# /* no readline */
40# #endif /* HAVE_LIBREADLINE */
41#
42# #ifdef HAVE_READLINE_HISTORY
43# # if defined(HAVE_READLINE_HISTORY_H)
44# # include <readline/history.h>
45# # elif defined(HAVE_HISTORY_H)
46# # include <history.h>
47# # else /* !defined(HAVE_HISTORY_H) */
48# extern void add_history ();
49# extern int write_history ();
50# extern int read_history ();
51# # endif /* defined(HAVE_READLINE_HISTORY_H) */
52# /* no history */
53# #endif /* HAVE_READLINE_HISTORY */
54#
55# LICENSE
56#
57# Copyright (c) 2008 Ville Laurikari <vl@iki.fi>
58#
59# Copying and distribution of this file, with or without modification, are
60# permitted in any medium without royalty provided the copyright notice
61# and this notice are preserved. This file is offered as-is, without any
62# warranty.
63
35f6f4fb
VB
64# Modified version. Original version is available here:
65# http://www.gnu.org/software/autoconf-archive/ax_lib_readline.html
66
23e7fa38
VB
67#serial 6
68
69AU_ALIAS([VL_LIB_READLINE], [AX_LIB_READLINE])
70AC_DEFUN([AX_LIB_READLINE], [
71 AC_CACHE_CHECK([for a readline compatible library],
72 ax_cv_lib_readline, [
73 _save_LIBS="$LIBS"
74 for readline_lib in readline edit editline; do
75 for termcap_lib in "" termcap curses ncurses; do
76 if test -z "$termcap_lib"; then
77 TRY_LIB="-l$readline_lib"
78 else
79 TRY_LIB="-l$readline_lib -l$termcap_lib"
80 fi
81 LIBS="$ORIG_LIBS $TRY_LIB"
07f2c567 82 for readline_func in readline rl_insert_text rl_forced_update_display; do
35f6f4fb
VB
83 AC_TRY_LINK_FUNC($readline_func, ax_cv_lib_readline="$TRY_LIB", ax_cv_lib_readline="")
84 if test -z "$ax_cv_lib_readline"; then
85 break
86 fi
87 done
23e7fa38
VB
88 if test -n "$ax_cv_lib_readline"; then
89 break
90 fi
91 done
92 if test -n "$ax_cv_lib_readline"; then
93 break
94 fi
95 done
96 if test -z "$ax_cv_lib_readline"; then
97 ax_cv_lib_readline="no"
98 fi
99 LIBS="$_save_LIBS"
100 ])
101
102 if test "$ax_cv_lib_readline" != "no"; then
103 READLINE_LIBS="$ax_cv_lib_readline"
104 AC_SUBST(READLINE_LIBS)
105
106 _save_LIBS="$LIBS"
107 LIBS="$LIBS $READLINE_LIBS"
108 AC_DEFINE(HAVE_LIBREADLINE, 1,
109 [Define if you have a readline compatible library])
110 AC_CHECK_HEADERS(readline.h readline/readline.h)
111 AC_CACHE_CHECK([whether readline supports history],
112 ax_cv_lib_readline_history, [
113 ax_cv_lib_readline_history="no"
114 AC_TRY_LINK_FUNC(add_history, ax_cv_lib_readline_history="yes")
115 ])
116 if test "$ax_cv_lib_readline_history" = "yes"; then
117 AC_DEFINE(HAVE_READLINE_HISTORY, 1,
118 [Define if your readline library has \`add_history'])
119 AC_CHECK_HEADERS(history.h readline/history.h)
120 fi
121
122 LIBS="$_save_LIBS"
123 fi
124])dnl