wi_LIB_READLINE 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. dnl Borut Razem
  2. dnl
  3. dnl This macro checks for the presence of the readline library.
  4. dnl It works also in cross-compilation environment.
  5. dnl
  6. dnl To get it into the aclocal.m4 dnl file, do this:
  7. dnl aclocal -I . --verbose
  8. dnl
  9. dnl The --verbose will show all of the files that are searched
  10. dnl for .m4 macros.
  11. AC_DEFUN([wi_LIB_READLINE], [
  12. dnl check for the readline.h header file
  13. AC_CHECK_HEADER(readline/readline.h)
  14. if test "$ac_cv_header_readline_readline_h" = yes; then
  15. dnl check the readline version
  16. cat > conftest.$ac_ext <<EOF
  17. #include <stdio.h>
  18. #include <readline/readline.h>
  19. wi_LIB_READLINE_VERSION RL_VERSION_MAJOR RL_VERSION_MINOR
  20. EOF
  21. wi_READLINE_VERSION=$($CPP $CPPFLAGS conftest.$ac_ext | sed -n -e "s/^wi_LIB_READLINE_VERSION *\([[0-9\]][[0-9\]]*\) *\([[0-9\]][[0-9\]]*\)$/\1.\2/p")
  22. rm -rf conftest*
  23. if test -n "$wi_READLINE_VERSION"; then
  24. wi_MAJOR=$(expr $wi_READLINE_VERSION : '\([[0-9]][[0-9]]*\)\.')
  25. wi_MINOR=$(expr $wi_READLINE_VERSION : '[[0-9]][[0-9]]*\.\([[0-9]][[0-9]]*$\)')
  26. if test $wi_MINOR -lt 10; then
  27. wi_MINOR=$(expr $wi_MINOR \* 10)
  28. fi
  29. wi_READLINE_VERSION=$(expr $wi_MAJOR \* 100 + $wi_MINOR)
  30. else
  31. wi_READLINE_VERSION=-1
  32. fi
  33. dnl check for the readline library
  34. ac_save_LIBS="$LIBS"
  35. # Note: $LIBCURSES is permitted to be empty.
  36. for LIBREADLINE in "-lreadline.dll" "-lreadline" "-lreadline $LIBCURSES" "-lreadline -ltermcap" "-lreadline -lncurses" "-lreadline -lcurses"
  37. do
  38. AC_MSG_CHECKING([for GNU Readline library $LIBREADLINE])
  39. LIBS="$ac_save_LIBS $LIBREADLINE"
  40. AC_TRY_LINK([
  41. /* includes */
  42. #include <stdio.h>
  43. #include <readline/readline.h>
  44. ],[
  45. /* function-body */
  46. int dummy = rl_completion_append_character; /* rl_completion_append_character appeared in version 2.1 */
  47. readline(NULL);
  48. ],[
  49. wi_cv_lib_readline=yes
  50. AC_MSG_RESULT(yes)
  51. ],[
  52. wi_cv_lib_readline=no
  53. AC_MSG_RESULT(no)
  54. ])
  55. if test "$wi_cv_lib_readline" = yes; then
  56. AC_SUBST(LIBREADLINE)
  57. AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, $wi_READLINE_VERSION, [Readline])
  58. break
  59. fi
  60. done
  61. LIBS="$ac_save_LIBS"
  62. fi
  63. ])