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