2007-05-19 Marcus Brinkmann <marcus@g10code.de>
[libgcrypt.git] / configure.ac
1 # Configure.ac script for Libgcrypt
2 # Copyright (C) 1998, 1999, 2000, 2001, 2002
3 #               2003, 2004, 2006 Free Software Foundation, Inc.
4 #
5 # This file is part of Libgcrypt.
6 #
7 # Libgcrypt is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser general Public License as
9 # published by the Free Software Foundation; either version 2.1 of
10 # the License, or (at your option) any later version.
11 #
12 # Libgcrypt is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #
21 # (Process this file with autoconf to produce a configure script.)
22 AC_REVISION($Revision$)
23 AC_PREREQ(2.60)
24 min_automake_version="1.10"
25
26
27 # Remember to change the version number immediately *after* a release.
28 # Set my_issvn to "yes" for non-released code.  Remember to run an
29 # "svn up" and "autogen.sh" right before creating a distribution.
30 m4_define([my_version], [1.3.1])
31 m4_define([my_issvn], [yes])
32
33 m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \
34             || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')]))
35 AC_INIT([libgcrypt], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]),
36         [bug-libgcrypt@gnupg.org])
37 # LT Version numbers, remember to change them just *before* a release.
38 #   (Interfaces removed:    CURRENT++, AGE=0, REVISION=0)
39 #   (Interfaces added:      CURRENT++, AGE++, REVISION=0)
40 #   (No interfaces changed:                   REVISION++)
41 LIBGCRYPT_LT_CURRENT=15
42 LIBGCRYPT_LT_AGE=4
43 LIBGCRYPT_LT_REVISION=0
44
45
46 # If the API is changed in an incompatible way: increment the next counter.
47 LIBGCRYPT_CONFIG_API_VERSION=1
48
49 NEED_GPG_ERROR_VERSION=1.0
50
51 BUILD_REVISION=svn_revision
52 PACKAGE=$PACKAGE_NAME
53 VERSION=$PACKAGE_VERSION
54
55 AC_CONFIG_SRCDIR([src/libgcrypt.vers])
56 AC_CANONICAL_TARGET()
57 AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
58 AM_CONFIG_HEADER(config.h)
59 AM_MAINTAINER_MODE
60
61 AH_TOP([
62 /* need this, because some autoconf tests rely on this (e.g. stpcpy)
63  * and it should be used for new programs  */
64 #define _GNU_SOURCE  1
65 ])
66
67 AH_BOTTOM([
68 #define _GCRYPT_IN_LIBGCRYPT 1
69
70 /* If the configure check for endianness has been disabled, get it from
71    OS macros.  This is intended for making fat binary builds on OS X.  */
72 #ifdef DISABLED_ENDIAN_CHECK
73 # if defined(__BIG_ENDIAN__)
74 #  define WORDS_BIGENDIAN 1
75 # elif defined(__LITTLE_ENDIAN__)
76 #  undef WORDS_BIGENDIAN
77 # else
78 #  error "No endianness found"
79 # endif
80 #endif /*DISABLED_ENDIAN_CHECK*/
81
82 ])
83
84 AH_VERBATIM([_REENTRANT],
85 [/* To allow the use of Libgcrypt in multithreaded programs we have to use
86     special features from the library. */
87 #ifndef _REENTRANT
88 # define _REENTRANT 1
89 #endif
90 ])
91
92
93 AC_SUBST(LIBGCRYPT_LT_CURRENT)
94 AC_SUBST(LIBGCRYPT_LT_AGE)
95 AC_SUBST(LIBGCRYPT_LT_REVISION)
96 AC_SUBST(PACKAGE)
97 AC_SUBST(VERSION)
98 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
99 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
100
101
102 ######################
103 ##  Basic checks.  ### (we need some results later on (e.g. $GCC)
104 ######################
105
106 AC_PROG_MAKE_SET
107 missing_dir=`cd $ac_aux_dir && pwd`
108 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
109 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
110 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
111 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
112 # AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
113 AC_PROG_CC
114 AC_PROG_CPP
115 AM_PROG_CC_C_O
116 AM_PROG_AS
117 AC_ISC_POSIX
118 AC_PROG_INSTALL
119 AC_PROG_AWK
120
121 AC_LIBTOOL_WIN32_DLL
122 AC_LIBTOOL_RC
123 AM_PROG_LIBTOOL
124
125
126 ##########################
127 ## General definitions. ##
128 ##########################
129
130 # Used by libgcrypt-config
131 LIBGCRYPT_CONFIG_LIBS="-lgcrypt"
132 LIBGCRYPT_CONFIG_CFLAGS=""
133
134 # Definitions for symmetric ciphers.
135 available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed"
136 available_ciphers="$available_ciphers camellia"
137 enabled_ciphers=""
138
139 # Definitions for public-key ciphers.
140 available_pubkey_ciphers="dsa elgamal rsa ecc"
141 enabled_pubkey_ciphers=""
142
143 # Definitions for message digests.
144 available_digests="crc md4 md5 rmd160 sha1 sha256"
145 available_digests_64="sha512 tiger whirlpool"
146 enabled_digests=""
147
148 # Definitions for random modules.
149 available_random_modules="linux egd unix"
150 auto_random_modules="$available_random_modules"
151
152 # Supported thread backends.
153 LIBGCRYPT_THREAD_MODULES=""
154
155 # Other definitions.
156 print_egd_notice=no
157 have_w32_system=no
158
159 # Setup some stuff depending on host/target.
160 case "${target}" in
161     *-*-mingw32*)
162       available_random_modules="w32"
163       ac_cv_have_dev_random=no
164       have_w32_system=yes
165       AC_DEFINE(USE_ONLY_8DOT3,1,
166                 [set this to limit filenames to the 8.3 format])
167       AC_DEFINE(HAVE_DRIVE_LETTERS,1,
168                 [defined if we must run on a stupid file system])
169       AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
170                 [defined if we run on some of the PCDOS like systems 
171                  (DOS, Windoze. OS/2) with special properties like
172                   no file modes])
173       ;;
174
175     i?86-emx-os2 | i?86-*-os2*emx)
176         # OS/2 with the EMX environment
177         ac_cv_have_dev_random=no
178         AC_DEFINE(HAVE_DRIVE_LETTERS)
179         AC_DEFINE(HAVE_DOSISH_SYSTEM)
180         ;;
181
182     i?86-*-msdosdjgpp*)
183         # DOS with the DJGPP environment
184         ac_cv_have_dev_random=no
185         AC_DEFINE(HAVE_DRIVE_LETTERS)
186         AC_DEFINE(HAVE_DOSISH_SYSTEM)
187         ;;
188
189     *-*-freebsd*)
190        # FreeBSD
191        CPPFLAGS="$CPPFLAGS -I/usr/local/include"
192        LDFLAGS="$LDFLAGS -L/usr/local/lib"
193        ;;
194
195     *-*-hpux*)
196         if test -z "$GCC" ; then
197             CFLAGS="$CFLAGS -Ae -D_HPUX_SOURCE"
198         fi
199         ;;
200     *-dec-osf4*)
201         if test -z "$GCC" ; then
202             # Suppress all warnings
203             # to get rid of the unsigned/signed char mismatch warnings.
204             CFLAGS="$CFLAGS -w"
205         fi
206         ;;
207     m68k-atari-mint)
208         ;;
209     *)
210       ;;
211 esac
212
213 if test "$have_w32_system" = yes; then
214    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
215 fi
216 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
217
218
219
220 # A printable OS Name is sometimes useful.
221 case "${target}" in
222     *-*-mingw32*)
223         PRINTABLE_OS_NAME="MingW32"
224         ;;
225
226     i?86-emx-os2 | i?86-*-os2*emx )
227         PRINTABLE_OS_NAME="OS/2"
228         ;;
229
230     i?86-*-msdosdjgpp*)
231         PRINTABLE_OS_NAME="MSDOS/DJGPP"
232         ;;
233
234     *-linux*)
235         PRINTABLE_OS_NAME="GNU/Linux"
236         ;;
237
238     *)
239         PRINTABLE_OS_NAME=`uname -s || echo "Unknown"`
240         ;;
241 esac
242
243 # Figure out the name of the random device
244 case "${target}" in
245     *-openbsd*)
246         # FIXME: Are these the best flags for OpenBSD?
247         NAME_OF_DEV_RANDOM="/dev/srandom"
248         NAME_OF_DEV_URANDOM="/dev/urandom"
249 #       DYNLINK_MOD_CFLAGS="-shared -rdynamic $CFLAGS_PIC -Wl,-Bshareable -Wl,-x"
250         ;;
251
252     *-solaris* | *-irix* | *-dec-osf* | *-netbsd* )
253         NAME_OF_DEV_RANDOM="/dev/random"
254         NAME_OF_DEV_URANDOM="/dev/random"
255 #       DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC"
256         ;;
257
258     *)
259         NAME_OF_DEV_RANDOM="/dev/random"
260         NAME_OF_DEV_URANDOM="/dev/urandom"
261         # -shared is a gcc-ism.  Find pic flags from GNUPG_CHECK_PIC.
262 #        if test -n "$GCC" ; then
263 #           DYNLINK_MOD_CFLAGS="-shared $CFLAGS_PIC"                            
264 #        else
265 #           DYNLINK_MOD_CFLAGS="$CFLAGS_PIC"
266 #        fi
267         ;;
268 esac
269
270
271 AC_ARG_ENABLE(endian-check,
272               AC_HELP_STRING([--disable-endian-check],
273               [disable the endian check and trust the OS provided macros]),
274               endiancheck=$enableval,endiancheck=yes)
275 if test x"$endiancheck" = xyes ; then
276   AC_C_BIGENDIAN
277 else
278   AC_DEFINE(DISABLED_ENDIAN_CHECK,1,[configure did not test for endianess])
279 fi
280
281
282 AC_CHECK_SIZEOF(unsigned short, 2)
283 AC_CHECK_SIZEOF(unsigned int, 4)
284 AC_CHECK_SIZEOF(unsigned long, 4)
285 AC_CHECK_SIZEOF(unsigned long long, 0)
286
287 if test "$ac_cv_sizeof_unsigned_short" = "0" \
288    || test "$ac_cv_sizeof_unsigned_int" = "0" \
289    || test "$ac_cv_sizeof_unsigned_long" = "0"; then
290     AC_MSG_WARN([Hmmm, something is wrong with the sizes - using defaults]);
291 fi
292
293 # Do we have any 64-bit data types?
294 if test "$ac_cv_sizeof_unsigned_int" != "8" \
295    && test "$ac_cv_sizeof_unsigned_long" != "8" \
296    && test "$ac_cv_sizeof_unsigned_long_long" != "8" \
297    && test "$ac_cv_sizeof_uint64_t" != "8"; then
298     AC_MSG_WARN([No 64-bit types.  Disabling TIGER/192, SHA-384, and SHA-512])
299 else
300   available_digests="$available_digests $available_digests_64"
301 fi
302
303 # If not specified otherwise, all available algorithms will be
304 # included.  Except for Camellia which is GPLed.
305 default_ciphers=`echo "$available_ciphers" | sed 's/ camellia//'`
306 default_pubkey_ciphers="$available_pubkey_ciphers"
307 default_digests="$available_digests"
308
309 ############################
310 ## Command line switches. ##
311 ############################
312
313 # Implementation of the --enable-ciphers switch.
314 AC_ARG_ENABLE(ciphers,
315               AC_HELP_STRING([--enable-ciphers=ciphers],
316                              [select the symmetric ciphers to include]),
317               [enabled_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
318               [enabled_ciphers=""])
319 if test "x$enabled_ciphers" = "x" \
320    -o "$enabled_ciphers" = "yes"  \
321    -o "$enabled_ciphers" = "no"; then
322    enabled_ciphers=$default_ciphers
323 fi
324 AC_MSG_CHECKING([which symmetric ciphers to include])
325 for cipher in $enabled_ciphers; do
326     LIST_MEMBER($cipher, $available_ciphers)
327     if test "$found" = "0"; then
328        AC_MSG_ERROR([unsupported cipher "$cipher" specified])
329     fi
330 done
331 AC_MSG_RESULT([$enabled_ciphers])
332
333 # Implementation of the --enable-pubkey-ciphers switch.
334 AC_ARG_ENABLE(pubkey-ciphers,
335               AC_HELP_STRING([--enable-pubkey-ciphers=ciphers],
336                              [select the public-key ciphers to include]),
337               [enabled_pubkey_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
338               [enabled_pubkey_ciphers=""])
339 if test "x$enabled_pubkey_ciphers" = "x" \
340    -o "$enabled_pubkey_ciphers" = "yes"  \
341    -o "$enabled_pubkey_ciphers" = "no"; then
342    enabled_pubkey_ciphers=$default_pubkey_ciphers
343 fi
344 AC_MSG_CHECKING([which public-key ciphers to include])
345 for cipher in $enabled_pubkey_ciphers; do
346     LIST_MEMBER($cipher, $available_pubkey_ciphers)
347     if test "$found" = "0"; then
348        AC_MSG_ERROR([unsupported public-key cipher specified])
349     fi
350 done
351 AC_MSG_RESULT([$enabled_pubkey_ciphers])
352
353 # Implementation of the --enable-digests switch.
354 AC_ARG_ENABLE(digests,
355               AC_HELP_STRING([--enable-digests=digests],
356                              [select the message digests to include]),
357               [enabled_digests=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
358               [enabled_digests=""])
359 if test "x$enabled_digests" = "x" \
360    -o "$enabled_digests" = "yes"  \
361    -o "$enabled_digests" = "no"; then
362    enabled_digests=$default_digests
363 fi
364 AC_MSG_CHECKING([which message digests to include])
365 for digest in $enabled_digests; do
366     LIST_MEMBER($digest, $available_digests)
367     if test "$found" = "0"; then
368        AC_MSG_ERROR([unsupported message digest specified])
369     fi
370 done
371 AC_MSG_RESULT([$enabled_digests])
372
373 # Implementation of the --enable-random switch.
374 AC_ARG_ENABLE(random,
375               AC_HELP_STRING([--enable-random=name],
376                              [select which random number generator to use]),
377               [random=`echo $enableval | tr '[A-Z]' '[a-z]'`],
378               [])
379 if test "x$random" = "x" -o "$random" = "yes" -o "$random" = "no"; then
380     random=default
381 fi
382 AC_MSG_CHECKING([which random module to use])
383 if test "$random" != "default" -a "$random" != "auto"; then
384     LIST_MEMBER($random, $available_random_modules)
385     if test "$found" = "0"; then
386        AC_MSG_ERROR([unsupported random module specified])
387     fi
388 fi
389 AC_MSG_RESULT($random)
390
391 # Implementation of the --disable-dev-random switch.
392 AC_MSG_CHECKING([whether use of /dev/random is requested])
393 AC_ARG_ENABLE(dev-random,
394 [  --disable-dev-random    disable the use of dev random],
395     try_dev_random=$enableval, try_dev_random=yes)
396 AC_MSG_RESULT($try_dev_random)
397
398 # Implementation of the --with-egd-socket switch.
399 AC_ARG_WITH(egd-socket,
400     [  --with-egd-socket=NAME  Use NAME for the EGD socket)],
401             egd_socket_name="$withval", egd_socket_name="" )
402 AC_DEFINE_UNQUOTED(EGD_SOCKET_NAME, "$egd_socket_name",
403                    [Define if you don't want the default EGD socket name.
404                     For details see cipher/rndegd.c])
405
406 # Implementation of the --enable-random-daemon
407 AC_MSG_CHECKING([whether the experimental random daemon is requested])
408 AC_ARG_ENABLE([random-daemon],
409               AC_HELP_STRING([--enable-random-daemon],
410                              [Build and support the experimental gcryptrnd]),
411               [use_random_daemon=$enableval],
412               [use_random_daemon=no])
413 AC_MSG_RESULT($use_random_daemon)
414 if test x$use_random_daemon = xyes ; then
415     AC_DEFINE(USE_RANDOM_DAEMON,1,
416               [Define to support the experimental random daemon])
417 fi
418 AM_CONDITIONAL(USE_RANDOM_DAEMON, test x$use_random_daemon = xyes)
419
420
421 # Implementation of --disable-asm.
422 AC_MSG_CHECKING([whether assembler modules are requested])
423 AC_ARG_ENABLE([asm],
424               AC_HELP_STRING([--disable-asm],
425                              [Disable assembler modules]),
426               [try_asm_modules=$enableval],
427               [try_asm_modules=yes])
428 AC_MSG_RESULT($try_asm_modules)
429
430 # Implementation of the --enable-m-guard switch.
431 AC_MSG_CHECKING([whether memory guard is requested])
432 AC_ARG_ENABLE(m-guard,
433     [  --enable-m-guard        enable memory guard facility],
434     use_m_guard=$enableval, use_m_guard=no)
435     AC_MSG_RESULT($use_m_guard)
436 if test "$use_m_guard" = yes ; then
437     AC_DEFINE(M_GUARD,1,[Define to use the (obsolete) malloc guarding feature])
438 fi
439
440 # Implementation of the --with-capabilities switch.
441 # Check whether we want to use Linux capabilities
442 AC_MSG_CHECKING([whether use of capabilities is requested])
443 AC_ARG_WITH(capabilities,
444     [  --with-capabilities     use linux capabilities [default=no]],
445 [use_capabilities="$withval"],[use_capabilities=no])
446 AC_MSG_RESULT($use_capabilities)
447
448 AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
449                    [A human readable text with the name of the OS])
450
451 # For some systems we know that we have ld_version scripts.  
452 # Use it then as default.
453 have_ld_version_script=no
454 case "${host}" in
455     *-*-linux*)
456         have_ld_version_script=yes
457         ;;
458     *-*-gnu*)
459         have_ld_version_script=yes
460         ;;
461 esac
462 AC_ARG_ENABLE([ld-version-script],
463               AC_HELP_STRING([--enable-ld-version-script],
464                              [enable/disable use of linker version script.
465                               (default is system dependent)]),
466               [have_ld_version_script=$enableval],
467               [ : ] )
468 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
469
470 AC_DEFINE_UNQUOTED(NAME_OF_DEV_RANDOM, "$NAME_OF_DEV_RANDOM",
471                    [defined to the name of the strong random device])
472 AC_DEFINE_UNQUOTED(NAME_OF_DEV_URANDOM, "$NAME_OF_DEV_URANDOM",
473                    [defined to the name of the weaker random device])
474
475 ###############################
476 #### Checks for libraries. ####
477 ###############################
478
479 #
480 # gpg-error is required.
481 #
482 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
483 if test "x$GPG_ERROR_LIBS" = "x"; then
484   AC_MSG_ERROR([libgpg-error is needed.
485                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
486 fi
487
488 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GCRYPT,
489           [The default error source for libgcrypt.])
490
491 #
492 # Check whether the GNU Pth library is available.  We require this 
493 # to build the optional gcryptrnd program.
494 #
495 AC_ARG_WITH(pth-prefix,
496             AC_HELP_STRING([--with-pth-prefix=PFX],
497                            [prefix where GNU Pth is installed (optional)]),
498      pth_config_prefix="$withval", pth_config_prefix="")
499 if test x$pth_config_prefix != x ; then
500    PTH_CONFIG="$pth_config_prefix/bin/pth-config"
501 fi
502 if test "$use_random_daemon" = "yes"; then
503   AC_PATH_PROG(PTH_CONFIG, pth-config, no)
504   if test "$PTH_CONFIG" = "no"; then
505     AC_MSG_WARN([[
506 ***
507 *** To build the Libgcrypt's random number daemon
508 *** we need the support of the GNU Portable Threads Library.
509 *** Download it from ftp://ftp.gnu.org/gnu/pth/
510 *** On a Debian GNU/Linux system you might want to try 
511 ***   apt-get install libpth-dev
512 ***]])
513   else
514     GNUPG_PTH_VERSION_CHECK([1.3.7])
515     if test $have_pth = yes; then      
516        PTH_CFLAGS=`$PTH_CONFIG --cflags`
517        PTH_LIBS=`$PTH_CONFIG --ldflags`
518        PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`"
519        AC_DEFINE(USE_GNU_PTH, 1,
520                 [Defined if the GNU Portable Thread Library should be used])
521        AC_DEFINE(HAVE_PTH, 1,
522                 [Defined if the GNU Pth is available])
523     fi
524   fi
525 fi
526 AC_SUBST(PTH_CFLAGS)
527 AC_SUBST(PTH_LIBS)
528
529
530 # Solaris needs -lsocket and -lnsl. Unisys system includes
531 # gethostbyname in libsocket but needs libnsl for socket.
532 AC_SEARCH_LIBS(setsockopt, [socket], ,
533         [AC_SEARCH_LIBS(setsockopt, [socket], , , [-lnsl])])
534 AC_SEARCH_LIBS(setsockopt, [nsl])
535
536 ##################################
537 #### Checks for header files. ####
538 ##################################
539
540 AC_HEADER_STDC
541 AC_CHECK_HEADERS(unistd.h sys/select.h)
542
543 ##########################################
544 #### Checks for typedefs, structures, ####
545 ####  and compiler characteristics.   ####
546 ##########################################
547
548 AC_C_CONST
549 AC_C_INLINE
550 AC_TYPE_SIZE_T
551 AC_TYPE_SIGNAL
552 AC_DECL_SYS_SIGLIST
553
554 GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF)
555 GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF)
556 GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF)
557 GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF)
558 GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)
559
560 gl_TYPE_SOCKLEN_T
561 case "${host}" in
562   *-*-mingw32*)
563     # socklen_t may or may not be defined depending on what headers
564     # are included.  To be safe we use int as this is the actual type.
565     FALLBACK_SOCKLEN_T="typedef int gcry_socklen_t;"
566     ;;
567   *)
568     if test ".$gl_cv_socklen_t_equiv" = "."; then
569       FALLBACK_SOCKLEN_T="typedef socklen_t gcry_socklen_t;"
570     else
571       FALLBACK_SOCKLEN_T="typedef ${gl_cv_socklen_t_equiv} gcry_socklen_t;"
572     fi
573 esac
574 AC_SUBST(FALLBACK_SOCKLEN_T)
575
576
577
578 #######################################
579 #### Checks for library functions. ####
580 #######################################
581
582 AC_FUNC_VPRINTF
583 # We have replacements for these in src/missing-string.c
584 AC_CHECK_FUNCS(stpcpy strcasecmp)
585 # We have replacements for these in src/g10lib.h
586 AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise)
587 # Other checks
588 AC_CHECK_FUNCS(strerror rand mmap getpagesize sysconf waitpid wait4)
589 AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime)
590 AC_CHECK_FUNCS(fcntl ftruncate)
591
592 GNUPG_CHECK_MLOCK
593
594 # Check whether we can use Linux capabilities as requested.
595 if test "$use_capabilities" = "yes" ; then
596 use_capabilities=no
597 AC_CHECK_HEADERS(sys/capability.h)
598 if test "$ac_cv_header_sys_capability_h" = "yes" ; then
599   AC_CHECK_LIB(cap, cap_init, ac_need_libcap=1)
600   if test "$ac_cv_lib_cap_cap_init" = "yes"; then
601      AC_DEFINE(USE_CAPABILITIES,1,
602                [define if capabilities should be used])
603      LIBS="$LIBS -lcap"
604      use_capabilities=yes
605   fi
606 fi
607 if test "$use_capabilities" = "no" ; then
608     AC_MSG_WARN([[
609 ***
610 *** The use of capabilities on this system is not possible.
611 *** You need a recent Linux kernel and some patches:
612 ***   fcaps-2.2.9-990610.patch      (kernel patch for 2.2.9)
613 ***   fcap-module-990613.tar.gz     (kernel module)
614 ***   libcap-1.92.tar.gz            (user mode library and utilities)
615 *** And you have to configure the kernel with CONFIG_VFS_CAP_PLUGIN
616 *** set (filesystems menu). Be warned: This code is *really* ALPHA.
617 ***]])
618 fi
619 fi
620
621 # Check whether a random device is available.
622 if test "$try_dev_random" = yes ; then
623     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
624     [if test -r "$NAME_OF_DEV_RANDOM" && test -r "$NAME_OF_DEV_URANDOM" ; then
625       ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
626     if test "$ac_cv_have_dev_random" = yes; then
627         AC_DEFINE(HAVE_DEV_RANDOM,1,
628                  [defined if the system supports a random device] )
629     fi
630 else
631     AC_MSG_CHECKING(for random device)
632     ac_cv_have_dev_random=no
633     AC_MSG_RESULT(has been disabled)
634 fi
635
636 # Figure out the random modules for this configuration.
637 if test "$random" = "default"; then
638
639     # Select default value.
640     if test "$ac_cv_have_dev_random" = yes; then
641         # Try Linuxish random device.
642         random_modules="linux"
643     else
644         case "${target}" in
645         *-*-mingw32*|*-*-cygwin*)
646           # Windows random device.
647           random_modules="w32"
648           ;;
649         *)
650           # Build everything, allow to select at runtime.
651           random_modules="$auto_random_modules"
652           ;;
653         esac    
654     fi
655 else
656     if test "$random" = "auto"; then
657         # Build everything, allow to select at runtime.
658         random_modules="$auto_random_modules"
659     else
660         random_modules="$random"
661     fi
662 fi
663
664
665 #
666 # Setup assembler stuff.
667 #
668 GNUPG_SYS_SYMBOL_UNDERSCORE()
669 AC_ARG_ENABLE(mpi-path,
670               AC_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
671               [prepend EXTRA_PATH to list of CPU specific optimizations]),
672               mpi_extra_path="$enableval",mpi_extra_path="")
673 AC_MSG_CHECKING(for mpi assembler functions)
674 if test -f $srcdir/mpi/config.links ; then
675     . $srcdir/mpi/config.links
676     AC_CONFIG_LINKS("$mpi_ln_list")
677     ac_cv_mpi_sflags="$mpi_sflags"
678     AC_MSG_RESULT(done)
679 else
680     AC_MSG_RESULT(failed)
681     AC_MSG_ERROR([mpi/config.links missing!])
682 fi
683 MPI_SFLAGS="$ac_cv_mpi_sflags"
684 AC_SUBST(MPI_SFLAGS)
685
686 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
687 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
688 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
689 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
690 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
691 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
692 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
693 AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
694 AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
695 AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
696 AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
697 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
698 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
699 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
700 AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
701 AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
702 AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
703 AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
704
705 # Allow users to append something to the version string without
706 # flagging it as development version.  The user version part is
707 # considered everything after a dash.
708 changequote(,)#
709 tmp_pat='[a-zA-Z]'
710 changequote([,])#
711 if echo "$VERSION" | sed 's/-.*//' | grep "$tmp_pat" >/dev/null ; then
712     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
713               [Defined if this is not a regular release])
714 fi
715
716 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
717
718
719 # This is handy for debugging so the compiler doesn't rearrange
720 # things and eliminate variables.
721 AC_ARG_ENABLE(optimization,
722        AC_HELP_STRING([--disable-optimization],
723                       [disable compiler optimization]),
724                       [if test $enableval = no ; then
725                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
726                        fi])
727
728 AC_ARG_ENABLE(gcc-warnings,
729               AC_HELP_STRING([--enable-gcc-warnings],
730                              [enable more verbose gcc warnings]),
731               [more_gcc_warnings="$enableval"],
732               [more_gcc_warnings="no"])
733
734 if test "$GCC" = yes; then
735     if test "$USE_MAINTAINER_MODE" = "yes" ||
736        test "$more_gcc_warnings" = "yes"; then
737         CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
738         if test "$more_gcc_warnings" = "yes"; then
739             CFLAGS="$CFLAGS -W -Wextra -Wpointer-arith -Wbad-function-cast"
740             CFLAGS="$CFLAGS -Wwrite-strings"
741             CFLAGS="$CFLAGS -Wdeclaration-after-statement"
742             CFLAGS="$CFLAGS -Wno-missing-field-initializers"
743             CFLAGS="$CFLAGS -Wno-sign-compare"
744             # Note: We don't use -Wunreachable-code because this gives
745             # warnings for all asserts and many inline functions like
746             # gpg_error (gcc 4.1.2 20060928).
747         fi
748     else
749         CFLAGS="$CFLAGS -Wall"
750     fi
751 fi
752
753 # Check whether as(1) supports a noeexecstack feature.  This test
754 # includes an override option.
755 CL_AS_NOEXECSTACK
756
757
758 AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION)
759 AC_SUBST(LIBGCRYPT_CONFIG_LIBS)
760 AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS)
761 AC_SUBST(LIBGCRYPT_THREAD_MODULES)
762
763 AC_CONFIG_COMMANDS([gcrypt-conf],[[
764 chmod +x src/libgcrypt-config
765 ]],[[
766 prefix=$prefix
767 exec_prefix=$exec_prefix
768 libdir=$libdir
769 datadir=$datadir
770 DATADIRNAME=$DATADIRNAME
771 ]])
772
773 #####################
774 #### Conclusion. ####
775 #####################
776
777 # Define conditional sources and config.h symbols depending on the
778 # selected ciphers, pubkey-ciphers, digests and random modules.
779
780 LIST_MEMBER(arcfour, $enabled_ciphers)
781 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo"
782 AC_DEFINE_UNQUOTED(USE_ARCFOUR, $found,
783                                  [Defined if this module should be included])
784
785 LIST_MEMBER(blowfish, $enabled_ciphers)
786 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo"
787 AC_DEFINE_UNQUOTED(USE_BLOWFISH, $found,
788                                   [Defined if this module should be included])
789
790 LIST_MEMBER(cast5, $enabled_ciphers)
791 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo"
792 AC_DEFINE_UNQUOTED(USE_CAST5, $found,
793                                [Defined if this module should be included])
794
795 LIST_MEMBER(des, $enabled_ciphers)
796 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo"
797 AC_DEFINE_UNQUOTED(USE_DES, $found,
798                              [Defined if this module should be included])
799
800 LIST_MEMBER(aes, $enabled_ciphers)
801 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo"
802 AC_DEFINE_UNQUOTED(USE_AES, $found,
803                              [Defined if this module should be included])
804
805 LIST_MEMBER(twofish, $enabled_ciphers)
806 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo"
807 AC_DEFINE_UNQUOTED(USE_TWOFISH, $found,
808                                  [Defined if this module should be included])
809
810 LIST_MEMBER(serpent, $enabled_ciphers)
811 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo"
812 AC_DEFINE_UNQUOTED(USE_SERPENT, $found,
813                                  [Defined if this module should be included])
814
815 LIST_MEMBER(rfc2268, $enabled_ciphers)
816 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo"
817 AC_DEFINE_UNQUOTED(USE_RFC2268, $found,
818                                  [Defined if this module should be included])
819
820 LIST_MEMBER(seed, $enabled_ciphers)
821 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo"
822 AC_DEFINE_UNQUOTED(USE_SEED, $found,
823                              [Defined if this module should be included])
824
825 LIST_MEMBER(camellia, $enabled_ciphers)
826 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia.lo camellia-glue.lo" && gpl="$gpl camellia"
827 AC_DEFINE_UNQUOTED(USE_CAMELLIA, $found,
828                              [Defined if this module should be included])
829
830 LIST_MEMBER(dsa, $enabled_pubkey_ciphers)
831 test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo"
832 AC_DEFINE_UNQUOTED(USE_DSA, $found,
833                              [Defined if this module should be included])
834
835 LIST_MEMBER(rsa, $enabled_pubkey_ciphers)
836 test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo"
837 AC_DEFINE_UNQUOTED(USE_RSA, $found,
838                             [Defined if this module should be included])
839
840 LIST_MEMBER(elgamal, $enabled_pubkey_ciphers)
841 test "$found" = "1" \ 
842      && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo"
843 AC_DEFINE_UNQUOTED(USE_ELGAMAL, $found,
844                                 [Defined if this module should be included])
845
846 LIST_MEMBER(ecc, $enabled_pubkey_ciphers)
847 test "$found" = "1" \ 
848      && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS ecc.lo"
849 AC_DEFINE_UNQUOTED(USE_ECC, $found,
850                                 [Defined if this module should be included])
851
852 LIST_MEMBER(crc, $enabled_digests)
853 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo"
854 AC_DEFINE_UNQUOTED(USE_CRC, $found,
855                             [Defined if this module should be included])
856
857 LIST_MEMBER(md4, $enabled_digests)
858 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo"
859 AC_DEFINE_UNQUOTED(USE_MD4, $found,
860                              [Defined if this module should be included])
861
862 LIST_MEMBER(md5, $enabled_digests)
863 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo"
864 AC_DEFINE_UNQUOTED(USE_MD5, $found,
865                              [Defined if this module should be included])
866
867 LIST_MEMBER(sha256, $enabled_digests)
868 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo"
869 AC_DEFINE_UNQUOTED(USE_SHA256, $found,
870                                 [Defined if this module should be included])
871
872 LIST_MEMBER(sha512, $enabled_digests)
873 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo"
874 AC_DEFINE_UNQUOTED(USE_SHA512, $found,
875                                 [Defined if this module should be included])
876
877 LIST_MEMBER(tiger, $enabled_digests)
878 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo"
879 AC_DEFINE_UNQUOTED(USE_TIGER, $found,
880                                [Defined if this module should be included])
881
882 LIST_MEMBER(whirlpool, $enabled_digests)
883 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo"
884 AC_DEFINE_UNQUOTED(USE_WHIRLPOOL, $found,
885                                [Defined if this module should be included])
886
887 # rmd160 and sha1 should be included always.
888 GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo"
889 AC_DEFINE_UNQUOTED(USE_RMD160, 1, [Defined if this module should be included])
890 AC_DEFINE_UNQUOTED(USE_SHA1, 1,   [Defined if this module should be included])
891
892 LIST_MEMBER(linux, $random_modules)
893 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndlinux.lo"
894 AC_DEFINE_UNQUOTED(USE_RNDLINUX, $found,
895                    [Defined if the /dev/random based RNG should be used.])
896
897
898 LIST_MEMBER(unix, $random_modules)
899 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo" \
900                     && gpl="$gpl rndunix"
901 AC_DEFINE_UNQUOTED(USE_RNDUNIX, $found,
902                   [Defined if the default Unix RNG should be used.])
903 if test "$found" = "1"; then
904    print_egd_notice=yes
905 fi
906
907 LIST_MEMBER(egd, $random_modules)
908 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo"
909 AC_DEFINE_UNQUOTED(USE_RNDEGD, $found,
910                   [Defined if the EGD based RNG should be used.])
911
912 LIST_MEMBER(w32, $random_modules)
913 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo" \
914                     && gpl="$gpl rndw32"
915 AC_DEFINE_UNQUOTED(USE_RNDW32, $found,
916                   [Defined if the Windows specific RNG should be used.])
917
918 AC_SUBST([GCRYPT_CIPHERS])
919 AC_SUBST([GCRYPT_PUBKEY_CIPHERS])
920 AC_SUBST([GCRYPT_DIGESTS])
921 AC_SUBST([GCRYPT_RANDOM])
922
923 AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers)
924 AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers)
925 AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests)
926
927 # For printing the configuration we need a colon separated list of
928 # algorithm names.
929 tmp=`echo "$enabled_ciphers" | tr ' ' : `
930 AC_DEFINE_UNQUOTED(LIBGCRYPT_CIPHERS, "$tmp", 
931                    [List of available cipher algorithms])
932 tmp=`echo "$enabled_pubkey_ciphers" | tr ' ' : `
933 AC_DEFINE_UNQUOTED(LIBGCRYPT_PUBKEY_CIPHERS, "$tmp", 
934                    [List of available public key cipher algorithms])
935 tmp=`echo "$enabled_digests" | tr ' ' : `
936 AC_DEFINE_UNQUOTED(LIBGCRYPT_DIGESTS, "$tmp", 
937                    [List of available digest algorithms])
938
939
940
941 # Generate extended version information for W32.
942 if test "$have_w32_system" = yes; then
943    BUILD_TIMESTAMP=`date --iso-8601=minutes`
944    changequote(,)dnl 
945    BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
946    changequote([,])dnl
947    BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
948 fi
949 AC_SUBST(BUILD_REVISION)
950 AC_SUBST(BUILD_TIMESTAMP)
951 AC_SUBST(BUILD_FILEVERSION)
952 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", 
953                    [Subversion revision used to build this package])
954
955
956
957 # And create the files.
958 AC_CONFIG_FILES([
959 Makefile
960 m4/Makefile
961 mpi/Makefile
962 cipher/Makefile
963 doc/Makefile
964 src/Makefile
965 src/gcrypt.h
966 src/libgcrypt-config
967 src/versioninfo.rc
968 tests/Makefile
969 ])
970 AC_OUTPUT
971
972 # Give some feedback
973 echo
974
975 if test "$print_egd_notice" = "yes"; then
976 cat <<G10EOF
977   
978    The performance of the Unix random gatherer module (rndunix) is not
979    very good and it does not keep the entropy pool over multiple
980    invocations of GnuPG.  The suggested way to overcome this problem is
981    to use the
982   
983                  Entropy Gathering Daemon (EGD)
984   
985    which provides a entropy source for the whole system.  It is written
986    in Perl and available at the GnuPG FTP servers.  To enable EGD you
987    should rerun configure with the option "--enable-static-rnd=egd".
988    For more information consult the GnuPG webpages:
989   
990              http://www.gnupg.org/download.html#egd
991
992 G10EOF
993 fi
994
995 if test -n "$gpl"; then
996   echo "Please note that you are building a version of Libgcrypt with"
997   echo "  $gpl"
998   echo "included.  These parts are licensed under the GPL and thus the"
999   echo "use of this library has to comply with the conditions of the GPL."
1000 fi
1001
1002 # Give some feedback
1003 echo   "                Configured for: $PRINTABLE_OS_NAME ($target)"
1004 echo