chiark / gitweb /
Import gnupg2_2.1.17.orig.tar.bz2
[gnupg2.git] / m4 / libgcrypt.m4
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
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 optionalliy 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 feature prevents building 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             AC_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      else
40        case "${SYSROOT}" in
41          /*)
42            if test -x "${SYSROOT}/bin/libgcrypt-config" ; then
43              LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config"
44            fi
45            ;;
46          '')
47            ;;
48           *)
49            AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
50            ;;
51        esac
52      fi
53   fi
54
55   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
56   tmp=ifelse([$1], ,1:1.2.0,$1)
57   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
58      req_libgcrypt_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
59      min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
60   else
61      req_libgcrypt_api=0
62      min_libgcrypt_version="$tmp"
63   fi
64
65   AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
66   ok=no
67   if test "$LIBGCRYPT_CONFIG" != "no" ; then
68     req_major=`echo $min_libgcrypt_version | \
69                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
70     req_minor=`echo $min_libgcrypt_version | \
71                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
72     req_micro=`echo $min_libgcrypt_version | \
73                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
74     libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
75     major=`echo $libgcrypt_config_version | \
76                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
77     minor=`echo $libgcrypt_config_version | \
78                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
79     micro=`echo $libgcrypt_config_version | \
80                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
81     if test "$major" -gt "$req_major"; then
82         ok=yes
83     else
84         if test "$major" -eq "$req_major"; then
85             if test "$minor" -gt "$req_minor"; then
86                ok=yes
87             else
88                if test "$minor" -eq "$req_minor"; then
89                    if test "$micro" -ge "$req_micro"; then
90                      ok=yes
91                    fi
92                fi
93             fi
94         fi
95     fi
96   fi
97   if test $ok = yes; then
98     AC_MSG_RESULT([yes ($libgcrypt_config_version)])
99   else
100     AC_MSG_RESULT(no)
101   fi
102   if test $ok = yes; then
103      # If we have a recent libgcrypt, we should also check that the
104      # API is compatible
105      if test "$req_libgcrypt_api" -gt 0 ; then
106         tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
107         if test "$tmp" -gt 0 ; then
108            AC_MSG_CHECKING([LIBGCRYPT API version])
109            if test "$req_libgcrypt_api" -eq "$tmp" ; then
110              AC_MSG_RESULT([okay])
111            else
112              ok=no
113              AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp])
114            fi
115         fi
116      fi
117   fi
118   if test $ok = yes; then
119     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
120     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
121     ifelse([$2], , :, [$2])
122     libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none`
123     if test x"$libgcrypt_config_host" != xnone ; then
124       if test x"$libgcrypt_config_host" != x"$host" ; then
125   AC_MSG_WARN([[
126 ***
127 *** The config script $LIBGCRYPT_CONFIG was
128 *** built for $libgcrypt_config_host and thus may not match the
129 *** used host $host.
130 *** You may want to use the configure option --with-libgcrypt-prefix
131 *** to specify a matching config script or use \$SYSROOT.
132 ***]])
133         gpg_config_script_warn="$gpg_config_script_warn libgcrypt"
134       fi
135     fi
136   else
137     LIBGCRYPT_CFLAGS=""
138     LIBGCRYPT_LIBS=""
139     ifelse([$3], , :, [$3])
140   fi
141   AC_SUBST(LIBGCRYPT_CFLAGS)
142   AC_SUBST(LIBGCRYPT_LIBS)
143 ])