1dnl Autoconf macros for libgnutls
2dnl $id$
3
4# Modified for LIBGNUTLS -- nmav
5# Configure paths for LIBGCRYPT
6# Shamelessly stolen from the one of XDELTA by Owen Taylor
7# Werner Koch   99-12-09
8
9dnl AM_PATH_LIBGNUTLS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
10dnl Test for libgnutls, and define LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS
11dnl
12AC_DEFUN([AX_PATH_LIBGNUTLS],
13[dnl
14dnl Get the cflags and libraries from the libgnutls-config script
15dnl
16AC_ARG_WITH(libgnutls-prefix,
17          [  --with-libgnutls-prefix=PFX   Prefix where libgnutls is installed (optional)],
18          libgnutls_config_prefix="$withval", libgnutls_config_prefix="")
19
20  if test x$libgnutls_config_prefix != x ; then
21     if test x${LIBGNUTLS_CONFIG+set} != xset ; then
22        LIBGNUTLS_CONFIG=$libgnutls_config_prefix/bin/libgnutls-config
23     fi
24  fi
25
26  AC_PATH_PROG(LIBGNUTLS_CONFIG, libgnutls-config, no)
27  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
28  no_libgnutls=""
29  if test "$LIBGNUTLS_CONFIG" != "no"; then
30    LIBGNUTLS_CFLAGS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --cflags`
31    LIBGNUTLS_LIBS="`$LIBGNUTLS_CONFIG $libgnutls_config_args --libs` -lpthread  -lgcrypt"
32    libgnutls_config_version=`$LIBGNUTLS_CONFIG $libgnutls_config_args --version`
33  elif test "$PKG_CONFIG" != "no"; then
34    LIBGNUTLS_CFLAGS=`$PKG_CONFIG --cflags gnutls`
35    LIBGNUTLS_LIBS="`$PKG_CONFIG --libs gnutls` -lpthread -lgcrypt"
36    libgnutls_config_version=`$PKG_CONFIG --modversion gnutls`
37  else
38    no_libgnutls=yes
39  fi
40
41  min_libgnutls_version=ifelse([$1], ,0.1.0,$1)
42  AC_MSG_CHECKING(for libgnutls - version >= $min_libgnutls_version)
43
44  if test x"$no_libgnutls" = x""; then
45
46      ac_save_CFLAGS="$CFLAGS"
47      ac_save_LIBS="$LIBS"
48      CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
49      LIBS="$LIBS $LIBGNUTLS_LIBS"
50dnl
51dnl Now check if the installed libgnutls is sufficiently new. Also sanity
52dnl checks the results of libgnutls-config to some extent
53dnl
54      rm -f conf.libgnutlstest
55      AC_TRY_RUN([
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <gnutls/gnutls.h>
60
61int
62main ()
63{
64    system ("touch conf.libgnutlstest");
65
66    if( strcmp( gnutls_check_version(NULL), "$libgnutls_config_version" ) )
67    {
68      printf("\n*** 'libgnutls-config --version' returned %s, but LIBGNUTLS (%s)\n",
69             "$libgnutls_config_version", gnutls_check_version(NULL) );
70      printf("*** was found! If libgnutls-config was correct, then it is best\n");
71      printf("*** to remove the old version of LIBGNUTLS. You may also be able to fix the error\n");
72      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
73      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
74      printf("*** required on your system.\n");
75      printf("*** If libgnutls-config was wrong, set the environment variable LIBGNUTLS_CONFIG\n");
76      printf("*** to point to the correct copy of libgnutls-config, and remove the file config.cache\n");
77      printf("*** before re-running configure\n");
78    }
79    else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_VERSION ) )
80    {
81      printf("\n*** LIBGNUTLS header file (version %s) does not match\n", LIBGNUTLS_VERSION);
82      printf("*** library (version %s)\n", gnutls_check_version(NULL) );
83    }
84    else
85    {
86      if ( gnutls_check_version( "$min_libgnutls_version" ) )
87      {
88        return 0;
89      }
90     else
91      {
92        printf("no\n*** An old version of LIBGNUTLS (%s) was found.\n",
93                gnutls_check_version(NULL) );
94        printf("*** You need a version of LIBGNUTLS newer than %s. The latest version of\n",
95               "$min_libgnutls_version" );
96        printf("*** LIBGNUTLS is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
97        printf("*** \n");
98        printf("*** If you have already installed a sufficiently new version, this error\n");
99        printf("*** probably means that the wrong copy of the libgnutls-config shell script is\n");
100        printf("*** being found. The easiest way to fix this is to remove the old version\n");
101        printf("*** of LIBGNUTLS, but you can also set the LIBGNUTLS_CONFIG environment to point to the\n");
102        printf("*** correct copy of libgnutls-config. (In this case, you will have to\n");
103        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
104        printf("*** so that the correct libraries are found at run-time))\n");
105      }
106    }
107  return 1;
108}
109],, no_libgnutls=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
110       CFLAGS="$ac_save_CFLAGS"
111       LIBS="$ac_save_LIBS"
112  fi
113
114  if test "x$no_libgnutls" = x ; then
115     AC_MSG_RESULT(yes)
116     ifelse([$2], , :, [$2])
117  else
118     if test -f conf.libgnutlstest ; then
119        :
120     else
121        AC_MSG_RESULT(no)
122     fi
123     if test "$LIBGNUTLS_CONFIG" = "no" ; then
124       echo "*** The libgnutls-config script installed by LIBGNUTLS could not be found"
125       echo "*** If LIBGNUTLS was installed in PREFIX, make sure PREFIX/bin is in"
126       echo "*** your path, or set the LIBGNUTLS_CONFIG environment variable to the"
127       echo "*** full path to libgnutls-config."
128     else
129       if test -f conf.libgnutlstest ; then
130        :
131       else
132          echo "*** Could not run libgnutls test program, checking why..."
133          CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
134          LIBS="$LIBS $LIBGNUTLS_LIBS"
135          AC_TRY_LINK([
136#include <stdio.h>
137#include <stdlib.h>
138#include <string.h>
139#include <gnutls/gnutls.h>
140],      [ return !!gnutls_check_version(NULL); ],
141        [ echo "*** The test program compiled, but did not run. This usually means"
142          echo "*** that the run-time linker is not finding LIBGNUTLS or finding the wrong"
143          echo "*** version of LIBGNUTLS. If it is not finding LIBGNUTLS, you'll need to set your"
144          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
145          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
146          echo "*** is required on your system"
147          echo "***"
148          echo "*** If you have an old version installed, it is best to remove it, although"
149          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
150          echo "***" ],
151        [ echo "*** The test program failed to compile or link. See the file config.log for the"
152          echo "*** exact error that occured. This usually means LIBGNUTLS was incorrectly installed"
153          echo "*** or that you have moved LIBGNUTLS since it was installed. In the latter case, you"
154          echo "*** may want to edit the libgnutls-config script: $LIBGNUTLS_CONFIG" ])
155          CFLAGS="$ac_save_CFLAGS"
156          LIBS="$ac_save_LIBS"
157       fi
158     fi
159     LIBGNUTLS_CFLAGS=""
160     LIBGNUTLS_LIBS=""
161     ifelse([$3], , :, [$3])
162  fi
163  rm -f conf.libgnutlstest
164  AC_SUBST(LIBGNUTLS_CFLAGS)
165  AC_SUBST(LIBGNUTLS_LIBS)
166])
167
168dnl *-*wedit:notab*-*  Please keep this as the last line.
169