libgcrypt.m4 4.8 KB

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