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