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