libgcrypt.m4 (6242B)
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 14 15 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION, 16 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 17 dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS. 18 dnl MINIMUM-VERSION is a string with the version number optionally prefixed 19 dnl with the API version to also check the API compatibility. Example: 20 dnl a MINIMUM-VERSION of 1:1.2.5 won't pass the test unless the installed 21 dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1. Using 22 dnl this features allows to prevent build against newer versions of libgcrypt 23 dnl with a changed API. 24 dnl 25 dnl If a prefix option is not used, the config script is first 26 dnl searched in $SYSROOT/bin and then along $PATH. If the used 27 dnl config script does not match the host specification the script 28 dnl is added to the gpg_config_script_warn variable. 29 dnl 30 AC_DEFUN([AM_PATH_LIBGCRYPT], 31 [ AC_REQUIRE([AC_CANONICAL_HOST]) 32 AC_ARG_WITH(libgcrypt-prefix, 33 AS_HELP_STRING([--with-libgcrypt-prefix=PFX], 34 [prefix where LIBGCRYPT is installed (optional)]), 35 libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="") 36 if test x"${LIBGCRYPT_CONFIG}" = x ; then 37 if test x"${libgcrypt_config_prefix}" != x ; then 38 LIBGCRYPT_CONFIG="${libgcrypt_config_prefix}/bin/libgcrypt-config" 39 fi 40 fi 41 42 use_gpgrt_config="" 43 if test x"${LIBGCRYPT_CONFIG}" = x -a x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then 44 if $GPGRT_CONFIG libgcrypt --exists; then 45 LIBGCRYPT_CONFIG="$GPGRT_CONFIG libgcrypt" 46 AC_MSG_NOTICE([Use gpgrt-config as libgcrypt-config]) 47 use_gpgrt_config=yes 48 fi 49 fi 50 if test -z "$use_gpgrt_config"; then 51 if test x"${LIBGCRYPT_CONFIG}" = x ; then 52 case "${SYSROOT}" in 53 /*) 54 if test -x "${SYSROOT}/bin/libgcrypt-config" ; then 55 LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config" 56 fi 57 ;; 58 '') 59 ;; 60 *) 61 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.]) 62 ;; 63 esac 64 fi 65 AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no) 66 fi 67 68 tmp=ifelse([$1], ,1:1.2.0,$1) 69 if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then 70 req_libgcrypt_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'` 71 min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'` 72 else 73 req_libgcrypt_api=0 74 min_libgcrypt_version="$tmp" 75 fi 76 77 AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version) 78 ok=no 79 if test "$LIBGCRYPT_CONFIG" != "no" ; then 80 req_major=`echo $min_libgcrypt_version | \ 81 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` 82 req_minor=`echo $min_libgcrypt_version | \ 83 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` 84 req_micro=`echo $min_libgcrypt_version | \ 85 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'` 86 if test -z "$use_gpgrt_config"; then 87 libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version` 88 else 89 libgcrypt_config_version=`$LIBGCRYPT_CONFIG --modversion` 90 fi 91 major=`echo $libgcrypt_config_version | \ 92 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` 93 minor=`echo $libgcrypt_config_version | \ 94 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` 95 micro=`echo $libgcrypt_config_version | \ 96 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'` 97 if test "$major" -gt "$req_major"; then 98 ok=yes 99 else 100 if test "$major" -eq "$req_major"; then 101 if test "$minor" -gt "$req_minor"; then 102 ok=yes 103 else 104 if test "$minor" -eq "$req_minor"; then 105 if test "$micro" -ge "$req_micro"; then 106 ok=yes 107 fi 108 fi 109 fi 110 fi 111 fi 112 fi 113 if test $ok = yes; then 114 AC_MSG_RESULT([yes ($libgcrypt_config_version)]) 115 else 116 AC_MSG_RESULT(no) 117 fi 118 if test $ok = yes; then 119 # If we have a recent libgcrypt, we should also check that the 120 # API is compatible 121 if test "$req_libgcrypt_api" -gt 0 ; then 122 if test -z "$use_gpgrt_config"; then 123 tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0` 124 else 125 tmp=`$LIBGCRYPT_CONFIG --variable=api_version 2>/dev/null || echo 0` 126 fi 127 if test "$tmp" -gt 0 ; then 128 AC_MSG_CHECKING([LIBGCRYPT API version]) 129 if test "$req_libgcrypt_api" -eq "$tmp" ; then 130 AC_MSG_RESULT([okay]) 131 else 132 ok=no 133 AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp]) 134 fi 135 fi 136 fi 137 fi 138 if test $ok = yes; then 139 LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags` 140 LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs` 141 ifelse([$2], , :, [$2]) 142 if test -z "$use_gpgrt_config"; then 143 libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none` 144 else 145 libgcrypt_config_host=`$LIBGCRYPT_CONFIG --variable=host 2>/dev/null || echo none` 146 fi 147 if test x"$libgcrypt_config_host" != xnone ; then 148 if test x"$libgcrypt_config_host" != x"$host" ; then 149 AC_MSG_WARN([[ 150 *** 151 *** The config script "$LIBGCRYPT_CONFIG" was 152 *** built for $libgcrypt_config_host and thus may not match the 153 *** used host $host. 154 *** You may want to use the configure option --with-libgcrypt-prefix 155 *** to specify a matching config script or use \$SYSROOT. 156 ***]]) 157 gpg_config_script_warn="$gpg_config_script_warn libgcrypt" 158 fi 159 fi 160 else 161 LIBGCRYPT_CFLAGS="" 162 LIBGCRYPT_LIBS="" 163 ifelse([$3], , :, [$3]) 164 fi 165 AC_SUBST(LIBGCRYPT_CFLAGS) 166 AC_SUBST(LIBGCRYPT_LIBS) 167 ])