libgcrypt.m4 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # libgcrypt.m4 - Autoconf macros to detect libgcrypt
  2. # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020 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: 2020-09-27
  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 optionally 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 features allows to prevent build 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. AS_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. fi
  38. fi
  39. use_gpgrt_config=""
  40. if test x"${LIBGCRYPT_CONFIG}" = x -a x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
  41. if $GPGRT_CONFIG libgcrypt --exists; then
  42. LIBGCRYPT_CONFIG="$GPGRT_CONFIG libgcrypt"
  43. AC_MSG_NOTICE([Use gpgrt-config as libgcrypt-config])
  44. use_gpgrt_config=yes
  45. fi
  46. fi
  47. if test -z "$use_gpgrt_config"; then
  48. if test x"${LIBGCRYPT_CONFIG}" = x ; then
  49. case "${SYSROOT}" in
  50. /*)
  51. if test -x "${SYSROOT}/bin/libgcrypt-config" ; then
  52. LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config"
  53. fi
  54. ;;
  55. '')
  56. ;;
  57. *)
  58. AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
  59. ;;
  60. esac
  61. fi
  62. AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
  63. fi
  64. tmp=ifelse([$1], ,1:1.2.0,$1)
  65. if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
  66. req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
  67. min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
  68. else
  69. req_libgcrypt_api=0
  70. min_libgcrypt_version="$tmp"
  71. fi
  72. AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
  73. ok=no
  74. if test "$LIBGCRYPT_CONFIG" != "no" ; then
  75. req_major=`echo $min_libgcrypt_version | \
  76. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
  77. req_minor=`echo $min_libgcrypt_version | \
  78. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
  79. req_micro=`echo $min_libgcrypt_version | \
  80. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
  81. if test -z "$use_gpgrt_config"; then
  82. libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
  83. else
  84. libgcrypt_config_version=`$LIBGCRYPT_CONFIG --modversion`
  85. fi
  86. major=`echo $libgcrypt_config_version | \
  87. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
  88. minor=`echo $libgcrypt_config_version | \
  89. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
  90. micro=`echo $libgcrypt_config_version | \
  91. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
  92. if test "$major" -gt "$req_major"; then
  93. ok=yes
  94. else
  95. if test "$major" -eq "$req_major"; then
  96. if test "$minor" -gt "$req_minor"; then
  97. ok=yes
  98. else
  99. if test "$minor" -eq "$req_minor"; then
  100. if test "$micro" -ge "$req_micro"; then
  101. ok=yes
  102. fi
  103. fi
  104. fi
  105. fi
  106. fi
  107. fi
  108. if test $ok = yes; then
  109. AC_MSG_RESULT([yes ($libgcrypt_config_version)])
  110. else
  111. AC_MSG_RESULT(no)
  112. fi
  113. if test $ok = yes; then
  114. # If we have a recent libgcrypt, we should also check that the
  115. # API is compatible
  116. if test "$req_libgcrypt_api" -gt 0 ; then
  117. if test -z "$use_gpgrt_config"; then
  118. tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
  119. else
  120. tmp=`$LIBGCRYPT_CONFIG --variable=api_version 2>/dev/null || echo 0`
  121. fi
  122. if test "$tmp" -gt 0 ; then
  123. AC_MSG_CHECKING([LIBGCRYPT API version])
  124. if test "$req_libgcrypt_api" -eq "$tmp" ; then
  125. AC_MSG_RESULT([okay])
  126. else
  127. ok=no
  128. AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp])
  129. fi
  130. fi
  131. fi
  132. fi
  133. if test $ok = yes; then
  134. LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
  135. LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
  136. ifelse([$2], , :, [$2])
  137. if test -z "$use_gpgrt_config"; then
  138. libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none`
  139. else
  140. libgcrypt_config_host=`$LIBGCRYPT_CONFIG --variable=host 2>/dev/null || echo none`
  141. fi
  142. if test x"$libgcrypt_config_host" != xnone ; then
  143. if test x"$libgcrypt_config_host" != x"$host" ; then
  144. AC_MSG_WARN([[
  145. ***
  146. *** The config script "$LIBGCRYPT_CONFIG" was
  147. *** built for $libgcrypt_config_host and thus may not match the
  148. *** used host $host.
  149. *** You may want to use the configure option --with-libgcrypt-prefix
  150. *** to specify a matching config script or use \$SYSROOT.
  151. ***]])
  152. gpg_config_script_warn="$gpg_config_script_warn libgcrypt"
  153. fi
  154. fi
  155. else
  156. LIBGCRYPT_CFLAGS=""
  157. LIBGCRYPT_LIBS=""
  158. ifelse([$3], , :, [$3])
  159. fi
  160. AC_SUBST(LIBGCRYPT_CFLAGS)
  161. AC_SUBST(LIBGCRYPT_LIBS)
  162. ])