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