more cleanups
[gnutls.git] / acinclude.m4
blob290fb151e230a4d2def418fadf9344f60cf63089
1 dnl *************** Autoconf macros for libgcrypt (1.1.3) ***************
2 dnl $id$
4 # Configure paths for LIBGCRYPT
5 # Shamelessly stolen from the one of XDELTA by Owen Taylor
6 # Werner Koch   99-12-09
8 dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
9 dnl Test for libgcrypt, and define GCRYPT_CFLAGS and GCRYPT_LIBS
10 dnl
11 AC_DEFUN(AM_PATH_LIBGCRYPT,
12 [dnl
13 dnl Get the cflags and libraries from the libgcrypt-config script
14 dnl
15 AC_ARG_WITH(libgcrypt-prefix,
16           [  --with-libgcrypt-prefix=PFX   Prefix where libgcrypt is installed (optional)],
17           libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
18 AC_ARG_ENABLE(libgcrypttest,
19           [  --disable-libgcrypttest    Do not try to compile and run a test libgcrypt program],
20           , enable_libgcrypttest=yes)
22   if test x$libgcrypt_config_prefix != x ; then
23      libgcrypt_config_args="$libgcrypt_config_args --prefix=$libgcrypt_config_prefix"
24      if test x${LIBGCRYPT_CONFIG+set} != xset ; then
25         LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config
26      fi
27   fi
29   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
30   min_libgcrypt_version=ifelse([$1], ,1.1.0,$1)
31   AC_MSG_CHECKING(for libgcrypt - version >= $min_libgcrypt_version)
32   no_libgcrypt=""
33   if test "$LIBGCRYPT_CONFIG" = "no" ; then
34     no_libgcrypt=yes
35   else
36     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --cflags`
37     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --libs`
38     libgcrypt_config_version=`$LIBGCRYPT_CONFIG $libgcrypt_config_args --version`
39     if test "x$enable_libgcrypttest" = "xyes" ; then
40       ac_save_CFLAGS="$CFLAGS"
41       ac_save_LIBS="$LIBS"
42       CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
43       LIBS="$LIBS $LIBGCRYPT_LIBS"
44 dnl
45 dnl Now check if the installed libgcrypt is sufficiently new. Also sanity
46 dnl checks the results of libgcrypt-config to some extent
47 dnl
48       rm -f conf.libgcrypttest
49       AC_TRY_RUN([
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <gcrypt.h>
55 int
56 main ()
58     system ("touch conf.libgcrypttest");
60     if( strcmp( gcry_check_version(NULL), "$libgcrypt_config_version" ) )
61     {
62       printf("\n*** 'libgcrypt-config --version' returned %s, but LIBGCRYPT (%s)\n",
63              "$libgcrypt_config_version", gcry_check_version(NULL) );
64       printf("*** was found! If libgcrypt-config was correct, then it is best\n");
65       printf("*** to remove the old version of LIBGCRYPT. You may also be able to fix the error\n");
66       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
67       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
68       printf("*** required on your system.\n");
69       printf("*** If libgcrypt-config was wrong, set the environment variable LIBGCRYPT_CONFIG\n");
70       printf("*** to point to the correct copy of libgcrypt-config, and remove the file config.cache\n");
71       printf("*** before re-running configure\n");
72     }
73     else if ( strcmp(gcry_check_version(NULL), GCRYPT_VERSION ) )
74     {
75       printf("\n*** LIBGCRYPT header file (version %s) does not match\n", GCRYPT_VERSION);
76       printf("*** library (version %s)\n", gcry_check_version(NULL) );
77     }
78     else
79     {
80       if ( gcry_check_version( "$min_libgcrypt_version" ) )
81       {
82         return 0;
83       }
84      else
85       {
86         printf("no\n*** An old version of LIBGCRYPT (%s) was found.\n",
87                 gcry_check_version(NULL) );
88         printf("*** You need a version of LIBGCRYPT newer than %s. The latest version of\n",
89                "$min_libgcrypt_version" );
90         printf("*** LIBGCRYPT is always available from ftp://ftp.gnupg.org/pub/libgcrypt/gnupg.\n");
91         printf("*** (It is distributed along with GnuPG).\n");
92         printf("*** \n");
93         printf("*** If you have already installed a sufficiently new version, this error\n");
94         printf("*** probably means that the wrong copy of the libgcrypt-config shell script is\n");
95         printf("*** being found. The easiest way to fix this is to remove the old version\n");
96         printf("*** of LIBGCRYPT, but you can also set the LIBGCRYPT_CONFIG environment to point to the\n");
97         printf("*** correct copy of libgcrypt-config. (In this case, you will have to\n");
98         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
99         printf("*** so that the correct libraries are found at run-time))\n");
100       }
101     }
102   return 1;
104 ],, no_libgcrypt=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
105        CFLAGS="$ac_save_CFLAGS"
106        LIBS="$ac_save_LIBS"
107      fi
108   fi
109   if test "x$no_libgcrypt" = x ; then
110      AC_MSG_RESULT(yes)
111      ifelse([$2], , :, [$2])
112   else
113      if test -f conf.libgcrypttest ; then
114         :
115      else
116         AC_MSG_RESULT(no)
117      fi
118      if test "$LIBGCRYPT_CONFIG" = "no" ; then
119        echo "*** The libgcrypt-config script installed by LIBGCRYPT could not be found"
120        echo "*** If LIBGCRYPT was installed in PREFIX, make sure PREFIX/bin is in"
121        echo "*** your path, or set the LIBGCRYPT_CONFIG environment variable to the"
122        echo "*** full path to libgcrypt-config."
123      else
124        if test -f conf.libgcrypttest ; then
125         :
126        else
127           echo "*** Could not run libgcrypt test program, checking why..."
128           CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
129           LIBS="$LIBS $LIBGCRYPT_LIBS"
130           AC_TRY_LINK([
131 #include <stdio.h>
132 #include <stdlib.h>
133 #include <string.h>
134 #include <gcrypt.h>
135 ],      [ return !!gcry_check_version(NULL); ],
136         [ echo "*** The test program compiled, but did not run. This usually means"
137           echo "*** that the run-time linker is not finding LIBGCRYPT or finding the wrong"
138           echo "*** version of LIBGCRYPT. If it is not finding LIBGCRYPT, you'll need to set your"
139           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
140           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
141           echo "*** is required on your system"
142           echo "***"
143           echo "*** If you have an old version installed, it is best to remove it, although"
144           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
145           echo "***" ],
146         [ echo "*** The test program failed to compile or link. See the file config.log for the"
147           echo "*** exact error that occured. This usually means LIBGCRYPT was incorrectly installed"
148           echo "*** or that you have moved LIBGCRYPT since it was installed. In the latter case, you"
149           echo "*** may want to edit the libgcrypt-config script: $LIBGCRYPT_CONFIG" ])
150           CFLAGS="$ac_save_CFLAGS"
151           LIBS="$ac_save_LIBS"
152        fi
153      fi
154      LIBGCRYPT_CFLAGS=""
155      LIBGCRYPT_LIBS=""
156      ifelse([$3], , :, [$3])
157   fi
158   AC_SUBST(LIBGCRYPT_CFLAGS)
159   AC_SUBST(LIBGCRYPT_LIBS)
160   rm -f conf.libgcrypttest
163 dnl Autoconf macros for libmcrypt
164 dnl $id$
166 # This script detects libmcrypt version and defines
167 # LIBMCRYPT_CFLAGS, LIBMCRYPT_LIBS
168 # and LIBMCRYPT24 or LIBMCRYPT22 depending on libmcrypt version
169 # found.
171 # Modified for LIBMCRYPT -- nmav
172 # Configure paths for LIBGCRYPT
173 # Shamelessly stolen from the one of XDELTA by Owen Taylor
174 # Werner Koch   99-12-09
176 dnl AM_PATH_LIBMCRYPT([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
177 dnl Test for libmcrypt, and define LIBMCRYPT_CFLAGS and LIBMCRYPT_LIBS
179 AC_DEFUN(AM_PATH_LIBMCRYPT,
180 [dnl
181 dnl Get the cflags and libraries from the libmcrypt-config script
183 AC_ARG_WITH(libmcrypt-prefix,
184           [  --with-libmcrypt-prefix=PFX   Prefix where libmcrypt is installed (optional)],
185           libmcrypt_config_prefix="$withval", libmcrypt_config_prefix="")
187   if test x$libmcrypt_config_prefix != x ; then
188      libmcrypt_config_args="$libmcrypt_config_args --prefix=$libmcrypt_config_prefix"
189      if test x${LIBMCRYPT_CONFIG+set} != xset ; then
190         LIBMCRYPT_CONFIG=$libmcrypt_config_prefix/bin/libmcrypt-config
191      fi
192   fi
194   AC_PATH_PROG(LIBMCRYPT_CONFIG, libmcrypt-config, no)
195   min_libmcrypt_version=ifelse([$1], ,2.4.0,$1)
196   AC_MSG_CHECKING(for libmcrypt - version >= $min_libmcrypt_version)
197   no_libmcrypt=""
198   if test "$LIBMCRYPT_CONFIG" = "no" ; then
199 dnl libmcrypt-config was not found (pre 2.4.11 versions)
200 dnl Try to detect libmcrypt version
201       AC_TRY_RUN([
202 #include <stdio.h>
203 #include <stdlib.h>
204 #include <string.h>
205 #include <mcrypt.h>
208 main ()
210 #if MCRYPT_API_VERSION <= 19991015 
211 /* version 2.2 */
212     return 0;
213 #else
214 /* version 2.4 */
215     return 1;
216 #endif /* 19991015 */
218 ],  libmcrypt_config_version="2.2.0"
219     if test x$libmcrypt_config_prefix != x ; then
220         TTLIBS="-L${libmcrypt_config_prefix}/libs"
221         TTINCLUDE="-I${libmcrypt_config_prefix}/include"
222     fi
223     LIBMCRYPT_CFLAGS="${TTINCLUDE}"
224     LIBMCRYPT_LIBS="${TTLIBS} -lmcrypt"
225     AC_DEFINE(LIBMCRYPT22)
227 ,   libmcrypt_config_version="2.4.0"
228     if test x$libmcrypt_config_prefix != x ; then
229         TTLIBS="-L${libmcrypt_config_prefix}/libs"
230         TTINCLUDE="-I${libmcrypt_config_prefix}/include"
231     fi
232     LIBMCRYPT_CFLAGS="${TTINCLUDE}"
233     LIBMCRYPT_LIBS="${TTLIBS} -lmcrypt -lltdl ${LIBADD_DL}"
234     AC_DEFINE(LIBMCRYPT24))
235   else
236 dnl libmcrypt-config was found
237     LIBMCRYPT_CFLAGS=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --cflags`
238     LIBMCRYPT_LIBS=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --libs`
239     libmcrypt_config_version=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --version`
240     AC_DEFINE(LIBMCRYPT24)
241   fi
243   ac_save_CFLAGS="$CFLAGS"
244   ac_save_LIBS="$LIBS"
245   CFLAGS="$CFLAGS $LIBMCRYPT_CFLAGS"
246   LIBS="$LIBS $LIBMCRYPT_LIBS"
249 dnl Now check if the installed libmcrypt is sufficiently new. Also sanity
250 dnl checks the results of libmcrypt-config to some extent
252       rm -f conf.libmcrypttest
253       AC_TRY_RUN([
254 #include <stdio.h>
255 #include <stdlib.h>
256 #include <string.h>
257 #include <mcrypt.h>
259 #define TWO "2.2"
262 main ()
264 #if MCRYPT_API_VERSION <= 20010201
266 #if MCRYPT_API_VERSION <= 19991015 
267 /* version 2.2 */
268     int x = mcrypt_get_key_size(MCRYPT_TWOFISH_128);
269     system ("touch conf.libmcrypttest");
271     if( strncmp( TWO, "$min_libmcrypt_version", strlen(TWO))) {
272       printf("\n*** Requested libmcrypt %s, but LIBMCRYPT (%s)\n",
273              "$min_libmcrypt_version", TWO );
274       printf("*** was found!\n"); 
275       return 1;
276     }
277     return 0;
278 #else
279 /* version 2.4 before 11 */
280     MCRYPT td = mcrypt_module_open("twofish", NULL, "cbc", NULL);
281     system ("touch conf.libmcrypttest");
282     mcrypt_module_close(td);
284     return 0;
285 #endif /* 19991015 */
287 #else
289     system ("touch conf.libmcrypttest");
291     if( strcmp( mcrypt_check_version(NULL), "$libmcrypt_config_version" ) )
292     {
293       printf("\n*** 'libmcrypt-config --version' returned %s, but LIBMCRYPT (%s)\n",
294              "$libmcrypt_config_version", mcrypt_check_version(NULL) );
295       printf("*** was found! If libmcrypt-config was correct, then it is best\n");
296       printf("*** to remove the old version of LIBMCRYPT. You may also be able to fix the error\n");
297       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
298       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
299       printf("*** required on your system.\n");
300       printf("*** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG\n");
301       printf("*** to point to the correct copy of libmcrypt-config, and remove the file config.cache\n");
302       printf("*** before re-running configure\n");
303     }
304     else if ( strcmp(mcrypt_check_version(NULL), LIBMCRYPT_VERSION ) )
305     {
306       printf("\n*** LIBMCRYPT header file (version %s) does not match\n", LIBMCRYPT_VERSION);
307       printf("*** library (version %s)\n", mcrypt_check_version(NULL) );
308     }
309     else
310     {
311       if ( mcrypt_check_version( "$min_libmcrypt_version" ) )
312       {
313         return 0;
314       }
315      else
316       {
317         printf("no\n*** An old version of LIBMCRYPT (%s) was found.\n",
318                 mcrypt_check_version(NULL) );
319         printf("*** You need a version of LIBMCRYPT newer than %s. The latest version of\n",
320                "$min_libmcrypt_version" );
321         printf("*** LIBMCRYPT is always available from ftp://mcrypt.hellug.gr/pub/mcrypt.\n");
322         printf("*** \n");
323         printf("*** If you have already installed a sufficiently new version, this error\n");
324         printf("*** probably means that the wrong copy of the libmcrypt-config shell script is\n");
325         printf("*** being found. The easiest way to fix this is to remove the old version\n");
326         printf("*** of LIBMCRYPT, but you can also set the LIBMCRYPT_CONFIG environment to point to the\n");
327         printf("*** correct copy of libmcrypt-config. (In this case, you will have to\n");
328         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
329         printf("*** so that the correct libraries are found at run-time))\n");
330       }
331     }
332   return 1;
334 #endif /* 20010201 */
337 ],, no_libmcrypt=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
338        CFLAGS="$ac_save_CFLAGS"
339        LIBS="$ac_save_LIBS"
342   if test "x$no_libmcrypt" = x ; then
343      AC_MSG_RESULT(yes)
344      ifelse([$2], , :, [$2])
345   else
346      if test -f conf.libmcrypttest ; then
347         :
348      else
349         AC_MSG_RESULT(no)
350      fi
351      
352      if test -f conf.libmcrypttest ; then
353         :
354      else
355           echo "*** Could not run libmcrypt test program, checking why..."
356           CFLAGS="$CFLAGS $LIBMCRYPT_CFLAGS"
357           LIBS="$LIBS $LIBMCRYPT_LIBS"
358           AC_TRY_LINK([
359 #include <stdio.h>
360 #include <stdlib.h>
361 #include <string.h>
362 #include <mcrypt.h>
363 ],      [ 
364 #if MCRYPT_API_VERSION <= 20010201
366 #if MCRYPT_API_VERSION <= 19991015 
367 /* version 2.2 */
368     int x = mcrypt_get_key_size(MCRYPT_TWOFISH_128);
369     return 0;
370 #else
371 /* version 2.4 before 11 */
372     MCRYPT td = mcrypt_module_open("twofish", NULL, "cbc", NULL);
373     mcrypt_module_close(td);
374     return 0;
375 #endif /* 19991015 */
376 #else
378 return !!mcrypt_check_version(NULL); 
380 #endif /* 20010201 */
383         [ echo "*** The test program compiled, but did not run. This usually means"
384           echo "*** that the run-time linker is not finding LIBMCRYPT or finding the wrong"
385           echo "*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your"
386           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
387           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
388           echo "*** is required on your system"
389           echo "***"
390           echo "*** If you have an old version installed, it is best to remove it, although"
391           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
392           echo "***" ],
393         [ echo "*** The test program failed to compile or link. See the file config.log for the"
394           echo "*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed"
395           echo "*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you"
396           echo "*** may want to edit the libmcrypt-config script: $LIBMCRYPT_CONFIG" ])
397           CFLAGS="$ac_save_CFLAGS"
398           LIBS="$ac_save_LIBS"
399      fi
400      
401      LIBMCRYPT_CFLAGS=""
402      LIBMCRYPT_LIBS=""
403      ifelse([$3], , :, [$3])
404   fi
405   rm -f conf.libmcrypttest
406   AC_SUBST(LIBMCRYPT_CFLAGS)
407   AC_SUBST(LIBMCRYPT_LIBS)
411 dnl *-*wedit:notab*-*  Please keep this as the last line.