Updated automake.
[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.0])
31 m4_define([my_issvn], [no])
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_mod_list="$mpi_mod_list"
678     ac_cv_mpi_sflags="$mpi_sflags"
679     ac_cv_mpi_config_done="yes"
680     AC_MSG_RESULT(done)
681 else
682     AC_MSG_RESULT(failed)
683     AC_MSG_ERROR([mpi/config.links missing!])
684 fi
685 MPI_MOD_LIST_LO=""
686 MPI_MOD_LIST_O=""
687 if test "$ac_cv_mpi_mod_list" != ""; then
688   for i in $ac_cv_mpi_mod_list; do
689       MPI_MOD_LIST_LO="$MPI_MOD_LIST_LO $i.lo"
690       MPI_MOD_LIST_O="$MPI_MOD_LIST_O $i.o"
691   done
692 fi
693 AC_SUBST(MPI_MOD_LIST_LO)
694 AC_SUBST(MPI_MOD_LIST_O)
695 MPI_SFLAGS="$ac_cv_mpi_sflags"
696 AC_SUBST(MPI_SFLAGS)
697
698 # Allow users to append something to the version string without
699 # flagging it as development version.  The user version part is
700 # considered everything after a dash.
701 changequote(,)#
702 tmp_pat='[a-zA-Z]'
703 changequote([,])#
704 if echo "$VERSION" | sed 's/-.*//' | grep "$tmp_pat" >/dev/null ; then
705     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
706               [Defined if this is not a regular release])
707 fi
708
709 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
710
711
712 # This is handy for debugging so the compiler doesn't rearrange
713 # things and eliminate variables.
714 AC_ARG_ENABLE(optimization,
715        AC_HELP_STRING([--disable-optimization],
716                       [disable compiler optimization]),
717                       [if test $enableval = no ; then
718                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
719                        fi])
720
721 AC_ARG_ENABLE(gcc-warnings,
722               AC_HELP_STRING([--enable-gcc-warnings],
723                              [enable more verbose gcc warnings]),
724               [more_gcc_warnings="$enableval"],
725               [more_gcc_warnings="no"])
726
727 if test "$GCC" = yes; then
728     if test "$USE_MAINTAINER_MODE" = "yes" ||
729        test "$more_gcc_warnings" = "yes"; then
730         CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
731         if test "$more_gcc_warnings" = "yes"; then
732             CFLAGS="$CFLAGS -W -Wextra -Wpointer-arith -Wbad-function-cast"
733             CFLAGS="$CFLAGS -Wwrite-strings"
734             CFLAGS="$CFLAGS -Wdeclaration-after-statement"
735             CFLAGS="$CFLAGS -Wno-missing-field-initializers"
736             CFLAGS="$CFLAGS -Wno-sign-compare"
737             # Note: We don't use -Wunreachable-code because this gives
738             # warnings for all asserts and many inline functions like
739             # gpg_error (gcc 4.1.2 20060928).
740         fi
741     else
742         CFLAGS="$CFLAGS -Wall"
743     fi
744 fi
745
746 # Check whether as(1) supports a noeexecstack feature.  This test
747 # includes an override option.
748 CL_AS_NOEXECSTACK
749
750
751 AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION)
752 AC_SUBST(LIBGCRYPT_CONFIG_LIBS)
753 AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS)
754 AC_SUBST(LIBGCRYPT_THREAD_MODULES)
755
756 AC_CONFIG_COMMANDS([gcrypt-conf],[[
757 chmod +x src/libgcrypt-config
758 ]],[[
759 prefix=$prefix
760 exec_prefix=$exec_prefix
761 libdir=$libdir
762 datadir=$datadir
763 DATADIRNAME=$DATADIRNAME
764 ]])
765
766 #####################
767 #### Conclusion. ####
768 #####################
769
770 # Define conditional sources and config.h symbols depending on the
771 # selected ciphers, pubkey-ciphers, digests and random modules.
772
773 LIST_MEMBER(arcfour, $enabled_ciphers)
774 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo"
775 AC_DEFINE_UNQUOTED(USE_ARCFOUR, $found,
776                                  [Defined if this module should be included])
777
778 LIST_MEMBER(blowfish, $enabled_ciphers)
779 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo"
780 AC_DEFINE_UNQUOTED(USE_BLOWFISH, $found,
781                                   [Defined if this module should be included])
782
783 LIST_MEMBER(cast5, $enabled_ciphers)
784 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo"
785 AC_DEFINE_UNQUOTED(USE_CAST5, $found,
786                                [Defined if this module should be included])
787
788 LIST_MEMBER(des, $enabled_ciphers)
789 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo"
790 AC_DEFINE_UNQUOTED(USE_DES, $found,
791                              [Defined if this module should be included])
792
793 LIST_MEMBER(aes, $enabled_ciphers)
794 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo"
795 AC_DEFINE_UNQUOTED(USE_AES, $found,
796                              [Defined if this module should be included])
797
798 LIST_MEMBER(twofish, $enabled_ciphers)
799 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo"
800 AC_DEFINE_UNQUOTED(USE_TWOFISH, $found,
801                                  [Defined if this module should be included])
802
803 LIST_MEMBER(serpent, $enabled_ciphers)
804 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo"
805 AC_DEFINE_UNQUOTED(USE_SERPENT, $found,
806                                  [Defined if this module should be included])
807
808 LIST_MEMBER(rfc2268, $enabled_ciphers)
809 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo"
810 AC_DEFINE_UNQUOTED(USE_RFC2268, $found,
811                                  [Defined if this module should be included])
812
813 LIST_MEMBER(seed, $enabled_ciphers)
814 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo"
815 AC_DEFINE_UNQUOTED(USE_SEED, $found,
816                              [Defined if this module should be included])
817
818 LIST_MEMBER(camellia, $enabled_ciphers)
819 test "$found" = "1" && GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia.lo camellia-glue.lo" && gpl="$gpl camellia"
820 AC_DEFINE_UNQUOTED(USE_CAMELLIA, $found,
821                              [Defined if this module should be included])
822
823 LIST_MEMBER(dsa, $enabled_pubkey_ciphers)
824 test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo"
825 AC_DEFINE_UNQUOTED(USE_DSA, $found,
826                              [Defined if this module should be included])
827
828 LIST_MEMBER(rsa, $enabled_pubkey_ciphers)
829 test "$found" = "1" && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo"
830 AC_DEFINE_UNQUOTED(USE_RSA, $found,
831                             [Defined if this module should be included])
832
833 LIST_MEMBER(elgamal, $enabled_pubkey_ciphers)
834 test "$found" = "1" \ 
835      && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo"
836 AC_DEFINE_UNQUOTED(USE_ELGAMAL, $found,
837                                 [Defined if this module should be included])
838
839 LIST_MEMBER(ecc, $enabled_pubkey_ciphers)
840 test "$found" = "1" \ 
841      && GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS ecc.lo"
842 AC_DEFINE_UNQUOTED(USE_ECC, $found,
843                                 [Defined if this module should be included])
844
845 LIST_MEMBER(crc, $enabled_digests)
846 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo"
847 AC_DEFINE_UNQUOTED(USE_CRC, $found,
848                             [Defined if this module should be included])
849
850 LIST_MEMBER(md4, $enabled_digests)
851 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo"
852 AC_DEFINE_UNQUOTED(USE_MD4, $found,
853                              [Defined if this module should be included])
854
855 LIST_MEMBER(md5, $enabled_digests)
856 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo"
857 AC_DEFINE_UNQUOTED(USE_MD5, $found,
858                              [Defined if this module should be included])
859
860 LIST_MEMBER(sha256, $enabled_digests)
861 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo"
862 AC_DEFINE_UNQUOTED(USE_SHA256, $found,
863                                 [Defined if this module should be included])
864
865 LIST_MEMBER(sha512, $enabled_digests)
866 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo"
867 AC_DEFINE_UNQUOTED(USE_SHA512, $found,
868                                 [Defined if this module should be included])
869
870 LIST_MEMBER(tiger, $enabled_digests)
871 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo"
872 AC_DEFINE_UNQUOTED(USE_TIGER, $found,
873                                [Defined if this module should be included])
874
875 LIST_MEMBER(whirlpool, $enabled_digests)
876 test "$found" = "1" && GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo"
877 AC_DEFINE_UNQUOTED(USE_WHIRLPOOL, $found,
878                                [Defined if this module should be included])
879
880 # rmd160 and sha1 should be included always.
881 GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo"
882 AC_DEFINE_UNQUOTED(USE_RMD160, 1, [Defined if this module should be included])
883 AC_DEFINE_UNQUOTED(USE_SHA1, 1,   [Defined if this module should be included])
884
885 LIST_MEMBER(linux, $random_modules)
886 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndlinux.lo"
887 AC_DEFINE_UNQUOTED(USE_RNDLINUX, $found,
888                    [Defined if the /dev/random based RNG should be used.])
889
890
891 LIST_MEMBER(unix, $random_modules)
892 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo" \
893                     && gpl="$gpl rndunix"
894 AC_DEFINE_UNQUOTED(USE_RNDUNIX, $found,
895                   [Defined if the default Unix RNG should be used.])
896 if test "$found" = "1"; then
897    print_egd_notice=yes
898 fi
899
900 LIST_MEMBER(egd, $random_modules)
901 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo"
902 AC_DEFINE_UNQUOTED(USE_RNDEGD, $found,
903                   [Defined if the EGD based RNG should be used.])
904
905 LIST_MEMBER(w32, $random_modules)
906 test "$found" = "1" && GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo" \
907                     && gpl="$gpl rndw32"
908 AC_DEFINE_UNQUOTED(USE_RNDW32, $found,
909                   [Defined if the Windows specific RNG should be used.])
910
911 AC_SUBST([GCRYPT_CIPHERS])
912 AC_SUBST([GCRYPT_PUBKEY_CIPHERS])
913 AC_SUBST([GCRYPT_DIGESTS])
914 AC_SUBST([GCRYPT_RANDOM])
915
916 AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers)
917 AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers)
918 AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests)
919
920 # For printing the configuration we need a colon separated list of
921 # algorithm names.
922 tmp=`echo "$enabled_ciphers" | tr ' ' : `
923 AC_DEFINE_UNQUOTED(LIBGCRYPT_CIPHERS, "$tmp", 
924                    [List of available cipher algorithms])
925 tmp=`echo "$enabled_pubkey_ciphers" | tr ' ' : `
926 AC_DEFINE_UNQUOTED(LIBGCRYPT_PUBKEY_CIPHERS, "$tmp", 
927                    [List of available public key cipher algorithms])
928 tmp=`echo "$enabled_digests" | tr ' ' : `
929 AC_DEFINE_UNQUOTED(LIBGCRYPT_DIGESTS, "$tmp", 
930                    [List of available digest algorithms])
931
932
933
934 # Generate extended version information for W32.
935 if test "$have_w32_system" = yes; then
936    BUILD_TIMESTAMP=`date --iso-8601=minutes`
937    changequote(,)dnl 
938    BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
939    changequote([,])dnl
940    BUILD_FILEVERSION="${BUILD_FILEVERSION}${BUILD_REVISION}"
941 fi
942 AC_SUBST(BUILD_REVISION)
943 AC_SUBST(BUILD_TIMESTAMP)
944 AC_SUBST(BUILD_FILEVERSION)
945 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", 
946                    [Subversion revision used to build this package])
947
948
949
950 # And create the files.
951 AC_CONFIG_FILES([
952 Makefile
953 m4/Makefile
954 mpi/Makefile
955 cipher/Makefile
956 doc/Makefile
957 src/Makefile
958 src/gcrypt.h
959 src/libgcrypt-config
960 src/versioninfo.rc
961 tests/Makefile
962 ])
963 AC_OUTPUT
964
965 # Give some feedback
966 echo
967
968 if test "$print_egd_notice" = "yes"; then
969 cat <<G10EOF
970   
971    The performance of the Unix random gatherer module (rndunix) is not
972    very good and it does not keep the entropy pool over multiple
973    invocations of GnuPG.  The suggested way to overcome this problem is
974    to use the
975   
976                  Entropy Gathering Daemon (EGD)
977   
978    which provides a entropy source for the whole system.  It is written
979    in Perl and available at the GnuPG FTP servers.  To enable EGD you
980    should rerun configure with the option "--enable-static-rnd=egd".
981    For more information consult the GnuPG webpages:
982   
983              http://www.gnupg.org/download.html#egd
984
985 G10EOF
986 fi
987
988 if test -n "$gpl"; then
989   echo "Please note that you are building a version of Libgcrypt with"
990   echo "  $gpl"
991   echo "included.  These parts are licensed under the GPL and thus the"
992   echo "use of this library has to comply with the conditions of the GPL."
993 fi
994
995 # Give some feedback
996 echo   "                Configured for: $PRINTABLE_OS_NAME ($target)"
997 echo