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