]> arthur.barton.de Git - netatalk.git/blob - macros/libgcrypt.m4
Merge branch 'develop' of netafp.com:git/netatalk into develop
[netatalk.git] / macros / libgcrypt.m4
1 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
2 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
3 dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
4 dnl MINIMUN-VERSION is a string with the version number optionalliy prefixed
5 dnl with the API version to also check the API compatibility. Example:
6 dnl a MINIMUN-VERSION of 1:1.2.5 won't pass the test unless the installed 
7 dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1.  Using
8 dnl this features allows to prevent build against newer versions of libgcrypt
9 dnl with a changed API.
10 dnl
11 AC_DEFUN([AC_NETATALK_PATH_LIBGCRYPT],
12 [ AC_ARG_WITH(libgcrypt-dir,
13             AC_HELP_STRING([--with-libgcrypt-dir=PATH],
14                            [path where LIBGCRYPT is installed (optional). 
15                             Must contain lib and include dirs.]),
16      libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
17   if test x$libgcrypt_config_prefix != x ; then
18      if test x${LIBGCRYPT_CONFIG+set} != xset ; then
19         LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
20      fi
21   fi
22
23   ok=no
24
25 if test x$libgcrypt_config_prefix != xno ; then
26
27   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
28   tmp=ifelse([$1], ,1:1.2.0,$1)
29   if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
30      req_libgcrypt_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
31      min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
32   else
33      req_libgcrypt_api=0
34      min_libgcrypt_version="$tmp"
35   fi
36
37   AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
38   if test "$LIBGCRYPT_CONFIG" != "no" ; then
39     req_major=`echo $min_libgcrypt_version | \
40                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
41     req_minor=`echo $min_libgcrypt_version | \
42                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
43     req_micro=`echo $min_libgcrypt_version | \
44                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
45     libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
46     major=`echo $libgcrypt_config_version | \
47                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
48     minor=`echo $libgcrypt_config_version | \
49                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
50     micro=`echo $libgcrypt_config_version | \
51                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
52     if test "$major" -gt "$req_major"; then
53         ok=yes
54     else 
55         if test "$major" -eq "$req_major"; then
56             if test "$minor" -gt "$req_minor"; then
57                ok=yes
58             else
59                if test "$minor" -eq "$req_minor"; then
60                    if test "$micro" -ge "$req_micro"; then
61                      ok=yes
62                    fi
63                fi
64             fi
65            fi
66         fi
67   fi
68   if test $ok = yes; then
69     AC_MSG_RESULT([yes ($libgcrypt_config_version)])
70   else
71     AC_MSG_RESULT(no)
72   fi
73 fi
74
75   if test $ok = yes; then
76      # If we have a recent libgcrypt, we should also check that the
77      # API is compatible
78      if test "$req_libgcrypt_api" -gt 0 ; then
79         tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
80         if test "$tmp" -gt 0 ; then
81            AC_MSG_CHECKING([libgcrypt API version])
82            if test "$req_libgcrypt_api" -eq "$tmp" ; then
83              AC_MSG_RESULT([okay])
84            else
85              ok=no
86              AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp])
87            fi
88         fi
89      fi
90   fi
91   if test $ok = yes; then
92      # Opensolaris 11/08 provided libgcrypt doesn't have CAST5,
93      # so we better check the general case
94       AC_MSG_CHECKING([libgcrypt hast CAST5 API])
95       cast=`$LIBGCRYPT_CONFIG --algorithms 2>/dev/null | grep cast5 | sed 's/\(.*\)\(cast5\)\(.*\)/\2/'`
96       if test x$cast = xcast5 ; then
97         AC_MSG_RESULT([yes])
98       else
99         AC_MSG_RESULT([no])
100         echo "***          Detected libgcryt without CAST5              ***"
101         echo "*** Please install/build another one and point to it with ***"
102         echo "***         --with-libgcrypt-dir=<path-to-lib>            ***"
103         ok=no
104       fi
105   fi
106
107   if test $ok = yes; then
108     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
109     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
110     neta_cv_compile_dhx2=yes
111     neta_cv_have_libgcrypt=yes
112         AC_MSG_NOTICE([Enabling DHX2 UAM])
113         AC_DEFINE(HAVE_LIBGCRYPT, 1, [Define if the DHX2 modules should be built with libgcrypt])
114         AC_DEFINE(UAM_DHX2, 1, [Define if the DHX2 UAM modules should be compiled])
115     ifelse([$2], , :, [$2])
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 ])