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