match_strval > try_val_to_str
[wireshark-wip.git] / aclocal-fallback / libgcrypt.m4
blob018b9294d6f99c3681b6eee0c0f87c9323680aef
1 dnl Autoconf macros for libgcrypt
2 dnl       Copyright (C) 2002, 2004 Free Software Foundation, Inc.
3 dnl $Id$
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.
14 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
15 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
16 dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
17 dnl MINIMUN-VERSION is a string with the version number optionalliy prefixed
18 dnl with the API version to also check the API compatibility. Example:
19 dnl a MINIMUN-VERSION of 1:1.2.5 won't pass the test unless the installed 
20 dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1.  Using
21 dnl this features allows to prevent build against newer versions of libgcrypt
22 dnl with a changed API.
23 dnl
24 AC_DEFUN([AM_PATH_LIBGCRYPT],
25 [ AC_ARG_WITH(libgcrypt-prefix,
26             AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
27                            [prefix where LIBGCRYPT is installed (optional)]),
28      libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
29   if test x$libgcrypt_config_prefix != x ; then
30      if test x${LIBGCRYPT_CONFIG+set} != xset ; then
31         LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
32      fi
33   fi
35   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
36   tmp=ifelse([$1], ,1:1.2.0,$1)
37   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
38      req_libgcrypt_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
39      min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
40   else
41      req_libgcrypt_api=0
42      min_libgcrypt_version="$tmp"
43   fi
45   AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
46   ok=no
47   if test "$LIBGCRYPT_CONFIG" != "no" ; then
48     req_major=`echo $min_libgcrypt_version | \
49                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
50     req_minor=`echo $min_libgcrypt_version | \
51                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
52     req_micro=`echo $min_libgcrypt_version | \
53                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
54     libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
55     major=`echo $libgcrypt_config_version | \
56                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
57     minor=`echo $libgcrypt_config_version | \
58                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
59     micro=`echo $libgcrypt_config_version | \
60                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
61     if test "$major" -gt "$req_major"; then
62         ok=yes
63     else 
64         if test "$major" -eq "$req_major"; then
65             if test "$minor" -gt "$req_minor"; then
66                ok=yes
67             else
68                if test "$minor" -eq "$req_minor"; then
69                    if test "$micro" -ge "$req_micro"; then
70                      ok=yes
71                    fi
72                fi
73             fi
74         fi
75     fi
76   fi
77   if test $ok = yes; then
78     AC_MSG_RESULT(yes)
79   else
80     AC_MSG_RESULT(no)
81   fi
82   if test $ok = yes; then
83      # If we have a recent libgcrypt, we should also check that the
84      # API is compatible
85      if test "$req_libgcrypt_api" -gt 0 ; then
86         tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
87         if test "$tmp" -gt 0 ; then
88            AC_MSG_CHECKING([LIBGCRYPT API version])
89            if test "$req_libgcrypt_api" -eq "$tmp" ; then
90              AC_MSG_RESULT(okay)
91            else
92              ok=no
93              AC_MSG_RESULT([does not match (want=$req_libgcrypt_api got=$tmp)])
94            fi
95         fi
96      fi
97   fi
98   if test $ok = yes; then
99     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
100     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
101     ifelse([$2], , :, [$2])
102   else
103     LIBGCRYPT_CFLAGS=""
104     LIBGCRYPT_LIBS=""
105     ifelse([$3], , :, [$3])
106   fi
107   AC_SUBST(LIBGCRYPT_CFLAGS)
108   AC_SUBST(LIBGCRYPT_LIBS)