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