cipher: Improve error handling.
[libgcrypt.git] / configure.ac
1 # Configure.ac script for Libgcrypt
2 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006,
3 #               2007, 2008, 2009, 2011 Free Software Foundation, Inc.
4 # Copyright (C) 2012, 2013  g10 Code GmbH
5 #
6 # This file is part of Libgcrypt.
7 #
8 # Libgcrypt is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Lesser General Public License as
10 # published by the Free Software Foundation; either version 2.1 of
11 # the License, or (at your option) any later version.
12 #
13 # Libgcrypt is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
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.14"
25
26 # To build a release you need to create a tag with the version number
27 # (git tag -s libgcrypt-n.m.k) and run "./autogen.sh --force".  Please
28 # bump the version number immediately after the release and do another
29 # commit and push so that the git magic is able to work.  See below
30 # for the LT versions.
31 m4_define(mym4_version_major, [1])
32 m4_define(mym4_version_minor, [7])
33 m4_define(mym4_version_micro, [0])
34
35 # Below is m4 magic to extract and compute the revision number, the
36 # decimalized short revision number, a beta version string, and a flag
37 # indicating a development version (mym4_isgit). Note that the m4
38 # processing is done by autoconf and not during the configure run.
39 m4_define(mym4_version,
40           [mym4_version_major.mym4_version_minor.mym4_version_micro])
41 m4_define([mym4_revision],
42           m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r']))
43 m4_define([mym4_revision_dec],
44           m4_esyscmd_s([echo $((0x$(echo ]mym4_revision[|head -c 4)))]))
45 m4_define([mym4_betastring],
46           m4_esyscmd_s([git describe --match 'libgcrypt-[0-9].*[0-9]' --long|\
47                         awk -F- '$3!=0{print"-beta"$3}']))
48 m4_define([mym4_isgit],m4_if(mym4_betastring,[],[no],[yes]))
49 m4_define([mym4_full_version],[mym4_version[]mym4_betastring])
50
51 AC_INIT([libgcrypt],[mym4_full_version],[http://bugs.gnupg.org])
52
53 # LT Version numbers, remember to change them just *before* a release.
54 # ====== NOTE: Already bumped to 21/1/0 for the 1.7.0 release. ====
55 #   (Interfaces removed:    CURRENT++, AGE=0, REVISION=0)
56 #   (Interfaces added:      CURRENT++, AGE++, REVISION=0)
57 #   (No interfaces changed:                   REVISION++)
58 LIBGCRYPT_LT_CURRENT=21
59 LIBGCRYPT_LT_AGE=1
60 LIBGCRYPT_LT_REVISION=0
61
62
63 # If the API is changed in an incompatible way: increment the next counter.
64 #
65 # 1.6: ABI and API change but the change is to most users irrelevant
66 #      and thus the API version number has not been incremented.
67 LIBGCRYPT_CONFIG_API_VERSION=1
68
69 # If you change the required gpg-error version, please remove
70 # unnecessary error code defines in src/gcrypt-int.h.
71 NEED_GPG_ERROR_VERSION=1.13
72
73 PACKAGE=$PACKAGE_NAME
74 VERSION=$PACKAGE_VERSION
75
76 AC_CONFIG_AUX_DIR([build-aux])
77 AC_CONFIG_SRCDIR([src/libgcrypt.vers])
78 AM_INIT_AUTOMAKE([serial-tests dist-bzip2])
79 AC_CONFIG_HEADER(config.h)
80 AC_CONFIG_MACRO_DIR([m4])
81 AC_CONFIG_LIBOBJ_DIR([compat])
82 AC_CANONICAL_HOST
83 AM_MAINTAINER_MODE
84 AM_SILENT_RULES
85
86 AC_ARG_VAR(SYSROOT,[locate config scripts also below that directory])
87
88 AH_TOP([
89 #ifndef _GCRYPT_CONFIG_H_INCLUDED
90 #define _GCRYPT_CONFIG_H_INCLUDED
91
92 /* Enable gpg-error's strerror macro for W32CE.  */
93 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
94 ])
95
96 AH_BOTTOM([
97 #define _GCRYPT_IN_LIBGCRYPT 1
98
99 /* If the configure check for endianness has been disabled, get it from
100    OS macros.  This is intended for making fat binary builds on OS X.  */
101 #ifdef DISABLED_ENDIAN_CHECK
102 # if defined(__BIG_ENDIAN__)
103 #  define WORDS_BIGENDIAN 1
104 # elif defined(__LITTLE_ENDIAN__)
105 #  undef WORDS_BIGENDIAN
106 # else
107 #  error "No endianness found"
108 # endif
109 #endif /*DISABLED_ENDIAN_CHECK*/
110
111 /* We basically use the original Camellia source.  Make sure the symbols
112    properly prefixed.  */
113 #define CAMELLIA_EXT_SYM_PREFIX _gcry_
114
115 #endif /*_GCRYPT_CONFIG_H_INCLUDED*/
116 ])
117
118 AH_VERBATIM([_REENTRANT],
119 [/* To allow the use of Libgcrypt in multithreaded programs we have to use
120     special features from the library. */
121 #ifndef _REENTRANT
122 # define _REENTRANT 1
123 #endif
124 ])
125
126
127 AC_SUBST(LIBGCRYPT_LT_CURRENT)
128 AC_SUBST(LIBGCRYPT_LT_AGE)
129 AC_SUBST(LIBGCRYPT_LT_REVISION)
130 AC_SUBST(PACKAGE)
131 AC_SUBST(VERSION)
132 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
133 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
134 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \
135                           mym4_version_minor mym4_version_micro)
136 AC_SUBST(VERSION_NUMBER)
137
138
139 ######################
140 ##  Basic checks.  ### (we need some results later on (e.g. $GCC)
141 ######################
142
143 AC_PROG_MAKE_SET
144 missing_dir=`cd $ac_aux_dir && pwd`
145 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
146 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
147 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
148 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
149 # AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
150 AC_PROG_CC
151 AC_PROG_CPP
152 AM_PROG_CC_C_O
153 AM_PROG_AS
154 AC_ISC_POSIX
155 AC_PROG_INSTALL
156 AC_PROG_AWK
157
158 AC_GNU_SOURCE
159
160 # We need to compile and run a program on the build machine.  A
161 # comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in
162 # the AC archive is broken for autoconf 2.57.  Given that there is no
163 # newer version of that macro, we assume that it is also broken for
164 # autoconf 2.61 and thus we use a simple but usually sufficient
165 # approach.
166 AC_MSG_CHECKING(for cc for build)
167 if test "$cross_compiling" = "yes"; then
168   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
169 else
170   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
171 fi
172 AC_MSG_RESULT($CC_FOR_BUILD)
173 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
174
175
176 LT_PREREQ([2.2.6])
177 LT_INIT([win32-dll disable-static])
178 LT_LANG([Windows Resource])
179
180
181 ##########################
182 ## General definitions. ##
183 ##########################
184
185 # Used by libgcrypt-config
186 LIBGCRYPT_CONFIG_LIBS="-lgcrypt"
187 LIBGCRYPT_CONFIG_CFLAGS=""
188 LIBGCRYPT_CONFIG_HOST="$host"
189
190 # Definitions for symmetric ciphers.
191 available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed"
192 available_ciphers="$available_ciphers camellia idea salsa20 gost28147 chacha20"
193 enabled_ciphers=""
194
195 # Definitions for public-key ciphers.
196 available_pubkey_ciphers="dsa elgamal rsa ecc"
197 enabled_pubkey_ciphers=""
198
199 # Definitions for message digests.
200 available_digests="crc gostr3411-94 md2 md4 md5 rmd160 sha1 sha256"
201 available_digests_64="sha512 sha3 tiger whirlpool stribog"
202 enabled_digests=""
203
204 # Definitions for kdfs (optional ones)
205 available_kdfs="s2k pkdf2"
206 available_kdfs_64="scrypt"
207 enabled_kdfs=""
208
209 # Definitions for random modules.
210 available_random_modules="linux egd unix"
211 auto_random_modules="$available_random_modules"
212
213 # Supported thread backends.
214 LIBGCRYPT_THREAD_MODULES=""
215
216 # Other definitions.
217 print_egd_notice=no
218 have_w32_system=no
219 have_w32ce_system=no
220 have_pthread=no
221
222
223 # Setup some stuff depending on host.
224 case "${host}" in
225     *-*-mingw32*)
226       ac_cv_have_dev_random=no
227       have_w32_system=yes
228       case "${host}" in
229         *-mingw32ce*)
230             have_w32ce_system=yes
231             available_random_modules="w32ce"
232             ;;
233         *)
234             available_random_modules="w32"
235             ;;
236       esac
237       AC_DEFINE(USE_ONLY_8DOT3,1,
238                 [set this to limit filenames to the 8.3 format])
239       AC_DEFINE(HAVE_DRIVE_LETTERS,1,
240                 [defined if we must run on a stupid file system])
241       AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
242                 [defined if we run on some of the PCDOS like systems
243                  (DOS, Windoze. OS/2) with special properties like
244                   no file modes])
245       ;;
246
247     i?86-emx-os2 | i?86-*-os2*emx)
248         # OS/2 with the EMX environment
249         ac_cv_have_dev_random=no
250         AC_DEFINE(HAVE_DRIVE_LETTERS)
251         AC_DEFINE(HAVE_DOSISH_SYSTEM)
252         ;;
253
254     i?86-*-msdosdjgpp*)
255         # DOS with the DJGPP environment
256         ac_cv_have_dev_random=no
257         AC_DEFINE(HAVE_DRIVE_LETTERS)
258         AC_DEFINE(HAVE_DOSISH_SYSTEM)
259         ;;
260
261     *-*-hpux*)
262         if test -z "$GCC" ; then
263             CFLAGS="$CFLAGS -Ae -D_HPUX_SOURCE"
264         fi
265         ;;
266     *-dec-osf4*)
267         if test -z "$GCC" ; then
268             # Suppress all warnings
269             # to get rid of the unsigned/signed char mismatch warnings.
270             CFLAGS="$CFLAGS -w"
271         fi
272         ;;
273     m68k-atari-mint)
274         ;;
275     *)
276       ;;
277 esac
278
279 if test "$have_w32_system" = yes; then
280    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
281    if test "$have_w32ce_system" = yes; then
282      AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
283    fi
284 fi
285 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
286 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
287
288
289
290 # A printable OS Name is sometimes useful.
291 case "${host}" in
292     *-*-mingw32ce*)
293         PRINTABLE_OS_NAME="W32CE"
294         ;;
295
296     *-*-mingw32*)
297         PRINTABLE_OS_NAME="W32"
298         ;;
299
300     i?86-emx-os2 | i?86-*-os2*emx )
301         PRINTABLE_OS_NAME="OS/2"
302         ;;
303
304     i?86-*-msdosdjgpp*)
305         PRINTABLE_OS_NAME="MSDOS/DJGPP"
306         ;;
307
308     *-linux*)
309         PRINTABLE_OS_NAME="GNU/Linux"
310         ;;
311
312     *)
313         PRINTABLE_OS_NAME=`uname -s || echo "Unknown"`
314         ;;
315 esac
316
317 #
318 # Figure out the name of the random device
319 #
320 case "${host}" in
321     *-openbsd*)
322         NAME_OF_DEV_RANDOM="/dev/srandom"
323         NAME_OF_DEV_URANDOM="/dev/urandom"
324         ;;
325
326     *)
327         NAME_OF_DEV_RANDOM="/dev/random"
328         NAME_OF_DEV_URANDOM="/dev/urandom"
329         ;;
330 esac
331
332
333 AC_ARG_ENABLE(endian-check,
334               AC_HELP_STRING([--disable-endian-check],
335               [disable the endian check and trust the OS provided macros]),
336               endiancheck=$enableval,endiancheck=yes)
337 if test x"$endiancheck" = xyes ; then
338   AC_C_BIGENDIAN
339 else
340   AC_DEFINE(DISABLED_ENDIAN_CHECK,1,[configure did not test for endianess])
341 fi
342
343 AC_CHECK_SIZEOF(unsigned short, 2)
344 AC_CHECK_SIZEOF(unsigned int, 4)
345 AC_CHECK_SIZEOF(unsigned long, 4)
346 AC_CHECK_SIZEOF(unsigned long long, 0)
347 AC_CHECK_SIZEOF(void *, 0)
348
349 AC_TYPE_UINTPTR_T
350
351 if test "$ac_cv_sizeof_unsigned_short" = "0" \
352    || test "$ac_cv_sizeof_unsigned_int" = "0" \
353    || test "$ac_cv_sizeof_unsigned_long" = "0"; then
354     AC_MSG_WARN([Hmmm, something is wrong with the sizes - using defaults]);
355 fi
356
357 # Ensure that we have UINT64_C before we bother to check for uint64_t
358 AC_CACHE_CHECK([for UINT64_C],[gnupg_cv_uint64_c_works],
359    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <inttypes.h>]],
360        [[uint64_t foo=UINT64_C(42);]])],
361      gnupg_cv_uint64_c_works=yes,gnupg_cv_uint64_c_works=no))
362 if test "$gnupg_cv_uint64_c_works" = "yes" ; then
363    AC_CHECK_SIZEOF(uint64_t)
364 fi
365
366 # Do we have any 64-bit data types?
367 if test "$ac_cv_sizeof_unsigned_int" != "8" \
368    && test "$ac_cv_sizeof_unsigned_long" != "8" \
369    && test "$ac_cv_sizeof_unsigned_long_long" != "8" \
370    && test "$ac_cv_sizeof_uint64_t" != "8"; then
371     AC_MSG_WARN([No 64-bit types.  Disabling TIGER/192, SCRYPT, SHA-384, \
372  SHA-512 and GOST R 34.11-12])
373 else
374   available_digests="$available_digests $available_digests_64"
375   available_kdfs="$available_kdfs $available_kdfs_64"
376 fi
377
378 # If not specified otherwise, all available algorithms will be
379 # included.
380 default_ciphers="$available_ciphers"
381 default_pubkey_ciphers="$available_pubkey_ciphers"
382 default_digests="$available_digests"
383 default_kdfs="$available_kdfs"
384 # Blacklist MD2 by default
385 default_digests=`echo $default_digests | sed -e 's/md2//g'`
386
387 # Substitutions to set generated files in a Emacs buffer to read-only.
388 AC_SUBST(emacs_local_vars_begin, ['Local Variables:'])
389 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
390 AC_SUBST(emacs_local_vars_end, ['End:'])
391
392 ############################
393 ## Command line switches. ##
394 ############################
395
396 # Implementation of the --enable-ciphers switch.
397 AC_ARG_ENABLE(ciphers,
398               AC_HELP_STRING([--enable-ciphers=ciphers],
399                              [select the symmetric ciphers to include]),
400               [enabled_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
401               [enabled_ciphers=""])
402 if test "x$enabled_ciphers" = "x" \
403    -o "$enabled_ciphers" = "yes"  \
404    -o "$enabled_ciphers" = "no"; then
405    enabled_ciphers=$default_ciphers
406 fi
407 AC_MSG_CHECKING([which symmetric ciphers to include])
408 for cipher in $enabled_ciphers; do
409     LIST_MEMBER($cipher, $available_ciphers)
410     if test "$found" = "0"; then
411        AC_MSG_ERROR([unsupported cipher "$cipher" specified])
412     fi
413 done
414 AC_MSG_RESULT([$enabled_ciphers])
415
416 # Implementation of the --enable-pubkey-ciphers switch.
417 AC_ARG_ENABLE(pubkey-ciphers,
418               AC_HELP_STRING([--enable-pubkey-ciphers=ciphers],
419                              [select the public-key ciphers to include]),
420               [enabled_pubkey_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
421               [enabled_pubkey_ciphers=""])
422 if test "x$enabled_pubkey_ciphers" = "x" \
423    -o "$enabled_pubkey_ciphers" = "yes"  \
424    -o "$enabled_pubkey_ciphers" = "no"; then
425    enabled_pubkey_ciphers=$default_pubkey_ciphers
426 fi
427 AC_MSG_CHECKING([which public-key ciphers to include])
428 for cipher in $enabled_pubkey_ciphers; do
429     LIST_MEMBER($cipher, $available_pubkey_ciphers)
430     if test "$found" = "0"; then
431        AC_MSG_ERROR([unsupported public-key cipher specified])
432     fi
433 done
434 AC_MSG_RESULT([$enabled_pubkey_ciphers])
435
436 # Implementation of the --enable-digests switch.
437 AC_ARG_ENABLE(digests,
438               AC_HELP_STRING([--enable-digests=digests],
439                              [select the message digests to include]),
440               [enabled_digests=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
441               [enabled_digests=""])
442 if test "x$enabled_digests" = "x" \
443    -o "$enabled_digests" = "yes"  \
444    -o "$enabled_digests" = "no"; then
445    enabled_digests=$default_digests
446 fi
447 AC_MSG_CHECKING([which message digests to include])
448 for digest in $enabled_digests; do
449     LIST_MEMBER($digest, $available_digests)
450     if test "$found" = "0"; then
451        AC_MSG_ERROR([unsupported message digest specified])
452     fi
453 done
454 AC_MSG_RESULT([$enabled_digests])
455
456 # Implementation of the --enable-kdfs switch.
457 AC_ARG_ENABLE(kdfs,
458       AC_HELP_STRING([--enable-kfds=kdfs],
459                      [select the KDFs to include]),
460       [enabled_kdfs=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
461       [enabled_kdfs=""])
462 if test "x$enabled_kdfs" = "x" \
463    -o "$enabled_kdfs" = "yes"  \
464    -o "$enabled_kdfs" = "no"; then
465    enabled_kdfs=$default_kdfs
466 fi
467 AC_MSG_CHECKING([which key derivation functions to include])
468 for kdf in $enabled_kdfs; do
469     LIST_MEMBER($kdf, $available_kdfs)
470     if test "$found" = "0"; then
471        AC_MSG_ERROR([unsupported key derivation function specified])
472     fi
473 done
474 AC_MSG_RESULT([$enabled_kdfs])
475
476 # Implementation of the --enable-random switch.
477 AC_ARG_ENABLE(random,
478               AC_HELP_STRING([--enable-random=name],
479                              [select which random number generator to use]),
480               [random=`echo $enableval | tr '[A-Z]' '[a-z]'`],
481               [])
482 if test "x$random" = "x" -o "$random" = "yes" -o "$random" = "no"; then
483     random=default
484 fi
485 AC_MSG_CHECKING([which random module to use])
486 if test "$random" != "default" -a "$random" != "auto"; then
487     LIST_MEMBER($random, $available_random_modules)
488     if test "$found" = "0"; then
489        AC_MSG_ERROR([unsupported random module specified])
490     fi
491 fi
492 AC_MSG_RESULT($random)
493
494 # Implementation of the --disable-dev-random switch.
495 AC_MSG_CHECKING([whether use of /dev/random is requested])
496 AC_ARG_ENABLE(dev-random,
497 [  --disable-dev-random    disable the use of dev random],
498     try_dev_random=$enableval, try_dev_random=yes)
499 AC_MSG_RESULT($try_dev_random)
500
501 # Implementation of the --with-egd-socket switch.
502 AC_ARG_WITH(egd-socket,
503     [  --with-egd-socket=NAME  Use NAME for the EGD socket)],
504             egd_socket_name="$withval", egd_socket_name="" )
505 AC_DEFINE_UNQUOTED(EGD_SOCKET_NAME, "$egd_socket_name",
506                    [Define if you don't want the default EGD socket name.
507                     For details see cipher/rndegd.c])
508
509 # Implementation of the --enable-random-daemon
510 AC_MSG_CHECKING([whether the experimental random daemon is requested])
511 AC_ARG_ENABLE([random-daemon],
512               AC_HELP_STRING([--enable-random-daemon],
513                              [Build and support the experimental gcryptrnd]),
514               [use_random_daemon=$enableval],
515               [use_random_daemon=no])
516 AC_MSG_RESULT($use_random_daemon)
517 if test x$use_random_daemon = xyes ; then
518     AC_DEFINE(USE_RANDOM_DAEMON,1,
519               [Define to support the experimental random daemon])
520 fi
521 AM_CONDITIONAL(USE_RANDOM_DAEMON, test x$use_random_daemon = xyes)
522
523
524 # Implementation of --disable-asm.
525 AC_MSG_CHECKING([whether MPI assembler modules are requested])
526 AC_ARG_ENABLE([asm],
527               AC_HELP_STRING([--disable-asm],
528                              [Disable MPI assembler modules]),
529               [try_asm_modules=$enableval],
530               [try_asm_modules=yes])
531 AC_MSG_RESULT($try_asm_modules)
532
533 # Implementation of the --enable-m-guard switch.
534 AC_MSG_CHECKING([whether memory guard is requested])
535 AC_ARG_ENABLE(m-guard,
536               AC_HELP_STRING([--enable-m-guard],
537                              [Enable memory guard facility]),
538               [use_m_guard=$enableval], [use_m_guard=no])
539 AC_MSG_RESULT($use_m_guard)
540 if test "$use_m_guard" = yes ; then
541     AC_DEFINE(M_GUARD,1,[Define to use the (obsolete) malloc guarding feature])
542 fi
543
544 # Implementation of the --enable-large-data-tests switch.
545 AC_MSG_CHECKING([whether to run large data tests])
546 AC_ARG_ENABLE(large-data-tests,
547               AC_HELP_STRING([--enable-large-data-tests],
548                  [Enable the real long ruinning large data tests]),
549               large_data_tests=$enableval,large_data_tests=no)
550 AC_MSG_RESULT($large_data_tests)
551 AC_SUBST(RUN_LARGE_DATA_TESTS, $large_data_tests)
552
553
554 # Implementation of the --with-capabilities switch.
555 # Check whether we want to use Linux capabilities
556 AC_MSG_CHECKING([whether use of capabilities is requested])
557 AC_ARG_WITH(capabilities,
558             AC_HELP_STRING([--with-capabilities],
559                            [Use linux capabilities [default=no]]),
560             [use_capabilities="$withval"],[use_capabilities=no])
561 AC_MSG_RESULT($use_capabilities)
562
563 # Implementation of the --enable-hmac-binary-check.
564 AC_MSG_CHECKING([whether a HMAC binary check is requested])
565 AC_ARG_ENABLE(hmac-binary-check,
566               AC_HELP_STRING([--enable-hmac-binary-check],
567                              [Enable library integrity check]),
568               [use_hmac_binary_check=$enableval],
569               [use_hmac_binary_check=no])
570 AC_MSG_RESULT($use_hmac_binary_check)
571 if test "$use_hmac_binary_check" = yes ; then
572     AC_DEFINE(ENABLE_HMAC_BINARY_CHECK,1,
573               [Define to support an HMAC based integrity check])
574 fi
575
576
577 # Implementation of the --disable-padlock-support switch.
578 AC_MSG_CHECKING([whether padlock support is requested])
579 AC_ARG_ENABLE(padlock-support,
580               AC_HELP_STRING([--disable-padlock-support],
581                  [Disable support for the PadLock Engine of VIA processors]),
582               padlocksupport=$enableval,padlocksupport=yes)
583 AC_MSG_RESULT($padlocksupport)
584
585 # Implementation of the --disable-aesni-support switch.
586 AC_MSG_CHECKING([whether AESNI support is requested])
587 AC_ARG_ENABLE(aesni-support,
588               AC_HELP_STRING([--disable-aesni-support],
589                  [Disable support for the Intel AES-NI instructions]),
590               aesnisupport=$enableval,aesnisupport=yes)
591 AC_MSG_RESULT($aesnisupport)
592
593 # Implementation of the --disable-pclmul-support switch.
594 AC_MSG_CHECKING([whether PCLMUL support is requested])
595 AC_ARG_ENABLE(pclmul-support,
596               AC_HELP_STRING([--disable-pclmul-support],
597                  [Disable support for the Intel PCLMUL instructions]),
598               pclmulsupport=$enableval,pclmulsupport=yes)
599 AC_MSG_RESULT($pclmulsupport)
600
601 # Implementation of the --disable-drng-support switch.
602 AC_MSG_CHECKING([whether DRNG support is requested])
603 AC_ARG_ENABLE(drng-support,
604               AC_HELP_STRING([--disable-drng-support],
605                  [Disable support for the Intel DRNG (RDRAND instruction)]),
606               drngsupport=$enableval,drngsupport=yes)
607 AC_MSG_RESULT($drngsupport)
608
609 # Implementation of the --disable-avx-support switch.
610 AC_MSG_CHECKING([whether AVX support is requested])
611 AC_ARG_ENABLE(avx-support,
612               AC_HELP_STRING([--disable-avx-support],
613                  [Disable support for the Intel AVX instructions]),
614               avxsupport=$enableval,avxsupport=yes)
615 AC_MSG_RESULT($avxsupport)
616
617 # Implementation of the --disable-avx2-support switch.
618 AC_MSG_CHECKING([whether AVX2 support is requested])
619 AC_ARG_ENABLE(avx2-support,
620               AC_HELP_STRING([--disable-avx2-support],
621                  [Disable support for the Intel AVX2 instructions]),
622               avx2support=$enableval,avx2support=yes)
623 AC_MSG_RESULT($avx2support)
624
625 # Implementation of the --disable-neon-support switch.
626 AC_MSG_CHECKING([whether NEON support is requested])
627 AC_ARG_ENABLE(neon-support,
628               AC_HELP_STRING([--disable-neon-support],
629                  [Disable support for the ARM NEON instructions]),
630               neonsupport=$enableval,neonsupport=yes)
631 AC_MSG_RESULT($neonsupport)
632
633 # Implementation of the --disable-O-flag-munging switch.
634 AC_MSG_CHECKING([whether a -O flag munging is requested])
635 AC_ARG_ENABLE([O-flag-munging],
636               AC_HELP_STRING([--disable-O-flag-munging],
637                  [Disable modification of the cc -O flag]),
638               [enable_o_flag_munging=$enableval],
639               [enable_o_flag_munging=yes])
640 AC_MSG_RESULT($enable_o_flag_munging)
641 AM_CONDITIONAL(ENABLE_O_FLAG_MUNGING, test "$enable_o_flag_munging" = "yes")
642
643 # Implementation of the --disable-amd64-as-feature-detection switch.
644 AC_MSG_CHECKING([whether to enable AMD64 as(1) feature detection])
645 AC_ARG_ENABLE(amd64-as-feature-detection,
646               AC_HELP_STRING([--disable-amd64-as-feature-detection],
647                  [Disable the auto-detection of AMD64 as(1) features]),
648               amd64_as_feature_detection=$enableval,
649               amd64_as_feature_detection=yes)
650 AC_MSG_RESULT($amd64_as_feature_detection)
651
652
653 AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
654                    [A human readable text with the name of the OS])
655
656 # For some systems we know that we have ld_version scripts.
657 # Use it then as default.
658 have_ld_version_script=no
659 case "${host}" in
660     *-*-linux*)
661         have_ld_version_script=yes
662         ;;
663     *-*-gnu*)
664         have_ld_version_script=yes
665         ;;
666 esac
667 AC_ARG_ENABLE([ld-version-script],
668               AC_HELP_STRING([--enable-ld-version-script],
669                              [enable/disable use of linker version script.
670                               (default is system dependent)]),
671               [have_ld_version_script=$enableval],
672               [ : ] )
673 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
674
675 AC_DEFINE_UNQUOTED(NAME_OF_DEV_RANDOM, "$NAME_OF_DEV_RANDOM",
676                    [defined to the name of the strong random device])
677 AC_DEFINE_UNQUOTED(NAME_OF_DEV_URANDOM, "$NAME_OF_DEV_URANDOM",
678                    [defined to the name of the weaker random device])
679
680
681 ###############################
682 #### Checks for libraries. ####
683 ###############################
684
685 #
686 # gpg-error is required.
687 #
688 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
689 if test "x$GPG_ERROR_LIBS" = "x"; then
690   AC_MSG_ERROR([libgpg-error is needed.
691                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
692 fi
693
694 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GCRYPT,
695           [The default error source for libgcrypt.])
696
697 #
698 # Check whether the GNU Pth library is available.  We require this
699 # to build the optional gcryptrnd program.
700 #
701 AC_ARG_WITH(pth-prefix,
702             AC_HELP_STRING([--with-pth-prefix=PFX],
703                            [prefix where GNU Pth is installed (optional)]),
704      pth_config_prefix="$withval", pth_config_prefix="")
705 if test x$pth_config_prefix != x ; then
706    PTH_CONFIG="$pth_config_prefix/bin/pth-config"
707 fi
708 if test "$use_random_daemon" = "yes"; then
709   AC_PATH_PROG(PTH_CONFIG, pth-config, no)
710   if test "$PTH_CONFIG" = "no"; then
711     AC_MSG_WARN([[
712 ***
713 *** To build the Libgcrypt's random number daemon
714 *** we need the support of the GNU Portable Threads Library.
715 *** Download it from ftp://ftp.gnu.org/gnu/pth/
716 *** On a Debian GNU/Linux system you might want to try
717 ***   apt-get install libpth-dev
718 ***]])
719   else
720     GNUPG_PTH_VERSION_CHECK([1.3.7])
721     if test $have_pth = yes; then
722        PTH_CFLAGS=`$PTH_CONFIG --cflags`
723        PTH_LIBS=`$PTH_CONFIG --ldflags`
724        PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`"
725        AC_DEFINE(USE_GNU_PTH, 1,
726                 [Defined if the GNU Portable Thread Library should be used])
727        AC_DEFINE(HAVE_PTH, 1,
728                 [Defined if the GNU Pth is available])
729     fi
730   fi
731 fi
732 AC_SUBST(PTH_CFLAGS)
733 AC_SUBST(PTH_LIBS)
734
735 #
736 # Check whether pthreads is available
737 #
738 if test "$have_w32_system" != yes; then
739   AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
740   if test "$have_pthread" = yes; then
741     AC_DEFINE(HAVE_PTHREAD, 1 ,[Define if we have pthread.])
742   fi
743 fi
744
745
746 # Solaris needs -lsocket and -lnsl. Unisys system includes
747 # gethostbyname in libsocket but needs libnsl for socket.
748 AC_SEARCH_LIBS(setsockopt, [socket], ,
749         [AC_SEARCH_LIBS(setsockopt, [socket], , , [-lnsl])])
750 AC_SEARCH_LIBS(setsockopt, [nsl])
751
752 ##################################
753 #### Checks for header files. ####
754 ##################################
755
756 AC_HEADER_STDC
757 AC_CHECK_HEADERS(unistd.h sys/select.h sys/msg.h)
758 INSERT_SYS_SELECT_H=
759 if test x"$ac_cv_header_sys_select_h" = xyes; then
760   INSERT_SYS_SELECT_H=" include <sys/select.h>"
761 fi
762 AC_SUBST(INSERT_SYS_SELECT_H)
763
764
765 ##########################################
766 #### Checks for typedefs, structures, ####
767 ####  and compiler characteristics.   ####
768 ##########################################
769
770 AC_C_CONST
771 AC_C_INLINE
772 AC_TYPE_SIZE_T
773 AC_TYPE_SIGNAL
774 AC_DECL_SYS_SIGLIST
775 AC_TYPE_PID_T
776
777 GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF)
778 GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF)
779 GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF)
780 GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF)
781 GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)
782
783 gl_TYPE_SOCKLEN_T
784 case "${host}" in
785   *-*-mingw32*)
786     # socklen_t may or may not be defined depending on what headers
787     # are included.  To be safe we use int as this is the actual type.
788     FALLBACK_SOCKLEN_T="typedef int gcry_socklen_t;"
789     ;;
790   *)
791     if test ".$gl_cv_socklen_t_equiv" = "."; then
792       FALLBACK_SOCKLEN_T="typedef socklen_t gcry_socklen_t;"
793     else
794       FALLBACK_SOCKLEN_T="typedef ${gl_cv_socklen_t_equiv} gcry_socklen_t;"
795     fi
796 esac
797 AC_SUBST(FALLBACK_SOCKLEN_T)
798
799
800 #
801 # Check for __builtin_bswap32 intrinsic.
802 #
803 AC_CACHE_CHECK(for __builtin_bswap32,
804        [gcry_cv_have_builtin_bswap32],
805        [gcry_cv_have_builtin_bswap32=no
806         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
807           [int x = 0; int y = __builtin_bswap32(x); return y;])],
808           [gcry_cv_have_builtin_bswap32=yes])])
809 if test "$gcry_cv_have_builtin_bswap32" = "yes" ; then
810    AC_DEFINE(HAVE_BUILTIN_BSWAP32,1,
811              [Defined if compiler has '__builtin_bswap32' intrinsic])
812 fi
813
814
815 #
816 # Check for __builtin_bswap64 intrinsic.
817 #
818 AC_CACHE_CHECK(for __builtin_bswap64,
819        [gcry_cv_have_builtin_bswap64],
820        [gcry_cv_have_builtin_bswap64=no
821         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
822           [long long x = 0; long long y = __builtin_bswap64(x); return y;])],
823           [gcry_cv_have_builtin_bswap64=yes])])
824 if test "$gcry_cv_have_builtin_bswap64" = "yes" ; then
825    AC_DEFINE(HAVE_BUILTIN_BSWAP64,1,
826              [Defined if compiler has '__builtin_bswap64' intrinsic])
827 fi
828
829
830 #
831 # Check for __builtin_ctz intrinsic.
832 #
833 AC_CACHE_CHECK(for __builtin_ctz,
834        [gcry_cv_have_builtin_ctz],
835        [gcry_cv_have_builtin_ctz=no
836         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
837           [unsigned int x = 0; int y = __builtin_ctz(x); return y;])],
838           [gcry_cv_have_builtin_ctz=yes])])
839 if test "$gcry_cv_have_builtin_ctz" = "yes" ; then
840    AC_DEFINE(HAVE_BUILTIN_CTZ, 1,
841              [Defined if compiler has '__builtin_ctz' intrinsic])
842 fi
843
844
845 #
846 # Check for VLA support (variable length arrays).
847 #
848 AC_CACHE_CHECK(whether the variable length arrays are supported,
849        [gcry_cv_have_vla],
850        [gcry_cv_have_vla=no
851         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
852           [[void f1(char *, int);
853             char foo(int i) {
854               char b[(i < 0 ? 0 : i) + 1];
855               f1(b, sizeof b); return b[0];}]])],
856           [gcry_cv_have_vla=yes])])
857 if test "$gcry_cv_have_vla" = "yes" ; then
858    AC_DEFINE(HAVE_VLA,1, [Defined if variable length arrays are supported])
859 fi
860
861
862 #
863 # Check for ELF visibility support.
864 #
865 AC_CACHE_CHECK(whether the visibility attribute is supported,
866        gcry_cv_visibility_attribute,
867        [gcry_cv_visibility_attribute=no
868         AC_LANG_CONFTEST([AC_LANG_SOURCE(
869           [[int foo __attribute__ ((visibility ("hidden"))) = 1;
870             int bar __attribute__ ((visibility ("protected"))) = 1;
871           ]])])
872
873         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
874                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
875             if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
876                 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
877                     gcry_cv_visibility_attribute=yes
878                 fi
879             fi
880         fi
881        ])
882 if test "$gcry_cv_visibility_attribute" = "yes"; then
883     AC_CACHE_CHECK(for broken visibility attribute,
884        gcry_cv_broken_visibility_attribute,
885        [gcry_cv_broken_visibility_attribute=yes
886         AC_LANG_CONFTEST([AC_LANG_SOURCE(
887           [[int foo (int x);
888             int bar (int x) __asm__ ("foo")
889                             __attribute__ ((visibility ("hidden")));
890             int bar (int x) { return x; }
891           ]])])
892
893         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
894                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
895            if grep '\.hidden@<:@        _@:>@foo' conftest.s >/dev/null 2>&1;
896             then
897                gcry_cv_broken_visibility_attribute=no
898            fi
899         fi
900        ])
901 fi
902 if test "$gcry_cv_visibility_attribute" = "yes"; then
903     AC_CACHE_CHECK(for broken alias attribute,
904        gcry_cv_broken_alias_attribute,
905        [gcry_cv_broken_alias_attribute=yes
906         AC_LANG_CONFTEST([AC_LANG_SOURCE(
907           [[extern int foo (int x) __asm ("xyzzy");
908             int bar (int x) { return x; }
909             extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
910             extern int dfoo;
911             extern __typeof (dfoo) dfoo __asm ("abccb");
912             int dfoo = 1;
913           ]])])
914
915         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
916                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
917            if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
918               grep 'abccb' conftest.s >/dev/null 2>&1; then
919               gcry_cv_broken_alias_attribute=no
920            fi
921         fi
922         ])
923 fi
924 if test "$gcry_cv_visibility_attribute" = "yes"; then
925     AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
926        gcry_cv_gcc_has_f_visibility,
927        [gcry_cv_gcc_has_f_visibility=no
928         _gcc_cflags_save=$CFLAGS
929         CFLAGS="-fvisibility=hidden"
930         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
931                           gcry_cv_gcc_has_f_visibility=yes)
932         CFLAGS=$_gcc_cflags_save;
933        ])
934 fi
935 if test "$gcry_cv_visibility_attribute" = "yes" \
936    && test "$gcry_cv_broken_visibility_attribute" != "yes" \
937    && test "$gcry_cv_broken_alias_attribute" != "yes" \
938    && test "$gcry_cv_gcc_has_f_visibility" = "yes"
939  then
940    AC_DEFINE(GCRY_USE_VISIBILITY, 1,
941                [Define to use the GNU C visibility attribute.])
942    CFLAGS="$CFLAGS -fvisibility=hidden"
943 fi
944
945
946 #
947 # Check whether the compiler supports the GCC style aligned attribute
948 #
949 AC_CACHE_CHECK([whether the GCC style aligned attribute is supported],
950        [gcry_cv_gcc_attribute_aligned],
951        [gcry_cv_gcc_attribute_aligned=no
952         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
953           [[struct { int a; } foo __attribute__ ((aligned (16)));]])],
954           [gcry_cv_gcc_attribute_aligned=yes])])
955 if test "$gcry_cv_gcc_attribute_aligned" = "yes" ; then
956    AC_DEFINE(HAVE_GCC_ATTRIBUTE_ALIGNED,1,
957      [Defined if a GCC style "__attribute__ ((aligned (n))" is supported])
958 fi
959
960
961 #
962 # Check whether the compiler supports the GCC style packed attribute
963 #
964 AC_CACHE_CHECK([whether the GCC style packed attribute is supported],
965        [gcry_cv_gcc_attribute_packed],
966        [gcry_cv_gcc_attribute_packed=no
967         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
968           [[struct foolong_s { long b; } __attribute__ ((packed));
969             struct foo_s { char a; struct foolong_s b; }
970               __attribute__ ((packed));
971             enum bar {
972               FOO = 1 / (sizeof(struct foo_s) == (sizeof(char) + sizeof(long))),
973             };]])],
974           [gcry_cv_gcc_attribute_packed=yes])])
975 if test "$gcry_cv_gcc_attribute_packed" = "yes" ; then
976    AC_DEFINE(HAVE_GCC_ATTRIBUTE_PACKED,1,
977      [Defined if a GCC style "__attribute__ ((packed))" is supported])
978 fi
979
980
981 #
982 # Check whether the compiler supports 'asm' or '__asm__' keyword for
983 # assembler blocks.
984 #
985 AC_CACHE_CHECK([whether 'asm' assembler keyword is supported],
986        [gcry_cv_have_asm],
987        [gcry_cv_have_asm=no
988         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
989           [[void a(void) { asm("":::"memory"); }]])],
990           [gcry_cv_have_asm=yes])])
991 AC_CACHE_CHECK([whether '__asm__' assembler keyword is supported],
992        [gcry_cv_have___asm__],
993        [gcry_cv_have___asm__=no
994         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
995           [[void a(void) { __asm__("":::"memory"); }]])],
996           [gcry_cv_have___asm__=yes])])
997 if test "$gcry_cv_have_asm" = "no" ; then
998    if test "$gcry_cv_have___asm__" = "yes" ; then
999       AC_DEFINE(asm,__asm__,
1000         [Define to supported assembler block keyword, if plain 'asm' was not
1001          supported])
1002    fi
1003 fi
1004
1005
1006 #
1007 # Check whether the compiler supports inline assembly memory barrier.
1008 #
1009 if test "$gcry_cv_have_asm" = "no" ; then
1010    if test "$gcry_cv_have___asm__" = "yes" ; then
1011       AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
1012           [gcry_cv_have_asm_volatile_memory],
1013           [gcry_cv_have_asm_volatile_memory=no
1014            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1015              [[void a(void) { __asm__ volatile("":::"memory"); }]])],
1016              [gcry_cv_have_asm_volatile_memory=yes])])
1017    fi
1018 else
1019    AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
1020        [gcry_cv_have_asm_volatile_memory],
1021        [gcry_cv_have_asm_volatile_memory=no
1022         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1023           [[void a(void) { asm volatile("":::"memory"); }]])],
1024           [gcry_cv_have_asm_volatile_memory=yes])])
1025 fi
1026 if test "$gcry_cv_have_asm_volatile_memory" = "yes" ; then
1027    AC_DEFINE(HAVE_GCC_ASM_VOLATILE_MEMORY,1,
1028      [Define if inline asm memory barrier is supported])
1029 fi
1030
1031
1032 #
1033 # Check whether GCC assembler supports features needed for our ARM
1034 # implementations.  This needs to be done before setting up the
1035 # assembler stuff.
1036 #
1037 AC_CACHE_CHECK([whether GCC assembler is compatible for ARM assembly implementations],
1038        [gcry_cv_gcc_arm_platform_as_ok],
1039        [gcry_cv_gcc_arm_platform_as_ok=no
1040         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1041           [[__asm__(
1042                 /* Test if assembler supports UAL syntax.  */
1043                 ".syntax unified\n\t"
1044                 ".arm\n\t" /* our assembly code is in ARM mode  */
1045                 /* Following causes error if assembler ignored '.syntax unified'.  */
1046                 "asmfunc:\n\t"
1047                 "add %r0, %r0, %r4, ror #12;\n\t"
1048
1049                 /* Test if '.type' and '.size' are supported.  */
1050                 ".size asmfunc,.-asmfunc;\n\t"
1051                 ".type asmfunc,%function;\n\t"
1052             );]])],
1053           [gcry_cv_gcc_arm_platform_as_ok=yes])])
1054 if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
1055    AC_DEFINE(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS,1,
1056      [Defined if underlying assembler is compatible with ARM assembly implementations])
1057 fi
1058
1059
1060 #
1061 # Check whether underscores in symbols are required.  This needs to be
1062 # done before setting up the assembler stuff.
1063 #
1064 GNUPG_SYS_SYMBOL_UNDERSCORE()
1065
1066
1067 #################################
1068 ####                         ####
1069 #### Setup assembler stuff.  ####
1070 #### Define mpi_cpu_arch.    ####
1071 ####                         ####
1072 #################################
1073 AC_ARG_ENABLE(mpi-path,
1074               AC_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
1075               [prepend EXTRA_PATH to list of CPU specific optimizations]),
1076               mpi_extra_path="$enableval",mpi_extra_path="")
1077 AC_MSG_CHECKING(architecture and mpi assembler functions)
1078 if test -f $srcdir/mpi/config.links ; then
1079     . $srcdir/mpi/config.links
1080     AC_CONFIG_LINKS("$mpi_ln_list")
1081     ac_cv_mpi_sflags="$mpi_sflags"
1082     AC_MSG_RESULT($mpi_cpu_arch)
1083 else
1084     AC_MSG_RESULT(failed)
1085     AC_MSG_ERROR([mpi/config.links missing!])
1086 fi
1087 MPI_SFLAGS="$ac_cv_mpi_sflags"
1088 AC_SUBST(MPI_SFLAGS)
1089
1090 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
1091 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
1092 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
1093 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
1094 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
1095 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
1096 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
1097 AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
1098 AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
1099 AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
1100 AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
1101 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
1102 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
1103 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
1104 AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
1105 AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
1106 AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
1107 AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
1108
1109 # Reset non applicable feature flags.
1110 if test "$mpi_cpu_arch" != "x86" ; then
1111    aesnisupport="n/a"
1112    pclmulsupport="n/a"
1113    avxsupport="n/a"
1114    avx2support="n/a"
1115    padlocksupport="n/a"
1116    drngsupport="n/a"
1117 fi
1118
1119 if test "$mpi_cpu_arch" != "arm" ; then
1120    neonsupport="n/a"
1121 fi
1122
1123
1124 #############################################
1125 ####                                     ####
1126 #### Platform specific compiler checks.  ####
1127 ####                                     ####
1128 #############################################
1129
1130
1131 # Following tests depend on warnings to cause compile to fail, so set -Werror
1132 # temporarily.
1133 _gcc_cflags_save=$CFLAGS
1134 CFLAGS="$CFLAGS -Werror"
1135
1136
1137 #
1138 # Check whether compiler supports 'ms_abi' function attribute.
1139 #
1140 AC_CACHE_CHECK([whether compiler supports 'ms_abi' function attribute],
1141        [gcry_cv_gcc_attribute_ms_abi],
1142        [gcry_cv_gcc_attribute_ms_abi=no
1143         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1144           [[int __attribute__ ((ms_abi)) proto(int);]])],
1145           [gcry_cv_gcc_attribute_ms_abi=yes])])
1146 if test "$gcry_cv_gcc_attribute_ms_abi" = "yes" ; then
1147    AC_DEFINE(HAVE_GCC_ATTRIBUTE_MS_ABI,1,
1148      [Defined if compiler supports "__attribute__ ((ms_abi))" function attribute])
1149 fi
1150
1151
1152 #
1153 # Check whether compiler supports 'sysv_abi' function attribute.
1154 #
1155 AC_CACHE_CHECK([whether compiler supports 'sysv_abi' function attribute],
1156        [gcry_cv_gcc_attribute_sysv_abi],
1157        [gcry_cv_gcc_attribute_sysv_abi=no
1158         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1159           [[int __attribute__ ((sysv_abi)) proto(int);]])],
1160           [gcry_cv_gcc_attribute_sysv_abi=yes])])
1161 if test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" ; then
1162    AC_DEFINE(HAVE_GCC_ATTRIBUTE_SYSV_ABI,1,
1163      [Defined if compiler supports "__attribute__ ((sysv_abi))" function attribute])
1164 fi
1165
1166
1167 #
1168 # Check whether default calling convention is 'ms_abi'.
1169 #
1170 if test "$gcry_cv_gcc_attribute_ms_abi" = "yes" ; then
1171    AC_CACHE_CHECK([whether default calling convention is 'ms_abi'],
1172           [gcry_cv_gcc_default_abi_is_ms_abi],
1173           [gcry_cv_gcc_default_abi_is_ms_abi=no
1174            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1175              [[void *test(void) {
1176                  void *(*def_func)(void) = test;
1177                  void *__attribute__((ms_abi))(*msabi_func)(void);
1178                  /* warning on SysV abi targets, passes on Windows based targets */
1179                  msabi_func = def_func;
1180                  return msabi_func;
1181              }]])],
1182              [gcry_cv_gcc_default_abi_is_ms_abi=yes])])
1183    if test "$gcry_cv_gcc_default_abi_is_ms_abi" = "yes" ; then
1184       AC_DEFINE(HAVE_GCC_DEFAULT_ABI_IS_MS_ABI,1,
1185         [Defined if default calling convention is 'ms_abi'])
1186    fi
1187 fi
1188
1189
1190 #
1191 # Check whether default calling convention is 'sysv_abi'.
1192 #
1193 if test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" ; then
1194    AC_CACHE_CHECK([whether default calling convention is 'sysv_abi'],
1195           [gcry_cv_gcc_default_abi_is_sysv_abi],
1196           [gcry_cv_gcc_default_abi_is_sysv_abi=no
1197            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1198              [[void *test(void) {
1199                  void *(*def_func)(void) = test;
1200                  void *__attribute__((sysv_abi))(*sysvabi_func)(void);
1201                  /* warning on MS ABI targets, passes on SysV ABI targets */
1202                  sysvabi_func = def_func;
1203                  return sysvabi_func;
1204              }]])],
1205              [gcry_cv_gcc_default_abi_is_sysv_abi=yes])])
1206    if test "$gcry_cv_gcc_default_abi_is_sysv_abi" = "yes" ; then
1207       AC_DEFINE(HAVE_GCC_DEFAULT_ABI_IS_SYSV_ABI,1,
1208         [Defined if default calling convention is 'sysv_abi'])
1209    fi
1210 fi
1211
1212
1213 # Restore flags.
1214 CFLAGS=$_gcc_cflags_save;
1215
1216
1217 #
1218 # Check whether GCC inline assembler supports SSSE3 instructions
1219 # This is required for the AES-NI instructions.
1220 #
1221 AC_CACHE_CHECK([whether GCC inline assembler supports SSSE3 instructions],
1222        [gcry_cv_gcc_inline_asm_ssse3],
1223        [if test "$mpi_cpu_arch" != "x86" ; then
1224           gcry_cv_gcc_inline_asm_ssse3="n/a"
1225         else
1226           gcry_cv_gcc_inline_asm_ssse3=no
1227           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1228           [[static unsigned char be_mask[16] __attribute__ ((aligned (16))) =
1229               { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
1230             void a(void) {
1231               __asm__("pshufb %[mask], %%xmm2\n\t"::[mask]"m"(*be_mask):);
1232             }]])],
1233           [gcry_cv_gcc_inline_asm_ssse3=yes])
1234         fi])
1235 if test "$gcry_cv_gcc_inline_asm_ssse3" = "yes" ; then
1236    AC_DEFINE(HAVE_GCC_INLINE_ASM_SSSE3,1,
1237      [Defined if inline assembler supports SSSE3 instructions])
1238 fi
1239
1240
1241 #
1242 # Check whether GCC inline assembler supports PCLMUL instructions.
1243 #
1244 AC_CACHE_CHECK([whether GCC inline assembler supports PCLMUL instructions],
1245        [gcry_cv_gcc_inline_asm_pclmul],
1246        [if test "$mpi_cpu_arch" != "x86" ; then
1247           gcry_cv_gcc_inline_asm_pclmul="n/a"
1248         else
1249           gcry_cv_gcc_inline_asm_pclmul=no
1250           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1251           [[void a(void) {
1252               __asm__("pclmulqdq \$0, %%xmm1, %%xmm3\n\t":::"cc");
1253             }]])],
1254           [gcry_cv_gcc_inline_asm_pclmul=yes])
1255         fi])
1256 if test "$gcry_cv_gcc_inline_asm_pclmul" = "yes" ; then
1257    AC_DEFINE(HAVE_GCC_INLINE_ASM_PCLMUL,1,
1258      [Defined if inline assembler supports PCLMUL instructions])
1259 fi
1260
1261
1262 #
1263 # Check whether GCC inline assembler supports AVX instructions
1264 #
1265 AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions],
1266        [gcry_cv_gcc_inline_asm_avx],
1267        [if test "$mpi_cpu_arch" != "x86" ; then
1268           gcry_cv_gcc_inline_asm_avx="n/a"
1269         else
1270           gcry_cv_gcc_inline_asm_avx=no
1271           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1272           [[void a(void) {
1273               __asm__("xgetbv; vaesdeclast (%[mem]),%%xmm0,%%xmm7\n\t"::[mem]"r"(0):);
1274             }]])],
1275           [gcry_cv_gcc_inline_asm_avx=yes])
1276         fi])
1277 if test "$gcry_cv_gcc_inline_asm_avx" = "yes" ; then
1278    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX,1,
1279      [Defined if inline assembler supports AVX instructions])
1280 fi
1281
1282
1283 #
1284 # Check whether GCC inline assembler supports AVX2 instructions
1285 #
1286 AC_CACHE_CHECK([whether GCC inline assembler supports AVX2 instructions],
1287        [gcry_cv_gcc_inline_asm_avx2],
1288        [if test "$mpi_cpu_arch" != "x86" ; then
1289           gcry_cv_gcc_inline_asm_avx2="n/a"
1290         else
1291           gcry_cv_gcc_inline_asm_avx2=no
1292           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1293           [[void a(void) {
1294               __asm__("xgetbv; vpbroadcastb %%xmm7,%%ymm1\n\t":::"cc");
1295             }]])],
1296           [gcry_cv_gcc_inline_asm_avx2=yes])
1297         fi])
1298 if test "$gcry_cv_gcc_inline_asm_avx2" = "yes" ; then
1299    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX2,1,
1300      [Defined if inline assembler supports AVX2 instructions])
1301 fi
1302
1303
1304 #
1305 # Check whether GCC inline assembler supports BMI2 instructions
1306 #
1307 AC_CACHE_CHECK([whether GCC inline assembler supports BMI2 instructions],
1308        [gcry_cv_gcc_inline_asm_bmi2],
1309        [if test "$mpi_cpu_arch" != "x86" ; then
1310           gcry_cv_gcc_inline_asm_bmi2="n/a"
1311         else
1312           gcry_cv_gcc_inline_asm_bmi2=no
1313           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1314           [[void a(void) {
1315               __asm__("rorxl \$23, %%eax, %%edx\\n\\t":::"memory");
1316             }]])],
1317           [gcry_cv_gcc_inline_asm_bmi2=yes])
1318         fi])
1319 if test "$gcry_cv_gcc_inline_asm_bmi2" = "yes" ; then
1320    AC_DEFINE(HAVE_GCC_INLINE_ASM_BMI2,1,
1321      [Defined if inline assembler supports BMI2 instructions])
1322 fi
1323
1324
1325 #
1326 # Check whether GCC assembler needs "-Wa,--divide" to correctly handle
1327 # constant division
1328 #
1329 if test $amd64_as_feature_detection = yes; then
1330   AC_CACHE_CHECK([whether GCC assembler handles division correctly],
1331        [gcry_cv_gcc_as_const_division_ok],
1332        [gcry_cv_gcc_as_const_division_ok=no
1333         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1334           [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
1335           [gcry_cv_gcc_as_const_division_ok=yes])])
1336   if test "$gcry_cv_gcc_as_const_division_ok" = "no" ; then
1337     #
1338     # Add '-Wa,--divide' to CPPFLAGS and try check again.
1339     #
1340     _gcc_cppflags_save="$CPPFLAGS"
1341     CPPFLAGS="$CPPFLAGS -Wa,--divide"
1342     AC_CACHE_CHECK([whether GCC assembler handles division correctly with "-Wa,--divide"],
1343          [gcry_cv_gcc_as_const_division_with_wadivide_ok],
1344          [gcry_cv_gcc_as_const_division_with_wadivide_ok=no
1345           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1346             [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
1347             [gcry_cv_gcc_as_const_division_with_wadivide_ok=yes])])
1348     if test "$gcry_cv_gcc_as_const_division_with_wadivide_ok" = "no" ; then
1349       # '-Wa,--divide' did not work, restore old flags.
1350       CPPFLAGS="$_gcc_cppflags_save"
1351     fi
1352   fi
1353 fi
1354
1355
1356 #
1357 # Check whether GCC assembler supports features needed for our amd64
1358 # implementations
1359 #
1360 if test $amd64_as_feature_detection = yes; then
1361   AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
1362        [gcry_cv_gcc_amd64_platform_as_ok],
1363        [if test "$mpi_cpu_arch" != "x86" ; then
1364           gcry_cv_gcc_amd64_platform_as_ok="n/a"
1365         else
1366           gcry_cv_gcc_amd64_platform_as_ok=no
1367           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1368           [[__asm__(
1369                 /* Test if '.type' and '.size' are supported.  */
1370                 /* These work only on ELF targets. */
1371                 "asmfunc:\n\t"
1372                 ".size asmfunc,.-asmfunc;\n\t"
1373                 ".type asmfunc,@function;\n\t"
1374                 /* Test if assembler allows use of '/' for constant division
1375                  * (Solaris/x86 issue). If previous constant division check
1376                  * and "-Wa,--divide" workaround failed, this causes assembly
1377                  * to be disable on this machine. */
1378                 "xorl \$(123456789/12345678), %ebp;\n\t"
1379             );]])],
1380           [gcry_cv_gcc_amd64_platform_as_ok=yes])
1381         fi])
1382   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then
1383      AC_DEFINE(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS,1,
1384               [Defined if underlying assembler is compatible with amd64 assembly implementations])
1385   fi
1386   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "no" &&
1387      test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" &&
1388      test "$gcry_cv_gcc_default_abi_is_ms_abi" = "yes"; then
1389     AC_CACHE_CHECK([whether GCC assembler is compatible for WIN64 assembly implementations],
1390       [gcry_cv_gcc_win64_platform_as_ok],
1391       [gcry_cv_gcc_win64_platform_as_ok=no
1392       AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1393         [[__asm__(
1394               ".globl asmfunc\n\t"
1395               "asmfunc:\n\t"
1396               "xorq \$(1234), %rbp;\n\t"
1397           );]])],
1398         [gcry_cv_gcc_win64_platform_as_ok=yes])])
1399     if test "$gcry_cv_gcc_win64_platform_as_ok" = "yes" ; then
1400       AC_DEFINE(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS,1,
1401                 [Defined if underlying assembler is compatible with WIN64 assembly implementations])
1402     fi
1403   fi
1404 fi
1405
1406
1407 #
1408 # Check whether GCC assembler supports features needed for assembly
1409 # implementations that use Intel syntax
1410 #
1411 AC_CACHE_CHECK([whether GCC assembler is compatible for Intel syntax assembly implementations],
1412        [gcry_cv_gcc_platform_as_ok_for_intel_syntax],
1413        [if test "$mpi_cpu_arch" != "x86" ; then
1414           gcry_cv_gcc_platform_as_ok_for_intel_syntax="n/a"
1415         else
1416           gcry_cv_gcc_platform_as_ok_for_intel_syntax=no
1417           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1418           [[__asm__(
1419                 ".intel_syntax noprefix\n\t"
1420                 "pxor xmm1, xmm7;\n\t"
1421                 /* Intel syntax implementation also use GAS macros, so check
1422                  * for them here. */
1423                 "VAL_A = xmm4\n\t"
1424                 "VAL_B = xmm2\n\t"
1425                 ".macro SET_VAL_A p1\n\t"
1426                 "  VAL_A = \\\\p1 \n\t"
1427                 ".endm\n\t"
1428                 ".macro SET_VAL_B p1\n\t"
1429                 "  VAL_B = \\\\p1 \n\t"
1430                 ".endm\n\t"
1431                 "vmovdqa VAL_A, VAL_B;\n\t"
1432                 "SET_VAL_A eax\n\t"
1433                 "SET_VAL_B ebp\n\t"
1434                 "add VAL_A, VAL_B;\n\t"
1435                 "add VAL_B, 0b10101;\n\t"
1436             );]])],
1437           [gcry_cv_gcc_platform_as_ok_for_intel_syntax=yes])
1438         fi])
1439 if test "$gcry_cv_gcc_platform_as_ok_for_intel_syntax" = "yes" ; then
1440   AC_DEFINE(HAVE_INTEL_SYNTAX_PLATFORM_AS,1,
1441             [Defined if underlying assembler is compatible with Intel syntax assembly implementations])
1442 fi
1443
1444
1445 #
1446 # Check whether compiler is configured for ARMv6 or newer architecture
1447 #
1448 AC_CACHE_CHECK([whether compiler is configured for ARMv6 or newer architecture],
1449        [gcry_cv_cc_arm_arch_is_v6],
1450        [if test "$mpi_cpu_arch" != "arm" ; then
1451           gcry_cv_cc_arm_arch_is_v6="n/a"
1452         else
1453           gcry_cv_cc_arm_arch_is_v6=no
1454           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1455           [[
1456            #if defined(__arm__) && \
1457              ((defined(__ARM_ARCH) && __ARM_ARCH >= 6) \
1458              || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
1459              || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \
1460              || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) \
1461              || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
1462              || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
1463              || defined(__ARM_ARCH_7EM__))
1464              /* empty */
1465            #else
1466              /* fail compile if not ARMv6. */
1467              not_armv6 not_armv6 = (not_armv6)not_armv6;
1468            #endif
1469           ]])],
1470           [gcry_cv_cc_arm_arch_is_v6=yes])
1471         fi])
1472 if test "$gcry_cv_cc_arm_arch_is_v6" = "yes" ; then
1473    AC_DEFINE(HAVE_ARM_ARCH_V6,1,
1474      [Defined if ARM architecture is v6 or newer])
1475 fi
1476
1477
1478 #
1479 # Check whether GCC inline assembler supports NEON instructions
1480 #
1481 AC_CACHE_CHECK([whether GCC inline assembler supports NEON instructions],
1482        [gcry_cv_gcc_inline_asm_neon],
1483        [if test "$mpi_cpu_arch" != "arm" ; then
1484           gcry_cv_gcc_inline_asm_neon="n/a"
1485         else
1486           gcry_cv_gcc_inline_asm_neon=no
1487           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1488           [[__asm__(
1489                 ".syntax unified\n\t"
1490                 ".thumb\n\t"
1491                 ".fpu neon\n\t"
1492                 "vld1.64 {%q0-%q1}, [%r0]!;\n\t"
1493                 "vrev64.8 %q0, %q3;\n\t"
1494                 "vadd.u64 %q0, %q1;\n\t"
1495                 "vadd.s64 %d3, %d2, %d3;\n\t"
1496                 );
1497             ]])],
1498           [gcry_cv_gcc_inline_asm_neon=yes])
1499         fi])
1500 if test "$gcry_cv_gcc_inline_asm_neon" = "yes" ; then
1501    AC_DEFINE(HAVE_GCC_INLINE_ASM_NEON,1,
1502      [Defined if inline assembler supports NEON instructions])
1503 fi
1504
1505
1506 #######################################
1507 #### Checks for library functions. ####
1508 #######################################
1509
1510 AC_FUNC_VPRINTF
1511 # We have replacements for these in src/missing-string.c
1512 AC_CHECK_FUNCS(stpcpy strcasecmp)
1513 # We have replacements for these in src/g10lib.h
1514 AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise)
1515 # Other checks
1516 AC_CHECK_FUNCS(strerror rand mmap getpagesize sysconf waitpid wait4)
1517 AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime syslog)
1518 AC_CHECK_FUNCS(fcntl ftruncate flockfile)
1519
1520 GNUPG_CHECK_MLOCK
1521
1522 #
1523 # Replacement functions.
1524 #
1525 AC_REPLACE_FUNCS([getpid clock])
1526
1527
1528 #
1529 # Check wether it is necessary to link against libdl.
1530 #
1531 DL_LIBS=""
1532 if test "$use_hmac_binary_check" = yes ; then
1533   _gcry_save_libs="$LIBS"
1534   LIBS=""
1535   AC_SEARCH_LIBS(dlopen, c dl,,,)
1536   DL_LIBS=$LIBS
1537   LIBS="$_gcry_save_libs"
1538   LIBGCRYPT_CONFIG_LIBS="${LIBGCRYPT_CONFIG_LIBS} ${DL_LIBS}"
1539 fi
1540 AC_SUBST(DL_LIBS)
1541
1542
1543 #
1544 # Check whether we can use Linux capabilities as requested.
1545 #
1546 if test "$use_capabilities" = "yes" ; then
1547 use_capabilities=no
1548 AC_CHECK_HEADERS(sys/capability.h)
1549 if test "$ac_cv_header_sys_capability_h" = "yes" ; then
1550   AC_CHECK_LIB(cap, cap_init, ac_need_libcap=1)
1551   if test "$ac_cv_lib_cap_cap_init" = "yes"; then
1552      AC_DEFINE(USE_CAPABILITIES,1,
1553                [define if capabilities should be used])
1554      LIBS="$LIBS -lcap"
1555      use_capabilities=yes
1556   fi
1557 fi
1558 if test "$use_capabilities" = "no" ; then
1559     AC_MSG_WARN([[
1560 ***
1561 *** The use of capabilities on this system is not possible.
1562 *** You need a recent Linux kernel and some patches:
1563 ***   fcaps-2.2.9-990610.patch      (kernel patch for 2.2.9)
1564 ***   fcap-module-990613.tar.gz     (kernel module)
1565 ***   libcap-1.92.tar.gz            (user mode library and utilities)
1566 *** And you have to configure the kernel with CONFIG_VFS_CAP_PLUGIN
1567 *** set (filesystems menu). Be warned: This code is *really* ALPHA.
1568 ***]])
1569 fi
1570 fi
1571
1572 # Check whether a random device is available.
1573 if test "$try_dev_random" = yes ; then
1574     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
1575     [if test -r "$NAME_OF_DEV_RANDOM" && test -r "$NAME_OF_DEV_URANDOM" ; then
1576       ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
1577     if test "$ac_cv_have_dev_random" = yes; then
1578         AC_DEFINE(HAVE_DEV_RANDOM,1,
1579                  [defined if the system supports a random device] )
1580     fi
1581 else
1582     AC_MSG_CHECKING(for random device)
1583     ac_cv_have_dev_random=no
1584     AC_MSG_RESULT(has been disabled)
1585 fi
1586
1587 # Figure out the random modules for this configuration.
1588 if test "$random" = "default"; then
1589
1590     # Select default value.
1591     if test "$ac_cv_have_dev_random" = yes; then
1592         # Try Linuxish random device.
1593         random_modules="linux"
1594     else
1595         case "${host}" in
1596         *-*-mingw32ce*)
1597           # WindowsCE random device.
1598           random_modules="w32ce"
1599           ;;
1600         *-*-mingw32*|*-*-cygwin*)
1601           # Windows random device.
1602           random_modules="w32"
1603           ;;
1604         *)
1605           # Build everything, allow to select at runtime.
1606           random_modules="$auto_random_modules"
1607           ;;
1608         esac
1609     fi
1610 else
1611     if test "$random" = "auto"; then
1612         # Build everything, allow to select at runtime.
1613         random_modules="$auto_random_modules"
1614     else
1615         random_modules="$random"
1616     fi
1617 fi
1618
1619
1620 #
1621 # Other defines
1622 #
1623 if test mym4_isgit = "yes"; then
1624     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
1625               [Defined if this is not a regular release])
1626 fi
1627
1628
1629 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
1630
1631
1632 # This is handy for debugging so the compiler doesn't rearrange
1633 # things and eliminate variables.
1634 AC_ARG_ENABLE(optimization,
1635        AC_HELP_STRING([--disable-optimization],
1636                       [disable compiler optimization]),
1637                       [if test $enableval = no ; then
1638                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
1639                        fi])
1640
1641 # CFLAGS mangling when using gcc.
1642 if test "$GCC" = yes; then
1643     CFLAGS="$CFLAGS -Wall"
1644     if test "$USE_MAINTAINER_MODE" = "yes"; then
1645         CFLAGS="$CFLAGS -Wcast-align -Wshadow -Wstrict-prototypes"
1646         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
1647
1648         # If -Wno-missing-field-initializers is supported we can enable a
1649         # a bunch of really useful warnings.
1650         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
1651         _gcc_cflags_save=$CFLAGS
1652         CFLAGS="-Wno-missing-field-initializers"
1653         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
1654         AC_MSG_RESULT($_gcc_wopt)
1655         CFLAGS=$_gcc_cflags_save;
1656         if test x"$_gcc_wopt" = xyes ; then
1657           CFLAGS="$CFLAGS -W -Wextra -Wbad-function-cast"
1658           CFLAGS="$CFLAGS -Wwrite-strings"
1659           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
1660           CFLAGS="$CFLAGS -Wno-missing-field-initializers"
1661           CFLAGS="$CFLAGS -Wno-sign-compare"
1662         fi
1663
1664         AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
1665         _gcc_cflags_save=$CFLAGS
1666         CFLAGS="-Wpointer-arith"
1667         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
1668         AC_MSG_RESULT($_gcc_wopt)
1669         CFLAGS=$_gcc_cflags_save;
1670         if test x"$_gcc_wopt" = xyes ; then
1671           CFLAGS="$CFLAGS -Wpointer-arith"
1672         fi
1673     fi
1674
1675 fi
1676
1677 # Check whether as(1) supports a noeexecstack feature.  This test
1678 # includes an override option.
1679 CL_AS_NOEXECSTACK
1680
1681
1682 AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION)
1683 AC_SUBST(LIBGCRYPT_CONFIG_LIBS)
1684 AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS)
1685 AC_SUBST(LIBGCRYPT_CONFIG_HOST)
1686 AC_SUBST(LIBGCRYPT_THREAD_MODULES)
1687
1688 AC_CONFIG_COMMANDS([gcrypt-conf],[[
1689 chmod +x src/libgcrypt-config
1690 ]],[[
1691 prefix=$prefix
1692 exec_prefix=$exec_prefix
1693 libdir=$libdir
1694 datadir=$datadir
1695 DATADIRNAME=$DATADIRNAME
1696 ]])
1697
1698 #####################
1699 #### Conclusion. ####
1700 #####################
1701
1702 # Check that requested feature can actually be used and define
1703 # ENABLE_foo_SUPPORT macros.
1704
1705 if test x"$aesnisupport" = xyes ; then
1706   if test "$gcry_cv_gcc_inline_asm_ssse3" != "yes" ; then
1707     aesnisupport="no (unsupported by compiler)"
1708   fi
1709 fi
1710 if test x"$pclmulsupport" = xyes ; then
1711   if test "$gcry_cv_gcc_inline_asm_pclmul" != "yes" ; then
1712     pclmulsupport="no (unsupported by compiler)"
1713   fi
1714 fi
1715 if test x"$avxsupport" = xyes ; then
1716   if test "$gcry_cv_gcc_inline_asm_avx" != "yes" ; then
1717     avxsupport="no (unsupported by compiler)"
1718   fi
1719 fi
1720 if test x"$avx2support" = xyes ; then
1721   if test "$gcry_cv_gcc_inline_asm_avx2" != "yes" ; then
1722     avx2support="no (unsupported by compiler)"
1723   fi
1724 fi
1725 if test x"$neonsupport" = xyes ; then
1726   if test "$gcry_cv_gcc_inline_asm_neon" != "yes" ; then
1727     neonsupport="no (unsupported by compiler)"
1728   fi
1729 fi
1730
1731 if test x"$aesnisupport" = xyes ; then
1732   AC_DEFINE(ENABLE_AESNI_SUPPORT, 1,
1733             [Enable support for Intel AES-NI instructions.])
1734 fi
1735 if test x"$pclmulsupport" = xyes ; then
1736   AC_DEFINE(ENABLE_PCLMUL_SUPPORT, 1,
1737             [Enable support for Intel PCLMUL instructions.])
1738 fi
1739 if test x"$avxsupport" = xyes ; then
1740   AC_DEFINE(ENABLE_AVX_SUPPORT,1,
1741             [Enable support for Intel AVX instructions.])
1742 fi
1743 if test x"$avx2support" = xyes ; then
1744   AC_DEFINE(ENABLE_AVX2_SUPPORT,1,
1745             [Enable support for Intel AVX2 instructions.])
1746 fi
1747 if test x"$neonsupport" = xyes ; then
1748   AC_DEFINE(ENABLE_NEON_SUPPORT,1,
1749             [Enable support for ARM NEON instructions.])
1750 fi
1751 if test x"$padlocksupport" = xyes ; then
1752   AC_DEFINE(ENABLE_PADLOCK_SUPPORT, 1,
1753             [Enable support for the PadLock engine.])
1754 fi
1755 if test x"$drngsupport" = xyes ; then
1756   AC_DEFINE(ENABLE_DRNG_SUPPORT, 1,
1757             [Enable support for Intel DRNG (RDRAND instruction).])
1758 fi
1759
1760
1761 # Define conditional sources and config.h symbols depending on the
1762 # selected ciphers, pubkey-ciphers, digests, kdfs, and random modules.
1763
1764 LIST_MEMBER(arcfour, $enabled_ciphers)
1765 if test "$found" = "1"; then
1766    GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo"
1767    AC_DEFINE(USE_ARCFOUR, 1, [Defined if this module should be included])
1768
1769    case "${host}" in
1770       x86_64-*-*)
1771          # Build with the assembly implementation
1772          GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour-amd64.lo"
1773       ;;
1774    esac
1775 fi
1776
1777 LIST_MEMBER(blowfish, $enabled_ciphers)
1778 if test "$found" = "1" ; then
1779    GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo"
1780    AC_DEFINE(USE_BLOWFISH, 1, [Defined if this module should be included])
1781
1782    case "${host}" in
1783       x86_64-*-*)
1784          # Build with the assembly implementation
1785          GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish-amd64.lo"
1786       ;;
1787       arm*-*-*)
1788          # Build with the assembly implementation
1789          GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish-arm.lo"
1790       ;;
1791    esac
1792 fi
1793
1794 LIST_MEMBER(cast5, $enabled_ciphers)
1795 if test "$found" = "1" ; then
1796    GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo"
1797    AC_DEFINE(USE_CAST5, 1, [Defined if this module should be included])
1798
1799    case "${host}" in
1800       x86_64-*-*)
1801          # Build with the assembly implementation
1802          GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5-amd64.lo"
1803       ;;
1804       arm*-*-*)
1805          # Build with the assembly implementation
1806          GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5-arm.lo"
1807       ;;
1808    esac
1809 fi
1810
1811 LIST_MEMBER(des, $enabled_ciphers)
1812 if test "$found" = "1" ; then
1813    GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo"
1814    AC_DEFINE(USE_DES, 1, [Defined if this module should be included])
1815
1816    case "${host}" in
1817       x86_64-*-*)
1818          # Build with the assembly implementation
1819          GCRYPT_CIPHERS="$GCRYPT_CIPHERS des-amd64.lo"
1820       ;;
1821    esac
1822 fi
1823
1824 LIST_MEMBER(aes, $enabled_ciphers)
1825 if test "$found" = "1" ; then
1826    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo"
1827    AC_DEFINE(USE_AES, 1, [Defined if this module should be included])
1828
1829    case "${host}" in
1830       x86_64-*-*)
1831          # Build with the assembly implementation
1832          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-amd64.lo"
1833
1834          # Build with the SSSE3 implementation
1835          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-ssse3-amd64.lo"
1836       ;;
1837       arm*-*-*)
1838          # Build with the assembly implementation
1839          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-arm.lo"
1840       ;;
1841    esac
1842
1843    case "$mpi_cpu_arch" in
1844      x86)
1845          # Build with the AES-NI implementation
1846          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-aesni.lo"
1847
1848          # Build with the Padlock implementation
1849          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-padlock.lo"
1850       ;;
1851    esac
1852 fi
1853
1854 LIST_MEMBER(twofish, $enabled_ciphers)
1855 if test "$found" = "1" ; then
1856    GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo"
1857    AC_DEFINE(USE_TWOFISH, 1, [Defined if this module should be included])
1858
1859    case "${host}" in
1860       x86_64-*-*)
1861          # Build with the assembly implementation
1862          GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish-amd64.lo"
1863       ;;
1864       arm*-*-*)
1865          # Build with the assembly implementation
1866          GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish-arm.lo"
1867       ;;
1868    esac
1869 fi
1870
1871 LIST_MEMBER(serpent, $enabled_ciphers)
1872 if test "$found" = "1" ; then
1873    GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo"
1874    AC_DEFINE(USE_SERPENT, 1, [Defined if this module should be included])
1875
1876    case "${host}" in
1877       x86_64-*-*)
1878          # Build with the SSE2 implementation
1879          GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-sse2-amd64.lo"
1880       ;;
1881    esac
1882
1883    if test x"$avx2support" = xyes ; then
1884       # Build with the AVX2 implementation
1885       GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-avx2-amd64.lo"
1886    fi
1887
1888    if test x"$neonsupport" = xyes ; then
1889       # Build with the NEON implementation
1890       GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-armv7-neon.lo"
1891    fi
1892 fi
1893
1894 LIST_MEMBER(rfc2268, $enabled_ciphers)
1895 if test "$found" = "1" ; then
1896    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo"
1897    AC_DEFINE(USE_RFC2268, 1, [Defined if this module should be included])
1898 fi
1899
1900 LIST_MEMBER(seed, $enabled_ciphers)
1901 if test "$found" = "1" ; then
1902    GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo"
1903    AC_DEFINE(USE_SEED, 1, [Defined if this module should be included])
1904 fi
1905
1906 LIST_MEMBER(camellia, $enabled_ciphers)
1907 if test "$found" = "1" ; then
1908    GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia.lo camellia-glue.lo"
1909    AC_DEFINE(USE_CAMELLIA, 1, [Defined if this module should be included])
1910
1911    case "${host}" in
1912       arm*-*-*)
1913          # Build with the assembly implementation
1914          GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-arm.lo"
1915       ;;
1916    esac
1917
1918    if test x"$avxsupport" = xyes ; then
1919       if test x"$aesnisupport" = xyes ; then
1920         # Build with the AES-NI/AVX implementation
1921         GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-aesni-avx-amd64.lo"
1922       fi
1923    fi
1924
1925    if test x"$avx2support" = xyes ; then
1926       if test x"$aesnisupport" = xyes ; then
1927         # Build with the AES-NI/AVX2 implementation
1928         GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-aesni-avx2-amd64.lo"
1929       fi
1930    fi
1931 fi
1932
1933 LIST_MEMBER(idea, $enabled_ciphers)
1934 if test "$found" = "1" ; then
1935    GCRYPT_CIPHERS="$GCRYPT_CIPHERS idea.lo"
1936    AC_DEFINE(USE_IDEA, 1, [Defined if this module should be included])
1937 fi
1938
1939 LIST_MEMBER(salsa20, $enabled_ciphers)
1940 if test "$found" = "1" ; then
1941    GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20.lo"
1942    AC_DEFINE(USE_SALSA20, 1, [Defined if this module should be included])
1943
1944    case "${host}" in
1945       x86_64-*-*)
1946          # Build with the assembly implementation
1947          GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20-amd64.lo"
1948       ;;
1949    esac
1950
1951    if test x"$neonsupport" = xyes ; then
1952      # Build with the NEON implementation
1953      GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20-armv7-neon.lo"
1954    fi
1955 fi
1956
1957 LIST_MEMBER(gost28147, $enabled_ciphers)
1958 if test "$found" = "1" ; then
1959    GCRYPT_CIPHERS="$GCRYPT_CIPHERS gost28147.lo"
1960    AC_DEFINE(USE_GOST28147, 1, [Defined if this module should be included])
1961 fi
1962
1963 LIST_MEMBER(chacha20, $enabled_ciphers)
1964 if test "$found" = "1" ; then
1965    GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20.lo"
1966    AC_DEFINE(USE_CHACHA20, 1, [Defined if this module should be included])
1967
1968    case "${host}" in
1969       x86_64-*-*)
1970          # Build with the assembly implementation
1971          GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20-sse2-amd64.lo"
1972          GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20-ssse3-amd64.lo"
1973          GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20-avx2-amd64.lo"
1974       ;;
1975    esac
1976
1977    if test x"$neonsupport" = xyes ; then
1978      # Build with the NEON implementation
1979      GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20-armv7-neon.lo"
1980    fi
1981 fi
1982
1983 case "${host}" in
1984    x86_64-*-*)
1985       # Build with the assembly implementation
1986       GCRYPT_CIPHERS="$GCRYPT_CIPHERS poly1305-sse2-amd64.lo"
1987       GCRYPT_CIPHERS="$GCRYPT_CIPHERS poly1305-avx2-amd64.lo"
1988    ;;
1989 esac
1990
1991 if test x"$neonsupport" = xyes ; then
1992    # Build with the NEON implementation
1993    GCRYPT_CIPHERS="$GCRYPT_CIPHERS poly1305-armv7-neon.lo"
1994 fi
1995
1996 LIST_MEMBER(dsa, $enabled_pubkey_ciphers)
1997 if test "$found" = "1" ; then
1998    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo"
1999    AC_DEFINE(USE_DSA, 1, [Defined if this module should be included])
2000 fi
2001
2002 LIST_MEMBER(rsa, $enabled_pubkey_ciphers)
2003 if test "$found" = "1" ; then
2004    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo"
2005    AC_DEFINE(USE_RSA, 1, [Defined if this module should be included])
2006 fi
2007
2008 LIST_MEMBER(elgamal, $enabled_pubkey_ciphers)
2009 if test "$found" = "1" ; then
2010    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo"
2011    AC_DEFINE(USE_ELGAMAL, 1, [Defined if this module should be included])
2012 fi
2013
2014 LIST_MEMBER(ecc, $enabled_pubkey_ciphers)
2015 if test "$found" = "1" ; then
2016    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS \
2017                           ecc.lo ecc-curves.lo ecc-misc.lo \
2018                           ecc-ecdsa.lo ecc-eddsa.lo ecc-gost.lo"
2019    AC_DEFINE(USE_ECC, 1, [Defined if this module should be included])
2020 fi
2021
2022 LIST_MEMBER(crc, $enabled_digests)
2023 if test "$found" = "1" ; then
2024    GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo"
2025    AC_DEFINE(USE_CRC, 1, [Defined if this module should be included])
2026 fi
2027
2028 LIST_MEMBER(gostr3411-94, $enabled_digests)
2029 if test "$found" = "1" ; then
2030    # GOST R 34.11-94 internally uses GOST 28147-89
2031    LIST_MEMBER(gost28147, $enabled_ciphers)
2032    if test "$found" = "1" ; then
2033       GCRYPT_DIGESTS="$GCRYPT_DIGESTS gostr3411-94.lo"
2034       AC_DEFINE(USE_GOST_R_3411_94, 1, [Defined if this module should be included])
2035    fi
2036 fi
2037
2038 LIST_MEMBER(stribog, $enabled_digests)
2039 if test "$found" = "1" ; then
2040    GCRYPT_DIGESTS="$GCRYPT_DIGESTS stribog.lo"
2041    AC_DEFINE(USE_GOST_R_3411_12, 1, [Defined if this module should be included])
2042 fi
2043
2044 LIST_MEMBER(md2, $enabled_digests)
2045 if test "$found" = "1" ; then
2046    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md2.lo"
2047    AC_DEFINE(USE_MD2, 1, [Defined if this module should be included])
2048 fi
2049
2050 LIST_MEMBER(md4, $enabled_digests)
2051 if test "$found" = "1" ; then
2052    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo"
2053    AC_DEFINE(USE_MD4, 1, [Defined if this module should be included])
2054 fi
2055
2056 LIST_MEMBER(md5, $enabled_digests)
2057 if test "$found" = "1" ; then
2058    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo"
2059    AC_DEFINE(USE_MD5, 1, [Defined if this module should be included])
2060 fi
2061
2062 LIST_MEMBER(sha256, $enabled_digests)
2063 if test "$found" = "1" ; then
2064    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo"
2065    AC_DEFINE(USE_SHA256, 1, [Defined if this module should be included])
2066
2067    case "${host}" in
2068       x86_64-*-*)
2069          # Build with the assembly implementation
2070          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-ssse3-amd64.lo"
2071          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-avx-amd64.lo"
2072          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-avx2-bmi2-amd64.lo"
2073       ;;
2074    esac
2075 fi
2076
2077 LIST_MEMBER(sha512, $enabled_digests)
2078 if test "$found" = "1" ; then
2079    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo"
2080    AC_DEFINE(USE_SHA512, 1, [Defined if this module should be included])
2081
2082    case "${host}" in
2083       x86_64-*-*)
2084          # Build with the assembly implementation
2085          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-ssse3-amd64.lo"
2086          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx-amd64.lo"
2087          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx2-bmi2-amd64.lo"
2088       ;;
2089    esac
2090
2091    if test x"$neonsupport" = xyes ; then
2092      # Build with the NEON implementation
2093      GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-armv7-neon.lo"
2094    fi
2095 fi
2096
2097 LIST_MEMBER(sha3, $enabled_digests)
2098 if test "$found" = "1" ; then
2099    GCRYPT_DIGESTS="$GCRYPT_DIGESTS keccak.lo"
2100    AC_DEFINE(USE_SHA3, 1, [Defined if this module should be included])
2101
2102    case "${host}" in
2103       x86_64-*-*)
2104          # Build with the assembly implementation
2105          :
2106       ;;
2107    esac
2108
2109    if test x"$neonsupport" = xyes ; then
2110      # Build with the NEON implementation
2111      GCRYPT_DIGESTS="$GCRYPT_DIGESTS keccak-armv7-neon.lo"
2112    fi
2113 fi
2114
2115 LIST_MEMBER(tiger, $enabled_digests)
2116 if test "$found" = "1" ; then
2117    GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo"
2118    AC_DEFINE(USE_TIGER, 1, [Defined if this module should be included])
2119 fi
2120
2121 LIST_MEMBER(whirlpool, $enabled_digests)
2122 if test "$found" = "1" ; then
2123    GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo"
2124    AC_DEFINE(USE_WHIRLPOOL, 1, [Defined if this module should be included])
2125
2126    case "${host}" in
2127       x86_64-*-*)
2128          # Build with the assembly implementation
2129          GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool-sse2-amd64.lo"
2130       ;;
2131    esac
2132 fi
2133
2134 # rmd160 and sha1 should be included always.
2135 GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo"
2136 AC_DEFINE(USE_RMD160, 1, [Defined if this module should be included])
2137 AC_DEFINE(USE_SHA1, 1,   [Defined if this module should be included])
2138
2139 case "${host}" in
2140   x86_64-*-*)
2141     # Build with the assembly implementation
2142     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-ssse3-amd64.lo"
2143     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-avx-amd64.lo"
2144     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-avx-bmi2-amd64.lo"
2145   ;;
2146   arm*-*-*)
2147     # Build with the assembly implementation
2148     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-armv7-neon.lo"
2149   ;;
2150 esac
2151
2152 LIST_MEMBER(scrypt, $enabled_kdfs)
2153 if test "$found" = "1" ; then
2154    GCRYPT_KDFS="$GCRYPT_KDFS scrypt.lo"
2155    AC_DEFINE(USE_SCRYPT, 1, [Defined if this module should be included])
2156 fi
2157
2158 LIST_MEMBER(linux, $random_modules)
2159 if test "$found" = "1" ; then
2160    GCRYPT_RANDOM="$GCRYPT_RANDOM rndlinux.lo"
2161    AC_DEFINE(USE_RNDLINUX, 1, [Defined if the /dev/random RNG should be used.])
2162 fi
2163
2164 LIST_MEMBER(unix, $random_modules)
2165 if test "$found" = "1" ; then
2166    GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo"
2167    AC_DEFINE(USE_RNDUNIX, 1, [Defined if the default Unix RNG should be used.])
2168    print_egd_notice=yes
2169 fi
2170
2171 LIST_MEMBER(egd, $random_modules)
2172 if test "$found" = "1" ; then
2173    GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo"
2174    AC_DEFINE(USE_RNDEGD, 1, [Defined if the EGD based RNG should be used.])
2175 fi
2176
2177 LIST_MEMBER(w32, $random_modules)
2178 if test "$found" = "1" ; then
2179    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo"
2180    AC_DEFINE(USE_RNDW32, 1,
2181              [Defined if the Windows specific RNG should be used.])
2182 fi
2183
2184 LIST_MEMBER(w32ce, $random_modules)
2185 if test "$found" = "1" ; then
2186    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32ce.lo"
2187    AC_DEFINE(USE_RNDW32CE, 1,
2188              [Defined if the WindowsCE specific RNG should be used.])
2189 fi
2190
2191 AC_SUBST([GCRYPT_CIPHERS])
2192 AC_SUBST([GCRYPT_PUBKEY_CIPHERS])
2193 AC_SUBST([GCRYPT_DIGESTS])
2194 AC_SUBST([GCRYPT_KDFS])
2195 AC_SUBST([GCRYPT_RANDOM])
2196
2197 AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers)
2198 AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers)
2199 AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests)
2200
2201 # For printing the configuration we need a colon separated list of
2202 # algorithm names.
2203 tmp=`echo "$enabled_ciphers" | tr ' ' : `
2204 AC_DEFINE_UNQUOTED(LIBGCRYPT_CIPHERS, "$tmp",
2205                    [List of available cipher algorithms])
2206 tmp=`echo "$enabled_pubkey_ciphers" | tr ' ' : `
2207 AC_DEFINE_UNQUOTED(LIBGCRYPT_PUBKEY_CIPHERS, "$tmp",
2208                    [List of available public key cipher algorithms])
2209 tmp=`echo "$enabled_digests" | tr ' ' : `
2210 AC_DEFINE_UNQUOTED(LIBGCRYPT_DIGESTS, "$tmp",
2211                    [List of available digest algorithms])
2212 tmp=`echo "$enabled_kdfs" | tr ' ' : `
2213 AC_DEFINE_UNQUOTED(LIBGCRYPT_KDFS, "$tmp",
2214                    [List of available KDF algorithms])
2215
2216
2217 #
2218 # Define conditional sources depending on the used hardware platform.
2219 # Note that all possible modules must also be listed in
2220 # src/Makefile.am (EXTRA_libgcrypt_la_SOURCES).
2221 #
2222 GCRYPT_HWF_MODULES=
2223 case "$mpi_cpu_arch" in
2224      x86)
2225         AC_DEFINE(HAVE_CPU_ARCH_X86, 1,   [Defined for the x86 platforms])
2226         GCRYPT_HWF_MODULES="hwf-x86.lo"
2227         ;;
2228      alpha)
2229         AC_DEFINE(HAVE_CPU_ARCH_ALPHA, 1, [Defined for Alpha platforms])
2230         ;;
2231      sparc)
2232         AC_DEFINE(HAVE_CPU_ARCH_SPARC, 1, [Defined for SPARC platforms])
2233         ;;
2234      mips)
2235         AC_DEFINE(HAVE_CPU_ARCH_MIPS, 1,  [Defined for MIPS platforms])
2236         ;;
2237      m68k)
2238         AC_DEFINE(HAVE_CPU_ARCH_M68K, 1,  [Defined for M68k platforms])
2239         ;;
2240      ppc)
2241         AC_DEFINE(HAVE_CPU_ARCH_PPC, 1,   [Defined for PPC platforms])
2242         ;;
2243      arm)
2244         AC_DEFINE(HAVE_CPU_ARCH_ARM, 1,   [Defined for ARM platforms])
2245         GCRYPT_HWF_MODULES="hwf-arm.lo"
2246         ;;
2247 esac
2248 AC_SUBST([GCRYPT_HWF_MODULES])
2249
2250
2251 #
2252 # Option to disable building of doc file
2253 #
2254 build_doc=yes
2255 AC_ARG_ENABLE([doc], AC_HELP_STRING([--disable-doc],
2256                                     [do not build the documentation]),
2257                      build_doc=$enableval, build_doc=yes)
2258 AM_CONDITIONAL([BUILD_DOC], [test "x$build_doc" != xno])
2259
2260
2261 #
2262 # Provide information about the build.
2263 #
2264 BUILD_REVISION="mym4_revision"
2265 AC_SUBST(BUILD_REVISION)
2266 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
2267                    [GIT commit id revision used to build this package])
2268
2269 changequote(,)dnl
2270 BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
2271 changequote([,])dnl
2272 BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
2273 AC_SUBST(BUILD_FILEVERSION)
2274
2275 AC_ARG_ENABLE([build-timestamp],
2276   AC_HELP_STRING([--enable-build-timestamp],
2277                  [set an explicit build timestamp for reproducibility.
2278                   (default is the current time in ISO-8601 format)]),
2279      [if test "$enableval" = "yes"; then
2280         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
2281       else
2282         BUILD_TIMESTAMP="$enableval"
2283       fi],
2284      [BUILD_TIMESTAMP="<none>"])
2285 AC_SUBST(BUILD_TIMESTAMP)
2286 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
2287                    [The time this package was configured for a build])
2288
2289
2290 # And create the files.
2291 AC_CONFIG_FILES([
2292 Makefile
2293 m4/Makefile
2294 compat/Makefile
2295 mpi/Makefile
2296 cipher/Makefile
2297 random/Makefile
2298 doc/Makefile
2299 src/Makefile
2300 src/gcrypt.h
2301 src/libgcrypt-config
2302 src/versioninfo.rc
2303 tests/Makefile
2304 ])
2305 AC_CONFIG_FILES([tests/hashtest-256g], [chmod +x tests/hashtest-256g])
2306 AC_OUTPUT
2307
2308
2309 detection_module="${GCRYPT_HWF_MODULES%.lo}"
2310 test -n "$detection_module" || detection_module="none"
2311
2312 # Give some feedback
2313 GCRY_MSG_SHOW([],[])
2314 GCRY_MSG_SHOW([Libgcrypt],[v${VERSION} has been configured as follows:])
2315 GCRY_MSG_SHOW([],[])
2316 GCRY_MSG_SHOW([Platform:                 ],[$PRINTABLE_OS_NAME ($host)])
2317 GCRY_MSG_SHOW([Hardware detection module:],[$detection_module])
2318 GCRY_MSG_WRAP([Enabled cipher algorithms:],[$enabled_ciphers])
2319 GCRY_MSG_WRAP([Enabled digest algorithms:],[$enabled_digests])
2320 GCRY_MSG_WRAP([Enabled kdf algorithms:   ],[$enabled_kdfs])
2321 GCRY_MSG_WRAP([Enabled pubkey algorithms:],[$enabled_pubkey_ciphers])
2322 GCRY_MSG_SHOW([Random number generator:  ],[$random])
2323 GCRY_MSG_SHOW([Using linux capabilities: ],[$use_capabilities])
2324 GCRY_MSG_SHOW([Try using Padlock crypto: ],[$padlocksupport])
2325 GCRY_MSG_SHOW([Try using AES-NI crypto:  ],[$aesnisupport])
2326 GCRY_MSG_SHOW([Try using Intel PCLMUL:   ],[$pclmulsupport])
2327 GCRY_MSG_SHOW([Try using DRNG (RDRAND):  ],[$drngsupport])
2328 GCRY_MSG_SHOW([Try using Intel AVX:      ],[$avxsupport])
2329 GCRY_MSG_SHOW([Try using Intel AVX2:     ],[$avx2support])
2330 GCRY_MSG_SHOW([Try using ARM NEON:       ],[$neonsupport])
2331 GCRY_MSG_SHOW([],[])
2332
2333 if test "x${gpg_config_script_warn}" != x; then
2334 cat <<G10EOF
2335         Mismatches between the target platform and the to
2336         be used libraries have been been detected for:
2337          ${gpg_config_script_warn}
2338         Please check above for warning messages.
2339
2340 G10EOF
2341 fi
2342 if test "$print_egd_notice" = "yes"; then
2343 cat <<G10EOF
2344    The performance of the Unix random gatherer module (rndunix) is not
2345    very good and it does not keep the entropy pool over multiple
2346    invocations of Libgcrypt base applications.  The suggested way to
2347    overcome this problem is to use the
2348
2349                  Entropy Gathering Daemon (EGD)
2350
2351    which provides a entropy source for the whole system.  It is written
2352    in Perl and available at the GnuPG FTP servers.  For more information
2353    consult the GnuPG site:
2354
2355           https://gnupg.org/related_software/swlist.html#egd
2356
2357 G10EOF
2358 fi
2359
2360 if test "$gcry_cv_gcc_attribute_aligned" != "yes" ; then
2361 cat <<G10EOF
2362    Please not that your compiler does not support the GCC style
2363    aligned attribute. Using this software may evoke bus errors.
2364
2365 G10EOF
2366 fi
2367
2368 if test -n "$gpl"; then
2369   echo "Please note that you are building a version of Libgcrypt with"
2370   echo "  $gpl"
2371   echo "included.  These parts are licensed under the GPL and thus the"
2372   echo "use of this library has to comply with the conditions of the GPL."
2373   echo ""
2374 fi