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