RL_LIB_READLINE_VERSION 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. dnl need: prefix exec_prefix libdir includedir CC TERMCAP_LIB
  2. dnl require:
  3. dnl AC_PROG_CC
  4. dnl BASH_CHECK_LIB_TERMCAP
  5. AC_DEFUN([RL_LIB_READLINE_VERSION],
  6. [
  7. AC_REQUIRE([BASH_CHECK_LIB_TERMCAP])
  8. AC_MSG_CHECKING([version of installed readline library])
  9. # What a pain in the ass this is.
  10. # save cpp and ld options
  11. _save_CFLAGS="$CFLAGS"
  12. _save_LDFLAGS="$LDFLAGS"
  13. _save_LIBS="$LIBS"
  14. # Don't set ac_cv_rl_prefix if the caller has already assigned a value. This
  15. # allows the caller to do something like $_rl_prefix=$withval if the user
  16. # specifies --with-installed-readline=PREFIX as an argument to configure
  17. if test -z "$ac_cv_rl_prefix"; then
  18. test "x$prefix" = xNONE && ac_cv_rl_prefix=$ac_default_prefix || ac_cv_rl_prefix=${prefix}
  19. fi
  20. eval ac_cv_rl_includedir=${ac_cv_rl_prefix}/include
  21. eval ac_cv_rl_libdir=${ac_cv_rl_prefix}/lib
  22. LIBS="$LIBS -lreadline ${TERMCAP_LIB}"
  23. CFLAGS="$CFLAGS -I${ac_cv_rl_includedir}"
  24. LDFLAGS="$LDFLAGS -L${ac_cv_rl_libdir}"
  25. AC_CACHE_VAL(ac_cv_rl_version,
  26. [AC_TRY_RUN([
  27. #include <stdio.h>
  28. #include <readline/readline.h>
  29. extern int rl_gnu_readline_p;
  30. main()
  31. {
  32. FILE *fp;
  33. fp = fopen("conftest.rlv", "w");
  34. if (fp == 0)
  35. exit(1);
  36. if (rl_gnu_readline_p != 1)
  37. fprintf(fp, "0.0\n");
  38. else
  39. fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0");
  40. fclose(fp);
  41. exit(0);
  42. }
  43. ],
  44. ac_cv_rl_version=`cat conftest.rlv`,
  45. ac_cv_rl_version='0.0',
  46. ac_cv_rl_version='4.2')])
  47. CFLAGS="$_save_CFLAGS"
  48. LDFLAGS="$_save_LDFLAGS"
  49. LIBS="$_save_LIBS"
  50. RL_MAJOR=0
  51. RL_MINOR=0
  52. # (
  53. case "$ac_cv_rl_version" in
  54. 2*|3*|4*|5*|6*|7*|8*|9*)
  55. RL_MAJOR=`echo $ac_cv_rl_version | sed 's:\..*$::'`
  56. RL_MINOR=`echo $ac_cv_rl_version | sed -e 's:^.*\.::' -e 's:[[a-zA-Z]]*$::'`
  57. ;;
  58. esac
  59. # (((
  60. case $RL_MAJOR in
  61. [[0-9][0-9]]) _RL_MAJOR=$RL_MAJOR ;;
  62. [[0-9]]) _RL_MAJOR=0$RL_MAJOR ;;
  63. *) _RL_MAJOR=00 ;;
  64. esac
  65. # (((
  66. case $RL_MINOR in
  67. [[0-9][0-9]]) _RL_MINOR=$RL_MINOR ;;
  68. [[0-9]]) _RL_MINOR=0$RL_MINOR ;;
  69. *) _RL_MINOR=00 ;;
  70. esac
  71. RL_VERSION="0x${_RL_MAJOR}${_RL_MINOR}"
  72. # Readline versions greater than 4.2 have these defines in readline.h
  73. if test $ac_cv_rl_version = '0.0' ; then
  74. AC_MSG_WARN([Could not test version of installed readline library.])
  75. elif test $RL_MAJOR -gt 4 || { test $RL_MAJOR = 4 && test $RL_MINOR -gt 2 ; } ; then
  76. # set these for use by the caller
  77. RL_PREFIX=$ac_cv_rl_prefix
  78. RL_LIBDIR=$ac_cv_rl_libdir
  79. RL_INCLUDEDIR=$ac_cv_rl_includedir
  80. AC_MSG_RESULT($ac_cv_rl_version)
  81. else
  82. AC_DEFINE_UNQUOTED(RL_READLINE_VERSION, $RL_VERSION, [encoded version of the installed readline library])
  83. AC_DEFINE_UNQUOTED(RL_VERSION_MAJOR, $RL_MAJOR, [major version of installed readline library])
  84. AC_DEFINE_UNQUOTED(RL_VERSION_MINOR, $RL_MINOR, [minor version of installed readline library])
  85. AC_SUBST(RL_VERSION)
  86. AC_SUBST(RL_MAJOR)
  87. AC_SUBST(RL_MINOR)
  88. # set these for use by the caller
  89. RL_PREFIX=$ac_cv_rl_prefix
  90. RL_LIBDIR=$ac_cv_rl_libdir
  91. RL_INCLUDEDIR=$ac_cv_rl_includedir
  92. AC_MSG_RESULT($ac_cv_rl_version)
  93. fi
  94. ])