libgcrypt.m4 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # libgcrypt.m4 - Autoconf macros to detect libgcrypt
  2. # Copyright (C) 2002, 2003, 2004, 2011, 2014 g10 Code GmbH
  3. #
  4. # This file is free software; as a special exception the author gives
  5. # unlimited permission to copy and/or distribute it, with or without
  6. # modifications, as long as this notice is preserved.
  7. #
  8. # This file is distributed in the hope that it will be useful, but
  9. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  10. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. #
  12. # Last-changed: 2014-10-02
  13. dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
  14. dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
  15. dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
  16. dnl MINIMUM-VERSION is a string with the version number optionalliy prefixed
  17. dnl with the API version to also check the API compatibility. Example:
  18. dnl a MINIMUM-VERSION of 1:1.2.5 won't pass the test unless the installed
  19. dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using
  20. dnl this feature prevents building against newer versions of libgcrypt
  21. dnl with a changed API.
  22. dnl
  23. dnl If a prefix option is not used, the config script is first
  24. dnl searched in $SYSROOT/bin and then along $PATH. If the used
  25. dnl config script does not match the host specification the script
  26. dnl is added to the gpg_config_script_warn variable.
  27. dnl
  28. AC_DEFUN([AM_PATH_LIBGCRYPT],
  29. [ AC_REQUIRE([AC_CANONICAL_HOST])
  30. AC_ARG_WITH(libgcrypt-prefix,
  31. AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
  32. [prefix where LIBGCRYPT is installed (optional)]),
  33. libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
  34. if test x"${LIBGCRYPT_CONFIG}" = x ; then
  35. if test x"${libgcrypt_config_prefix}" != x ; then
  36. LIBGCRYPT_CONFIG="${libgcrypt_config_prefix}/bin/libgcrypt-config"
  37. else
  38. case "${SYSROOT}" in
  39. /*)
  40. if test -x "${SYSROOT}/bin/libgcrypt-config" ; then
  41. LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config"
  42. fi
  43. ;;
  44. '')
  45. ;;
  46. *)
  47. AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
  48. ;;
  49. esac
  50. fi
  51. fi
  52. AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
  53. tmp=ifelse([$1], ,1:1.2.0,$1)
  54. if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
  55. req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
  56. min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
  57. else
  58. req_libgcrypt_api=0
  59. min_libgcrypt_version="$tmp"
  60. fi
  61. AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
  62. ok=no
  63. if test "$LIBGCRYPT_CONFIG" != "no" ; then
  64. req_major=`echo $min_libgcrypt_version | \
  65. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
  66. req_minor=`echo $min_libgcrypt_version | \
  67. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
  68. req_micro=`echo $min_libgcrypt_version | \
  69. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
  70. libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
  71. major=`echo $libgcrypt_config_version | \
  72. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
  73. minor=`echo $libgcrypt_config_version | \
  74. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
  75. micro=`echo $libgcrypt_config_version | \
  76. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
  77. if test "$major" -gt "$req_major"; then
  78. ok=yes
  79. else
  80. if test "$major" -eq "$req_major"; then
  81. if test "$minor" -gt "$req_minor"; then
  82. ok=yes
  83. else
  84. if test "$minor" -eq "$req_minor"; then
  85. if test "$micro" -ge "$req_micro"; then
  86. ok=yes
  87. fi
  88. fi
  89. fi
  90. fi
  91. fi
  92. fi
  93. if test $ok = yes; then
  94. AC_MSG_RESULT([yes ($libgcrypt_config_version)])
  95. else
  96. AC_MSG_RESULT(no)
  97. fi
  98. if test $ok = yes; then
  99. # If we have a recent libgcrypt, we should also check that the
  100. # API is compatible
  101. if test "$req_libgcrypt_api" -gt 0 ; then
  102. tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
  103. if test "$tmp" -gt 0 ; then
  104. AC_MSG_CHECKING([LIBGCRYPT API version])
  105. if test "$req_libgcrypt_api" -eq "$tmp" ; then
  106. AC_MSG_RESULT([okay])
  107. else
  108. ok=no
  109. AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp])
  110. fi
  111. fi
  112. fi
  113. fi
  114. if test $ok = yes; then
  115. LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
  116. LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
  117. ifelse([$2], , :, [$2])
  118. libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none`
  119. if test x"$libgcrypt_config_host" != xnone ; then
  120. if test x"$libgcrypt_config_host" != x"$host" ; then
  121. AC_MSG_WARN([[
  122. ***
  123. *** The config script $LIBGCRYPT_CONFIG was
  124. *** built for $libgcrypt_config_host and thus may not match the
  125. *** used host $host.
  126. *** You may want to use the configure option --with-libgcrypt-prefix
  127. *** to specify a matching config script or use \$SYSROOT.
  128. ***]])
  129. gpg_config_script_warn="$gpg_config_script_warn libgcrypt"
  130. fi
  131. fi
  132. else
  133. LIBGCRYPT_CFLAGS=""
  134. LIBGCRYPT_LIBS=""
  135. ifelse([$3], , :, [$3])
  136. fi
  137. AC_SUBST(LIBGCRYPT_CFLAGS)
  138. AC_SUBST(LIBGCRYPT_LIBS)
  139. ])