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