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