Actually check for uint64_t.
[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  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.10"
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, [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=20
58 LIBGCRYPT_LT_AGE=0
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
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 AH_TOP([
86 #ifndef _GCRYPT_CONFIG_H_INCLUDED
87 #define _GCRYPT_CONFIG_H_INCLUDED
88
89 /* Enable gpg-error's strerror macro for W32CE.  */
90 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
91 ])
92
93 AH_BOTTOM([
94 #define _GCRYPT_IN_LIBGCRYPT 1
95
96 /* If the configure check for endianness has been disabled, get it from
97    OS macros.  This is intended for making fat binary builds on OS X.  */
98 #ifdef DISABLED_ENDIAN_CHECK
99 # if defined(__BIG_ENDIAN__)
100 #  define WORDS_BIGENDIAN 1
101 # elif defined(__LITTLE_ENDIAN__)
102 #  undef WORDS_BIGENDIAN
103 # else
104 #  error "No endianness found"
105 # endif
106 #endif /*DISABLED_ENDIAN_CHECK*/
107
108 /* We basically use the original Camellia source.  Make sure the symbols
109    properly prefixed.  */
110 #define CAMELLIA_EXT_SYM_PREFIX _gcry_
111
112 #endif /*_GCRYPT_CONFIG_H_INCLUDED*/
113 ])
114
115 AH_VERBATIM([_REENTRANT],
116 [/* To allow the use of Libgcrypt in multithreaded programs we have to use
117     special features from the library. */
118 #ifndef _REENTRANT
119 # define _REENTRANT 1
120 #endif
121 ])
122
123
124 AC_SUBST(LIBGCRYPT_LT_CURRENT)
125 AC_SUBST(LIBGCRYPT_LT_AGE)
126 AC_SUBST(LIBGCRYPT_LT_REVISION)
127 AC_SUBST(PACKAGE)
128 AC_SUBST(VERSION)
129 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
130 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
131 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \
132                           mym4_version_minor mym4_version_micro)
133 AC_SUBST(VERSION_NUMBER)
134
135
136 ######################
137 ##  Basic checks.  ### (we need some results later on (e.g. $GCC)
138 ######################
139
140 AC_PROG_MAKE_SET
141 missing_dir=`cd $ac_aux_dir && pwd`
142 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
143 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
144 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
145 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
146 # AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
147 AC_PROG_CC
148 AC_PROG_CPP
149 AM_PROG_CC_C_O
150 AM_PROG_AS
151 AC_ISC_POSIX
152 AC_PROG_INSTALL
153 AC_PROG_AWK
154
155 AC_GNU_SOURCE
156
157 # We need to compile and run a program on the build machine.  A
158 # comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in
159 # the AC archive is broken for autoconf 2.57.  Given that there is no
160 # newer version of that macro, we assume that it is also broken for
161 # autoconf 2.61 and thus we use a simple but usually sufficient
162 # approach.
163 AC_MSG_CHECKING(for cc for build)
164 if test "$cross_compiling" = "yes"; then
165   CC_FOR_BUILD="${CC_FOR_BUILD-cc}"
166 else
167   CC_FOR_BUILD="${CC_FOR_BUILD-$CC}"
168 fi
169 AC_MSG_RESULT($CC_FOR_BUILD)
170 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
171
172
173 LT_PREREQ([2.2.6])
174 LT_INIT([win32-dll disable-static])
175 LT_LANG([Windows Resource])
176
177
178 ##########################
179 ## General definitions. ##
180 ##########################
181
182 # Used by libgcrypt-config
183 LIBGCRYPT_CONFIG_LIBS="-lgcrypt"
184 LIBGCRYPT_CONFIG_CFLAGS=""
185 LIBGCRYPT_CONFIG_HOST="$host"
186
187 # Definitions for symmetric ciphers.
188 available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed"
189 available_ciphers="$available_ciphers camellia idea salsa20 gost28147"
190 enabled_ciphers=""
191
192 # Definitions for public-key ciphers.
193 available_pubkey_ciphers="dsa elgamal rsa ecc"
194 enabled_pubkey_ciphers=""
195
196 # Definitions for message digests.
197 available_digests="crc gostr3411-94 md4 md5 rmd160 sha1 sha256"
198 available_digests_64="sha512 tiger whirlpool stribog"
199 enabled_digests=""
200
201 # Definitions for kdfs (optional ones)
202 available_kdfs="s2k pkdf2"
203 available_kdfs_64="scrypt"
204 enabled_kdfs=""
205
206 # Definitions for random modules.
207 available_random_modules="linux egd unix"
208 auto_random_modules="$available_random_modules"
209
210 # Supported thread backends.
211 LIBGCRYPT_THREAD_MODULES=""
212
213 # Other definitions.
214 print_egd_notice=no
215 have_w32_system=no
216 have_w32ce_system=no
217 have_pthread=no
218
219
220 # Setup some stuff depending on host.
221 case "${host}" in
222     *-*-mingw32*)
223       ac_cv_have_dev_random=no
224       have_w32_system=yes
225       case "${host}" in
226         *-mingw32ce*)
227             have_w32ce_system=yes
228             available_random_modules="w32ce"
229             ;;
230         *)
231             available_random_modules="w32"
232             ;;
233       esac
234       AC_DEFINE(USE_ONLY_8DOT3,1,
235                 [set this to limit filenames to the 8.3 format])
236       AC_DEFINE(HAVE_DRIVE_LETTERS,1,
237                 [defined if we must run on a stupid file system])
238       AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
239                 [defined if we run on some of the PCDOS like systems
240                  (DOS, Windoze. OS/2) with special properties like
241                   no file modes])
242       ;;
243
244     i?86-emx-os2 | i?86-*-os2*emx)
245         # OS/2 with the EMX environment
246         ac_cv_have_dev_random=no
247         AC_DEFINE(HAVE_DRIVE_LETTERS)
248         AC_DEFINE(HAVE_DOSISH_SYSTEM)
249         ;;
250
251     i?86-*-msdosdjgpp*)
252         # DOS with the DJGPP environment
253         ac_cv_have_dev_random=no
254         AC_DEFINE(HAVE_DRIVE_LETTERS)
255         AC_DEFINE(HAVE_DOSISH_SYSTEM)
256         ;;
257
258     *-*-hpux*)
259         if test -z "$GCC" ; then
260             CFLAGS="$CFLAGS -Ae -D_HPUX_SOURCE"
261         fi
262         ;;
263     *-dec-osf4*)
264         if test -z "$GCC" ; then
265             # Suppress all warnings
266             # to get rid of the unsigned/signed char mismatch warnings.
267             CFLAGS="$CFLAGS -w"
268         fi
269         ;;
270     m68k-atari-mint)
271         ;;
272     *)
273       ;;
274 esac
275
276 if test "$have_w32_system" = yes; then
277    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
278    if test "$have_w32ce_system" = yes; then
279      AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
280    fi
281 fi
282 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
283 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
284
285
286
287 # A printable OS Name is sometimes useful.
288 case "${host}" in
289     *-*-mingw32ce*)
290         PRINTABLE_OS_NAME="W32CE"
291         ;;
292
293     *-*-mingw32*)
294         PRINTABLE_OS_NAME="W32"
295         ;;
296
297     i?86-emx-os2 | i?86-*-os2*emx )
298         PRINTABLE_OS_NAME="OS/2"
299         ;;
300
301     i?86-*-msdosdjgpp*)
302         PRINTABLE_OS_NAME="MSDOS/DJGPP"
303         ;;
304
305     *-linux*)
306         PRINTABLE_OS_NAME="GNU/Linux"
307         ;;
308
309     *)
310         PRINTABLE_OS_NAME=`uname -s || echo "Unknown"`
311         ;;
312 esac
313
314 #
315 # Figure out the name of the random device
316 #
317 case "${host}" in
318     *-openbsd*)
319         NAME_OF_DEV_RANDOM="/dev/srandom"
320         NAME_OF_DEV_URANDOM="/dev/urandom"
321         ;;
322
323     *)
324         NAME_OF_DEV_RANDOM="/dev/random"
325         NAME_OF_DEV_URANDOM="/dev/urandom"
326         ;;
327 esac
328
329
330 AC_ARG_ENABLE(endian-check,
331               AC_HELP_STRING([--disable-endian-check],
332               [disable the endian check and trust the OS provided macros]),
333               endiancheck=$enableval,endiancheck=yes)
334 if test x"$endiancheck" = xyes ; then
335   AC_C_BIGENDIAN
336 else
337   AC_DEFINE(DISABLED_ENDIAN_CHECK,1,[configure did not test for endianess])
338 fi
339
340 AC_CHECK_SIZEOF(unsigned short, 2)
341 AC_CHECK_SIZEOF(unsigned int, 4)
342 AC_CHECK_SIZEOF(unsigned long, 4)
343 AC_CHECK_SIZEOF(unsigned long long, 0)
344
345 AC_TYPE_UINTPTR_T
346
347 if test "$ac_cv_sizeof_unsigned_short" = "0" \
348    || test "$ac_cv_sizeof_unsigned_int" = "0" \
349    || test "$ac_cv_sizeof_unsigned_long" = "0"; then
350     AC_MSG_WARN([Hmmm, something is wrong with the sizes - using defaults]);
351 fi
352
353 # Ensure that we have UINT64_C before we bother to check for uint64_t
354 AC_CACHE_CHECK([for UINT64_C],[gnupg_cv_uint64_c_works],
355    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <inttypes.h>]],
356        [[uint64_t foo=UINT64_C(42);]])],
357      gnupg_cv_uint64_c_works=yes,gnupg_cv_uint64_c_works=no))
358 if test "$gnupg_cv_uint64_c_works" = "yes" ; then
359    AC_CHECK_SIZEOF(uint64_t)
360 fi
361
362 # Do we have any 64-bit data types?
363 if test "$ac_cv_sizeof_unsigned_int" != "8" \
364    && test "$ac_cv_sizeof_unsigned_long" != "8" \
365    && test "$ac_cv_sizeof_unsigned_long_long" != "8" \
366    && test "$ac_cv_sizeof_uint64_t" != "8"; then
367     AC_MSG_WARN([No 64-bit types.  Disabling TIGER/192, SCRYPT, SHA-384, \
368  SHA-512 and GOST R 34.11-12])
369 else
370   available_digests="$available_digests $available_digests_64"
371   available_kdfs="$available_kdfs $available_kdfs_64"
372 fi
373
374 # If not specified otherwise, all available algorithms will be
375 # included.
376 default_ciphers="$available_ciphers"
377 default_pubkey_ciphers="$available_pubkey_ciphers"
378 default_digests="$available_digests"
379 default_kdfs="$available_kdfs"
380
381 # Substitutions to set generated files in a Emacs buffer to read-only.
382 AC_SUBST(emacs_local_vars_begin, ['Local Variables:'])
383 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
384 AC_SUBST(emacs_local_vars_end, ['End:'])
385
386 ############################
387 ## Command line switches. ##
388 ############################
389
390 # Implementation of the --enable-ciphers switch.
391 AC_ARG_ENABLE(ciphers,
392               AC_HELP_STRING([--enable-ciphers=ciphers],
393                              [select the symmetric ciphers to include]),
394               [enabled_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
395               [enabled_ciphers=""])
396 if test "x$enabled_ciphers" = "x" \
397    -o "$enabled_ciphers" = "yes"  \
398    -o "$enabled_ciphers" = "no"; then
399    enabled_ciphers=$default_ciphers
400 fi
401 AC_MSG_CHECKING([which symmetric ciphers to include])
402 for cipher in $enabled_ciphers; do
403     LIST_MEMBER($cipher, $available_ciphers)
404     if test "$found" = "0"; then
405        AC_MSG_ERROR([unsupported cipher "$cipher" specified])
406     fi
407 done
408 AC_MSG_RESULT([$enabled_ciphers])
409
410 # Implementation of the --enable-pubkey-ciphers switch.
411 AC_ARG_ENABLE(pubkey-ciphers,
412               AC_HELP_STRING([--enable-pubkey-ciphers=ciphers],
413                              [select the public-key ciphers to include]),
414               [enabled_pubkey_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
415               [enabled_pubkey_ciphers=""])
416 if test "x$enabled_pubkey_ciphers" = "x" \
417    -o "$enabled_pubkey_ciphers" = "yes"  \
418    -o "$enabled_pubkey_ciphers" = "no"; then
419    enabled_pubkey_ciphers=$default_pubkey_ciphers
420 fi
421 AC_MSG_CHECKING([which public-key ciphers to include])
422 for cipher in $enabled_pubkey_ciphers; do
423     LIST_MEMBER($cipher, $available_pubkey_ciphers)
424     if test "$found" = "0"; then
425        AC_MSG_ERROR([unsupported public-key cipher specified])
426     fi
427 done
428 AC_MSG_RESULT([$enabled_pubkey_ciphers])
429
430 # Implementation of the --enable-digests switch.
431 AC_ARG_ENABLE(digests,
432               AC_HELP_STRING([--enable-digests=digests],
433                              [select the message digests to include]),
434               [enabled_digests=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
435               [enabled_digests=""])
436 if test "x$enabled_digests" = "x" \
437    -o "$enabled_digests" = "yes"  \
438    -o "$enabled_digests" = "no"; then
439    enabled_digests=$default_digests
440 fi
441 AC_MSG_CHECKING([which message digests to include])
442 for digest in $enabled_digests; do
443     LIST_MEMBER($digest, $available_digests)
444     if test "$found" = "0"; then
445        AC_MSG_ERROR([unsupported message digest specified])
446     fi
447 done
448 AC_MSG_RESULT([$enabled_digests])
449
450 # Implementation of the --enable-kdfs switch.
451 AC_ARG_ENABLE(kdfs,
452       AC_HELP_STRING([--enable-kfds=kdfs],
453                      [select the KDFs to include]),
454       [enabled_kdfs=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
455       [enabled_kdfs=""])
456 if test "x$enabled_kdfs" = "x" \
457    -o "$enabled_kdfs" = "yes"  \
458    -o "$enabled_kdfs" = "no"; then
459    enabled_kdfs=$default_kdfs
460 fi
461 AC_MSG_CHECKING([which key derivation functions to include])
462 for kdf in $enabled_kdfs; do
463     LIST_MEMBER($kdf, $available_kdfs)
464     if test "$found" = "0"; then
465        AC_MSG_ERROR([unsupported key derivation function specified])
466     fi
467 done
468 AC_MSG_RESULT([$enabled_kdfs])
469
470 # Implementation of the --enable-random switch.
471 AC_ARG_ENABLE(random,
472               AC_HELP_STRING([--enable-random=name],
473                              [select which random number generator to use]),
474               [random=`echo $enableval | tr '[A-Z]' '[a-z]'`],
475               [])
476 if test "x$random" = "x" -o "$random" = "yes" -o "$random" = "no"; then
477     random=default
478 fi
479 AC_MSG_CHECKING([which random module to use])
480 if test "$random" != "default" -a "$random" != "auto"; then
481     LIST_MEMBER($random, $available_random_modules)
482     if test "$found" = "0"; then
483        AC_MSG_ERROR([unsupported random module specified])
484     fi
485 fi
486 AC_MSG_RESULT($random)
487
488 # Implementation of the --disable-dev-random switch.
489 AC_MSG_CHECKING([whether use of /dev/random is requested])
490 AC_ARG_ENABLE(dev-random,
491 [  --disable-dev-random    disable the use of dev random],
492     try_dev_random=$enableval, try_dev_random=yes)
493 AC_MSG_RESULT($try_dev_random)
494
495 # Implementation of the --with-egd-socket switch.
496 AC_ARG_WITH(egd-socket,
497     [  --with-egd-socket=NAME  Use NAME for the EGD socket)],
498             egd_socket_name="$withval", egd_socket_name="" )
499 AC_DEFINE_UNQUOTED(EGD_SOCKET_NAME, "$egd_socket_name",
500                    [Define if you don't want the default EGD socket name.
501                     For details see cipher/rndegd.c])
502
503 # Implementation of the --enable-random-daemon
504 AC_MSG_CHECKING([whether the experimental random daemon is requested])
505 AC_ARG_ENABLE([random-daemon],
506               AC_HELP_STRING([--enable-random-daemon],
507                              [Build and support the experimental gcryptrnd]),
508               [use_random_daemon=$enableval],
509               [use_random_daemon=no])
510 AC_MSG_RESULT($use_random_daemon)
511 if test x$use_random_daemon = xyes ; then
512     AC_DEFINE(USE_RANDOM_DAEMON,1,
513               [Define to support the experimental random daemon])
514 fi
515 AM_CONDITIONAL(USE_RANDOM_DAEMON, test x$use_random_daemon = xyes)
516
517
518 # Implementation of --disable-asm.
519 AC_MSG_CHECKING([whether MPI assembler modules are requested])
520 AC_ARG_ENABLE([asm],
521               AC_HELP_STRING([--disable-asm],
522                              [Disable MPI assembler modules]),
523               [try_asm_modules=$enableval],
524               [try_asm_modules=yes])
525 AC_MSG_RESULT($try_asm_modules)
526
527 # Implementation of the --enable-m-guard switch.
528 AC_MSG_CHECKING([whether memory guard is requested])
529 AC_ARG_ENABLE(m-guard,
530               AC_HELP_STRING([--enable-m-guard],
531                              [Enable memory guard facility]),
532               [use_m_guard=$enableval], [use_m_guard=no])
533 AC_MSG_RESULT($use_m_guard)
534 if test "$use_m_guard" = yes ; then
535     AC_DEFINE(M_GUARD,1,[Define to use the (obsolete) malloc guarding feature])
536 fi
537
538 # Implementation of the --enable-large-data-tests switch.
539 AC_MSG_CHECKING([whether to run large data tests])
540 AC_ARG_ENABLE(large-data-tests,
541               AC_HELP_STRING([--enable-large-data-tests],
542                  [Enable the real long ruinning large data tests]),
543               large_data_tests=$enableval,large_data_tests=no)
544 AC_MSG_RESULT($large_data_tests)
545 AC_SUBST(RUN_LARGE_DATA_TESTS, $large_data_tests)
546
547
548 # Implementation of the --with-capabilities switch.
549 # Check whether we want to use Linux capabilities
550 AC_MSG_CHECKING([whether use of capabilities is requested])
551 AC_ARG_WITH(capabilities,
552             AC_HELP_STRING([--with-capabilities],
553                            [Use linux capabilities [default=no]]),
554             [use_capabilities="$withval"],[use_capabilities=no])
555 AC_MSG_RESULT($use_capabilities)
556
557 # Implementation of the --enable-hmac-binary-check.
558 AC_MSG_CHECKING([whether a HMAC binary check is requested])
559 AC_ARG_ENABLE(hmac-binary-check,
560               AC_HELP_STRING([--enable-hmac-binary-check],
561                              [Enable library integrity check]),
562               [use_hmac_binary_check=$enableval],
563               [use_hmac_binary_check=no])
564 AC_MSG_RESULT($use_hmac_binary_check)
565 if test "$use_hmac_binary_check" = yes ; then
566     AC_DEFINE(ENABLE_HMAC_BINARY_CHECK,1,
567               [Define to support an HMAC based integrity check])
568 fi
569
570
571 # Implementation of the --disable-padlock-support switch.
572 AC_MSG_CHECKING([whether padlock support is requested])
573 AC_ARG_ENABLE(padlock-support,
574               AC_HELP_STRING([--disable-padlock-support],
575                  [Disable support for the PadLock Engine of VIA processors]),
576               padlocksupport=$enableval,padlocksupport=yes)
577 AC_MSG_RESULT($padlocksupport)
578 if test x"$padlocksupport" = xyes ; then
579   AC_DEFINE(ENABLE_PADLOCK_SUPPORT, 1,
580             [Enable support for the PadLock engine.])
581 fi
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-pclmul-support switch.
592 AC_MSG_CHECKING([whether PCLMUL support is requested])
593 AC_ARG_ENABLE(pclmul-support,
594               AC_HELP_STRING([--disable-pclmul-support],
595                  [Disable support for the Intel PCLMUL instructions]),
596               pclmulsupport=$enableval,pclmulsupport=yes)
597 AC_MSG_RESULT($pclmulsupport)
598
599 # Implementation of the --disable-drng-support switch.
600 AC_MSG_CHECKING([whether DRNG support is requested])
601 AC_ARG_ENABLE(drng-support,
602               AC_HELP_STRING([--disable-drng-support],
603                  [Disable support for the Intel DRNG (RDRAND instruction)]),
604               drngsupport=$enableval,drngsupport=yes)
605 AC_MSG_RESULT($drngsupport)
606 if test x"$drngsupport" = xyes ; then
607   AC_DEFINE(ENABLE_DRNG_SUPPORT, 1,
608             [Enable support for Intel DRNG (RDRAND instruction).])
609 fi
610
611 # Implementation of the --disable-avx-support switch.
612 AC_MSG_CHECKING([whether AVX support is requested])
613 AC_ARG_ENABLE(avx-support,
614               AC_HELP_STRING([--disable-avx-support],
615                  [Disable support for the Intel AVX instructions]),
616               avxsupport=$enableval,avxsupport=yes)
617 AC_MSG_RESULT($avxsupport)
618
619 # Implementation of the --disable-avx2-support switch.
620 AC_MSG_CHECKING([whether AVX2 support is requested])
621 AC_ARG_ENABLE(avx2-support,
622               AC_HELP_STRING([--disable-avx2-support],
623                  [Disable support for the Intel AVX2 instructions]),
624               avx2support=$enableval,avx2support=yes)
625 AC_MSG_RESULT($avx2support)
626
627 # Implementation of the --disable-neon-support switch.
628 AC_MSG_CHECKING([whether NEON support is requested])
629 AC_ARG_ENABLE(neon-support,
630               AC_HELP_STRING([--disable-neon-support],
631                  [Disable support for the ARM NEON instructions]),
632               neonsupport=$enableval,neonsupport=yes)
633 AC_MSG_RESULT($neonsupport)
634
635 # Implementation of the --disable-O-flag-munging switch.
636 AC_MSG_CHECKING([whether a -O flag munging is requested])
637 AC_ARG_ENABLE([O-flag-munging],
638               AC_HELP_STRING([--disable-O-flag-munging],
639                  [Disable modification of the cc -O flag]),
640               [enable_o_flag_munging=$enableval],
641               [enable_o_flag_munging=yes])
642 AC_MSG_RESULT($enable_o_flag_munging)
643 AM_CONDITIONAL(ENABLE_O_FLAG_MUNGING, test "$enable_o_flag_munging" = "yes")
644
645 # Implementation of the --disable-amd64-as-feature-detection switch.
646 AC_MSG_CHECKING([whether to enable AMD64 as(1) feature detection])
647 AC_ARG_ENABLE(amd64-as-feature-detection,
648               AC_HELP_STRING([--disable-amd64-as-feature-detection],
649                  [Disable the auto-detection of AMD64 as(1) features]),
650               amd64_as_feature_detection=$enableval,
651               amd64_as_feature_detection=yes)
652 AC_MSG_RESULT($amd64_as_feature_detection)
653
654
655 AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
656                    [A human readable text with the name of the OS])
657
658 # For some systems we know that we have ld_version scripts.
659 # Use it then as default.
660 have_ld_version_script=no
661 case "${host}" in
662     *-*-linux*)
663         have_ld_version_script=yes
664         ;;
665     *-*-gnu*)
666         have_ld_version_script=yes
667         ;;
668 esac
669 AC_ARG_ENABLE([ld-version-script],
670               AC_HELP_STRING([--enable-ld-version-script],
671                              [enable/disable use of linker version script.
672                               (default is system dependent)]),
673               [have_ld_version_script=$enableval],
674               [ : ] )
675 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
676
677 AC_DEFINE_UNQUOTED(NAME_OF_DEV_RANDOM, "$NAME_OF_DEV_RANDOM",
678                    [defined to the name of the strong random device])
679 AC_DEFINE_UNQUOTED(NAME_OF_DEV_URANDOM, "$NAME_OF_DEV_URANDOM",
680                    [defined to the name of the weaker random device])
681
682
683 ###############################
684 #### Checks for libraries. ####
685 ###############################
686
687 #
688 # gpg-error is required.
689 #
690 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
691 if test "x$GPG_ERROR_LIBS" = "x"; then
692   AC_MSG_ERROR([libgpg-error is needed.
693                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
694 fi
695
696 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GCRYPT,
697           [The default error source for libgcrypt.])
698
699 #
700 # Check whether the GNU Pth library is available.  We require this
701 # to build the optional gcryptrnd program.
702 #
703 AC_ARG_WITH(pth-prefix,
704             AC_HELP_STRING([--with-pth-prefix=PFX],
705                            [prefix where GNU Pth is installed (optional)]),
706      pth_config_prefix="$withval", pth_config_prefix="")
707 if test x$pth_config_prefix != x ; then
708    PTH_CONFIG="$pth_config_prefix/bin/pth-config"
709 fi
710 if test "$use_random_daemon" = "yes"; then
711   AC_PATH_PROG(PTH_CONFIG, pth-config, no)
712   if test "$PTH_CONFIG" = "no"; then
713     AC_MSG_WARN([[
714 ***
715 *** To build the Libgcrypt's random number daemon
716 *** we need the support of the GNU Portable Threads Library.
717 *** Download it from ftp://ftp.gnu.org/gnu/pth/
718 *** On a Debian GNU/Linux system you might want to try
719 ***   apt-get install libpth-dev
720 ***]])
721   else
722     GNUPG_PTH_VERSION_CHECK([1.3.7])
723     if test $have_pth = yes; then
724        PTH_CFLAGS=`$PTH_CONFIG --cflags`
725        PTH_LIBS=`$PTH_CONFIG --ldflags`
726        PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`"
727        AC_DEFINE(USE_GNU_PTH, 1,
728                 [Defined if the GNU Portable Thread Library should be used])
729        AC_DEFINE(HAVE_PTH, 1,
730                 [Defined if the GNU Pth is available])
731     fi
732   fi
733 fi
734 AC_SUBST(PTH_CFLAGS)
735 AC_SUBST(PTH_LIBS)
736
737 #
738 # Check whether pthreads is available
739 #
740 AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
741 if test "$have_pthread" = yes; then
742    AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
743 fi
744
745
746 # Solaris needs -lsocket and -lnsl. Unisys system includes
747 # gethostbyname in libsocket but needs libnsl for socket.
748 AC_SEARCH_LIBS(setsockopt, [socket], ,
749         [AC_SEARCH_LIBS(setsockopt, [socket], , , [-lnsl])])
750 AC_SEARCH_LIBS(setsockopt, [nsl])
751
752 ##################################
753 #### Checks for header files. ####
754 ##################################
755
756 AC_HEADER_STDC
757 AC_CHECK_HEADERS(unistd.h sys/select.h sys/msg.h)
758 INSERT_SYS_SELECT_H=
759 if test x"$ac_cv_header_sys_select_h" = xyes; then
760   INSERT_SYS_SELECT_H=" include <sys/select.h>"
761 fi
762 AC_SUBST(INSERT_SYS_SELECT_H)
763
764
765 ##########################################
766 #### Checks for typedefs, structures, ####
767 ####  and compiler characteristics.   ####
768 ##########################################
769
770 AC_C_CONST
771 AC_C_INLINE
772 AC_TYPE_SIZE_T
773 AC_TYPE_SIGNAL
774 AC_DECL_SYS_SIGLIST
775 AC_TYPE_PID_T
776
777 GNUPG_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF)
778 GNUPG_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF)
779 GNUPG_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF)
780 GNUPG_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF)
781 GNUPG_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)
782
783 gl_TYPE_SOCKLEN_T
784 case "${host}" in
785   *-*-mingw32*)
786     # socklen_t may or may not be defined depending on what headers
787     # are included.  To be safe we use int as this is the actual type.
788     FALLBACK_SOCKLEN_T="typedef int gcry_socklen_t;"
789     ;;
790   *)
791     if test ".$gl_cv_socklen_t_equiv" = "."; then
792       FALLBACK_SOCKLEN_T="typedef socklen_t gcry_socklen_t;"
793     else
794       FALLBACK_SOCKLEN_T="typedef ${gl_cv_socklen_t_equiv} gcry_socklen_t;"
795     fi
796 esac
797 AC_SUBST(FALLBACK_SOCKLEN_T)
798
799
800 #
801 # Check for __builtin_bswap32 intrinsic.
802 #
803 AC_CACHE_CHECK(for __builtin_bswap32,
804        [gcry_cv_have_builtin_bswap32],
805        [gcry_cv_have_builtin_bswap32=no
806         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
807           [int x = 0; int y = __builtin_bswap32(x); return y;])],
808           [gcry_cv_have_builtin_bswap32=yes])])
809 if test "$gcry_cv_have_builtin_bswap32" = "yes" ; then
810    AC_DEFINE(HAVE_BUILTIN_BSWAP32,1,
811              [Defined if compiler has '__builtin_bswap32' intrinsic])
812 fi
813
814
815 #
816 # Check for __builtin_bswap64 intrinsic.
817 #
818 AC_CACHE_CHECK(for __builtin_bswap64,
819        [gcry_cv_have_builtin_bswap64],
820        [gcry_cv_have_builtin_bswap64=no
821         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
822           [long long x = 0; long long y = __builtin_bswap64(x); return y;])],
823           [gcry_cv_have_builtin_bswap64=yes])])
824 if test "$gcry_cv_have_builtin_bswap64" = "yes" ; then
825    AC_DEFINE(HAVE_BUILTIN_BSWAP64,1,
826              [Defined if compiler has '__builtin_bswap64' intrinsic])
827 fi
828
829
830 #
831 # Check for VLA support (variable length arrays).
832 #
833 AC_CACHE_CHECK(whether the variable length arrays are supported,
834        [gcry_cv_have_vla],
835        [gcry_cv_have_vla=no
836         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
837           [[void f1(char *, int);
838             char foo(int i) {
839               char b[(i < 0 ? 0 : i) + 1];
840               f1(b, sizeof b); return b[0];}]])],
841           [gcry_cv_have_vla=yes])])
842 if test "$gcry_cv_have_vla" = "yes" ; then
843    AC_DEFINE(HAVE_VLA,1, [Defined if variable length arrays are supported])
844 fi
845
846
847 #
848 # Check for ELF visibility support.
849 #
850 AC_CACHE_CHECK(whether the visibility attribute is supported,
851        gcry_cv_visibility_attribute,
852        [gcry_cv_visibility_attribute=no
853         AC_LANG_CONFTEST([AC_LANG_SOURCE(
854           [[int foo __attribute__ ((visibility ("hidden"))) = 1;
855             int bar __attribute__ ((visibility ("protected"))) = 1;
856           ]])])
857
858         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
859                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
860             if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
861                 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
862                     gcry_cv_visibility_attribute=yes
863                 fi
864             fi
865         fi
866        ])
867 if test "$gcry_cv_visibility_attribute" = "yes"; then
868     AC_CACHE_CHECK(for broken visibility attribute,
869        gcry_cv_broken_visibility_attribute,
870        [gcry_cv_broken_visibility_attribute=yes
871         AC_LANG_CONFTEST([AC_LANG_SOURCE(
872           [[int foo (int x);
873             int bar (int x) __asm__ ("foo")
874                             __attribute__ ((visibility ("hidden")));
875             int bar (int x) { return x; }
876           ]])])
877
878         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
879                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
880            if grep '\.hidden@<:@        _@:>@foo' conftest.s >/dev/null 2>&1;
881             then
882                gcry_cv_broken_visibility_attribute=no
883            fi
884         fi
885        ])
886 fi
887 if test "$gcry_cv_visibility_attribute" = "yes"; then
888     AC_CACHE_CHECK(for broken alias attribute,
889        gcry_cv_broken_alias_attribute,
890        [gcry_cv_broken_alias_attribute=yes
891         AC_LANG_CONFTEST([AC_LANG_SOURCE(
892           [[extern int foo (int x) __asm ("xyzzy");
893             int bar (int x) { return x; }
894             extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
895             extern int dfoo;
896             extern __typeof (dfoo) dfoo __asm ("abccb");
897             int dfoo = 1;
898           ]])])
899
900         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
901                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
902            if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
903               grep 'abccb' conftest.s >/dev/null 2>&1; then
904               gcry_cv_broken_alias_attribute=no
905            fi
906         fi
907         ])
908 fi
909 if test "$gcry_cv_visibility_attribute" = "yes"; then
910     AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
911        gcry_cv_gcc_has_f_visibility,
912        [gcry_cv_gcc_has_f_visibility=no
913         _gcc_cflags_save=$CFLAGS
914         CFLAGS="-fvisibility=hidden"
915         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
916                           gcry_cv_gcc_has_f_visibility=yes)
917         CFLAGS=$_gcc_cflags_save;
918        ])
919 fi
920 if test "$gcry_cv_visibility_attribute" = "yes" \
921    && test "$gcry_cv_broken_visibility_attribute" != "yes" \
922    && test "$gcry_cv_broken_alias_attribute" != "yes" \
923    && test "$gcry_cv_gcc_has_f_visibility" = "yes"
924  then
925    AC_DEFINE(GCRY_USE_VISIBILITY, 1,
926                [Define to use the GNU C visibility attribute.])
927    CFLAGS="$CFLAGS -fvisibility=hidden"
928 fi
929
930
931 #
932 # Check whether the compiler supports the GCC style aligned attribute
933 #
934 AC_CACHE_CHECK([whether the GCC style aligned attribute is supported],
935        [gcry_cv_gcc_attribute_aligned],
936        [gcry_cv_gcc_attribute_aligned=no
937         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
938           [[struct { int a; } foo __attribute__ ((aligned (16)));]])],
939           [gcry_cv_gcc_attribute_aligned=yes])])
940 if test "$gcry_cv_gcc_attribute_aligned" = "yes" ; then
941    AC_DEFINE(HAVE_GCC_ATTRIBUTE_ALIGNED,1,
942      [Defined if a GCC style "__attribute__ ((aligned (n))" is supported])
943 fi
944
945
946 #
947 # Check whether the compiler supports 'asm' or '__asm__' keyword for
948 # assembler blocks.
949 #
950 AC_CACHE_CHECK([whether 'asm' assembler keyword is supported],
951        [gcry_cv_have_asm],
952        [gcry_cv_have_asm=no
953         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
954           [[void a(void) { asm("":::"memory"); }]])],
955           [gcry_cv_have_asm=yes])])
956 AC_CACHE_CHECK([whether '__asm__' assembler keyword is supported],
957        [gcry_cv_have___asm__],
958        [gcry_cv_have___asm__=no
959         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
960           [[void a(void) { __asm__("":::"memory"); }]])],
961           [gcry_cv_have___asm__=yes])])
962 if test "$gcry_cv_have_asm" = "no" ; then
963    if test "$gcry_cv_have___asm__" = "yes" ; then
964       AC_DEFINE(asm,__asm__,
965         [Define to supported assembler block keyword, if plain 'asm' was not
966          supported])
967    fi
968 fi
969
970
971 #
972 # Check whether the compiler supports inline assembly memory barrier.
973 #
974 if test "$gcry_cv_have_asm" = "no" ; then
975    if test "$gcry_cv_have___asm__" = "yes" ; then
976       AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
977           [gcry_cv_have_asm_volatile_memory],
978           [gcry_cv_have_asm_volatile_memory=no
979            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
980              [[void a(void) { __asm__ volatile("":::"memory"); }]])],
981              [gcry_cv_have_asm_volatile_memory=yes])])
982    fi
983 else
984    AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
985        [gcry_cv_have_asm_volatile_memory],
986        [gcry_cv_have_asm_volatile_memory=no
987         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
988           [[void a(void) { asm volatile("":::"memory"); }]])],
989           [gcry_cv_have_asm_volatile_memory=yes])])
990 fi
991 if test "$gcry_cv_have_asm_volatile_memory" = "yes" ; then
992    AC_DEFINE(HAVE_GCC_ASM_VOLATILE_MEMORY,1,
993      [Define if inline asm memory barrier is supported])
994 fi
995
996
997 #
998 # Check whether GCC inline assembler supports SSSE3 instructions
999 # This is required for the AES-NI instructions.
1000 #
1001 AC_CACHE_CHECK([whether GCC inline assembler supports SSSE3 instructions],
1002        [gcry_cv_gcc_inline_asm_ssse3],
1003        [gcry_cv_gcc_inline_asm_ssse3=no
1004         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1005           [[static unsigned char be_mask[16] __attribute__ ((aligned (16))) =
1006               { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
1007             void a(void) {
1008               __asm__("pshufb %[mask], %%xmm2\n\t"::[mask]"m"(*be_mask):);
1009             }]])],
1010           [gcry_cv_gcc_inline_asm_ssse3=yes])])
1011 if test "$gcry_cv_gcc_inline_asm_ssse3" = "yes" ; then
1012    AC_DEFINE(HAVE_GCC_INLINE_ASM_SSSE3,1,
1013      [Defined if inline assembler supports SSSE3 instructions])
1014 fi
1015
1016
1017 #
1018 # Check whether GCC inline assembler supports PCLMUL instructions.
1019 #
1020 AC_CACHE_CHECK([whether GCC inline assembler supports PCLMUL instructions],
1021        [gcry_cv_gcc_inline_asm_pclmul],
1022        [gcry_cv_gcc_inline_asm_pclmul=no
1023         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1024           [[void a(void) {
1025               __asm__("pclmulqdq \$0, %%xmm1, %%xmm3\n\t":::"cc");
1026             }]])],
1027           [gcry_cv_gcc_inline_asm_pclmul=yes])])
1028 if test "$gcry_cv_gcc_inline_asm_pclmul" = "yes" ; then
1029    AC_DEFINE(HAVE_GCC_INLINE_ASM_PCLMUL,1,
1030      [Defined if inline assembler supports PCLMUL instructions])
1031 fi
1032
1033
1034 #
1035 # Check whether GCC inline assembler supports AVX instructions
1036 #
1037 AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions],
1038        [gcry_cv_gcc_inline_asm_avx],
1039        [gcry_cv_gcc_inline_asm_avx=no
1040         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1041           [[void a(void) {
1042               __asm__("xgetbv; vaesdeclast (%[mem]),%%xmm0,%%xmm7\n\t"::[mem]"r"(0):);
1043             }]])],
1044           [gcry_cv_gcc_inline_asm_avx=yes])])
1045 if test "$gcry_cv_gcc_inline_asm_avx" = "yes" ; then
1046    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX,1,
1047      [Defined if inline assembler supports AVX instructions])
1048 fi
1049
1050
1051 #
1052 # Check whether GCC inline assembler supports AVX2 instructions
1053 #
1054 AC_CACHE_CHECK([whether GCC inline assembler supports AVX2 instructions],
1055        [gcry_cv_gcc_inline_asm_avx2],
1056        [gcry_cv_gcc_inline_asm_avx2=no
1057         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1058           [[void a(void) {
1059               __asm__("xgetbv; vpbroadcastb %%xmm7,%%ymm1\n\t":::"cc");
1060             }]])],
1061           [gcry_cv_gcc_inline_asm_avx2=yes])])
1062 if test "$gcry_cv_gcc_inline_asm_avx2" = "yes" ; then
1063    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX2,1,
1064      [Defined if inline assembler supports AVX2 instructions])
1065 fi
1066
1067
1068 #
1069 # Check whether GCC inline assembler supports BMI2 instructions
1070 #
1071 AC_CACHE_CHECK([whether GCC inline assembler supports BMI2 instructions],
1072        [gcry_cv_gcc_inline_asm_bmi2],
1073        [gcry_cv_gcc_inline_asm_bmi2=no
1074         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1075           [[void a(void) {
1076               __asm__("rorxl \$23, %%eax, %%edx\\n\\t":::"memory");
1077             }]])],
1078           [gcry_cv_gcc_inline_asm_bmi2=yes])])
1079 if test "$gcry_cv_gcc_inline_asm_bmi2" = "yes" ; then
1080    AC_DEFINE(HAVE_GCC_INLINE_ASM_BMI2,1,
1081      [Defined if inline assembler supports BMI2 instructions])
1082 fi
1083
1084
1085 #
1086 # Check whether GCC assembler needs "-Wa,--divide" to correctly handle
1087 # constant division
1088 #
1089 if test $amd64_as_feature_detection = yes; then
1090   AC_CACHE_CHECK([whether GCC assembler handles division correctly],
1091        [gcry_cv_gcc_as_const_division_ok],
1092        [gcry_cv_gcc_as_const_division_ok=no
1093         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1094           [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
1095           [gcry_cv_gcc_as_const_division_ok=yes])])
1096   if test "$gcry_cv_gcc_as_const_division_ok" = "no" ; then
1097     #
1098     # Add '-Wa,--divide' to CPPFLAGS and try check again.
1099     #
1100     _gcc_cppflags_save="$CPPFLAGS"
1101     CPPFLAGS="$CPPFLAGS -Wa,--divide"
1102     AC_CACHE_CHECK([whether GCC assembler handles division correctly with "-Wa,--divide"],
1103          [gcry_cv_gcc_as_const_division_with_wadivide_ok],
1104          [gcry_cv_gcc_as_const_division_with_wadivide_ok=no
1105           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1106             [[__asm__("xorl \$(123456789/12345678), %ebp;\n\t");]])],
1107             [gcry_cv_gcc_as_const_division_with_wadivide_ok=yes])])
1108     if test "$gcry_cv_gcc_as_const_division_with_wadivide_ok" = "no" ; then
1109       # '-Wa,--divide' did not work, restore old flags.
1110       CPPFLAGS="$_gcc_cppflags_save"
1111     fi
1112   fi
1113 fi
1114
1115
1116 #
1117 # Check whether GCC assembler supports features needed for our amd64
1118 # implementations
1119 #
1120 if test $amd64_as_feature_detection = yes; then
1121   AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
1122        [gcry_cv_gcc_amd64_platform_as_ok],
1123        [gcry_cv_gcc_amd64_platform_as_ok=no
1124         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1125           [[__asm__(
1126                 /* Test if '.type' and '.size' are supported.  */
1127                 /* These work only on ELF targets. */
1128                 /* TODO: add COFF (mingw64, cygwin64) support to assembly
1129                  * implementations.  Mingw64/cygwin64 also require additional
1130                  * work because they use different calling convention. */
1131                 "asmfunc:\n\t"
1132                 ".size asmfunc,.-asmfunc;\n\t"
1133                 ".type asmfunc,@function;\n\t"
1134                 /* Test if assembler allows use of '/' for constant division
1135                  * (Solaris/x86 issue). If previous constant division check
1136                  * and "-Wa,--divide" workaround failed, this causes assembly
1137                  * to be disable on this machine. */
1138                 "xorl \$(123456789/12345678), %ebp;\n\t"
1139             );]])],
1140           [gcry_cv_gcc_amd64_platform_as_ok=yes])])
1141   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then
1142      AC_DEFINE(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS,1,
1143               [Defined if underlying assembler is compatible with amd64 assembly implementations])
1144   fi
1145 fi
1146
1147
1148 #
1149 # Check whether GCC assembler supports features needed for assembly
1150 # implementations that use Intel syntax
1151 #
1152 AC_CACHE_CHECK([whether GCC assembler is compatible for Intel syntax assembly implementations],
1153        [gcry_cv_gcc_platform_as_ok_for_intel_syntax],
1154        [gcry_cv_gcc_platform_as_ok_for_intel_syntax=no
1155         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1156           [[__asm__(
1157                 ".intel_syntax noprefix\n\t"
1158                 "pxor xmm1, xmm7;\n\t"
1159                 /* Intel syntax implementation also use GAS macros, so check
1160                  * for them here. */
1161                 "VAL_A = xmm4\n\t"
1162                 "VAL_B = xmm2\n\t"
1163                 ".macro SET_VAL_A p1\n\t"
1164                 "  VAL_A = \\\\p1 \n\t"
1165                 ".endm\n\t"
1166                 ".macro SET_VAL_B p1\n\t"
1167                 "  VAL_B = \\\\p1 \n\t"
1168                 ".endm\n\t"
1169                 "vmovdqa VAL_A, VAL_B;\n\t"
1170                 "SET_VAL_A eax\n\t"
1171                 "SET_VAL_B ebp\n\t"
1172                 "add VAL_A, VAL_B;\n\t"
1173                 "add VAL_B, 0b10101;\n\t"
1174             );]])],
1175           [gcry_cv_gcc_platform_as_ok_for_intel_syntax=yes])])
1176 if test "$gcry_cv_gcc_platform_as_ok_for_intel_syntax" = "yes" ; then
1177   AC_DEFINE(HAVE_INTEL_SYNTAX_PLATFORM_AS,1,
1178             [Defined if underlying assembler is compatible with Intel syntax assembly implementations])
1179 fi
1180
1181
1182 #
1183 # Check whether compiler is configured for ARMv6 or newer architecture
1184 #
1185 AC_CACHE_CHECK([whether compiler is configured for ARMv6 or newer architecture],
1186        [gcry_cv_cc_arm_arch_is_v6],
1187        [AC_EGREP_CPP(yes,
1188           [#if defined(__arm__) && \
1189              ((defined(__ARM_ARCH) && __ARM_ARCH >= 6) \
1190              || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
1191              || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \
1192              || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) \
1193              || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
1194              || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
1195              || defined(__ARM_ARCH_7EM__))
1196             yes
1197            #endif
1198           ], gcry_cv_cc_arm_arch_is_v6=yes, gcry_cv_cc_arm_arch_is_v6=no)])
1199 if test "$gcry_cv_cc_arm_arch_is_v6" = "yes" ; then
1200    AC_DEFINE(HAVE_ARM_ARCH_V6,1,
1201      [Defined if ARM architecture is v6 or newer])
1202 fi
1203
1204
1205 #
1206 # Check whether GCC inline assembler supports NEON instructions
1207 #
1208 AC_CACHE_CHECK([whether GCC inline assembler supports NEON instructions],
1209        [gcry_cv_gcc_inline_asm_neon],
1210        [gcry_cv_gcc_inline_asm_neon=no
1211         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1212           [[__asm__(
1213                 ".syntax unified\n\t"
1214                 ".thumb\n\t"
1215                 ".fpu neon\n\t"
1216                 "vld1.64 {%q0-%q1}, [%r0]!;\n\t"
1217                 "vrev64.8 %q0, %q3;\n\t"
1218                 "vadd.u64 %q0, %q1;\n\t"
1219                 "vadd.s64 %d3, %d2, %d3;\n\t"
1220                 );
1221             ]])],
1222           [gcry_cv_gcc_inline_asm_neon=yes])])
1223 if test "$gcry_cv_gcc_inline_asm_neon" = "yes" ; then
1224    AC_DEFINE(HAVE_GCC_INLINE_ASM_NEON,1,
1225      [Defined if inline assembler supports NEON instructions])
1226 fi
1227
1228
1229 #
1230 # Check whether GCC assembler supports features needed for our ARM
1231 # implementations
1232 #
1233 AC_CACHE_CHECK([whether GCC assembler is compatible for ARM assembly implementations],
1234        [gcry_cv_gcc_arm_platform_as_ok],
1235        [gcry_cv_gcc_arm_platform_as_ok=no
1236         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1237           [[__asm__(
1238                 /* Test if assembler supports UAL syntax.  */
1239                 ".syntax unified\n\t"
1240                 ".arm\n\t" /* our assembly code is in ARM mode  */
1241                 /* Following causes error if assembler ignored '.syntax unified'.  */
1242                 "asmfunc:\n\t"
1243                 "add %r0, %r0, %r4, ror #12;\n\t"
1244
1245                 /* Test if '.type' and '.size' are supported.  */
1246                 ".size asmfunc,.-asmfunc;\n\t"
1247                 ".type asmfunc,%function;\n\t"
1248             );]])],
1249           [gcry_cv_gcc_arm_platform_as_ok=yes])])
1250 if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
1251    AC_DEFINE(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS,1,
1252      [Defined if underlying assembler is compatible with ARM assembly implementations])
1253 fi
1254
1255
1256 #######################################
1257 #### Checks for library functions. ####
1258 #######################################
1259
1260 AC_FUNC_VPRINTF
1261 # We have replacements for these in src/missing-string.c
1262 AC_CHECK_FUNCS(stpcpy strcasecmp)
1263 # We have replacements for these in src/g10lib.h
1264 AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise)
1265 # Other checks
1266 AC_CHECK_FUNCS(strerror rand mmap getpagesize sysconf waitpid wait4)
1267 AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime syslog)
1268 AC_CHECK_FUNCS(fcntl ftruncate)
1269
1270 GNUPG_CHECK_MLOCK
1271
1272 #
1273 # Replacement functions.
1274 #
1275 AC_REPLACE_FUNCS([getpid clock])
1276
1277
1278 #
1279 # Check wether it is necessary to link against libdl.
1280 #
1281 DL_LIBS=""
1282 if test "$use_hmac_binary_check" = yes ; then
1283   _gcry_save_libs="$LIBS"
1284   LIBS=""
1285   AC_SEARCH_LIBS(dlopen, c dl,,,)
1286   DL_LIBS=$LIBS
1287   LIBS="$_gcry_save_libs"
1288   LIBGCRYPT_CONFIG_LIBS="${LIBGCRYPT_CONFIG_LIBS} ${DL_LIBS}"
1289 fi
1290 AC_SUBST(DL_LIBS)
1291
1292
1293 #
1294 # Check whether we can use Linux capabilities as requested.
1295 #
1296 if test "$use_capabilities" = "yes" ; then
1297 use_capabilities=no
1298 AC_CHECK_HEADERS(sys/capability.h)
1299 if test "$ac_cv_header_sys_capability_h" = "yes" ; then
1300   AC_CHECK_LIB(cap, cap_init, ac_need_libcap=1)
1301   if test "$ac_cv_lib_cap_cap_init" = "yes"; then
1302      AC_DEFINE(USE_CAPABILITIES,1,
1303                [define if capabilities should be used])
1304      LIBS="$LIBS -lcap"
1305      use_capabilities=yes
1306   fi
1307 fi
1308 if test "$use_capabilities" = "no" ; then
1309     AC_MSG_WARN([[
1310 ***
1311 *** The use of capabilities on this system is not possible.
1312 *** You need a recent Linux kernel and some patches:
1313 ***   fcaps-2.2.9-990610.patch      (kernel patch for 2.2.9)
1314 ***   fcap-module-990613.tar.gz     (kernel module)
1315 ***   libcap-1.92.tar.gz            (user mode library and utilities)
1316 *** And you have to configure the kernel with CONFIG_VFS_CAP_PLUGIN
1317 *** set (filesystems menu). Be warned: This code is *really* ALPHA.
1318 ***]])
1319 fi
1320 fi
1321
1322 # Check whether a random device is available.
1323 if test "$try_dev_random" = yes ; then
1324     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
1325     [if test -r "$NAME_OF_DEV_RANDOM" && test -r "$NAME_OF_DEV_URANDOM" ; then
1326       ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
1327     if test "$ac_cv_have_dev_random" = yes; then
1328         AC_DEFINE(HAVE_DEV_RANDOM,1,
1329                  [defined if the system supports a random device] )
1330     fi
1331 else
1332     AC_MSG_CHECKING(for random device)
1333     ac_cv_have_dev_random=no
1334     AC_MSG_RESULT(has been disabled)
1335 fi
1336
1337 # Figure out the random modules for this configuration.
1338 if test "$random" = "default"; then
1339
1340     # Select default value.
1341     if test "$ac_cv_have_dev_random" = yes; then
1342         # Try Linuxish random device.
1343         random_modules="linux"
1344     else
1345         case "${host}" in
1346         *-*-mingw32ce*)
1347           # WindowsCE random device.
1348           random_modules="w32ce"
1349           ;;
1350         *-*-mingw32*|*-*-cygwin*)
1351           # Windows random device.
1352           random_modules="w32"
1353           ;;
1354         *)
1355           # Build everything, allow to select at runtime.
1356           random_modules="$auto_random_modules"
1357           ;;
1358         esac
1359     fi
1360 else
1361     if test "$random" = "auto"; then
1362         # Build everything, allow to select at runtime.
1363         random_modules="$auto_random_modules"
1364     else
1365         random_modules="$random"
1366     fi
1367 fi
1368
1369
1370 #
1371 # Setup assembler stuff.
1372 #
1373 # Note that config.links also defines mpi_cpu_arch, which is required
1374 # later on.
1375 #
1376 GNUPG_SYS_SYMBOL_UNDERSCORE()
1377 AC_ARG_ENABLE(mpi-path,
1378               AC_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
1379               [prepend EXTRA_PATH to list of CPU specific optimizations]),
1380               mpi_extra_path="$enableval",mpi_extra_path="")
1381 AC_MSG_CHECKING(for mpi assembler functions)
1382 if test -f $srcdir/mpi/config.links ; then
1383     . $srcdir/mpi/config.links
1384     AC_CONFIG_LINKS("$mpi_ln_list")
1385     ac_cv_mpi_sflags="$mpi_sflags"
1386     AC_MSG_RESULT(done)
1387 else
1388     AC_MSG_RESULT(failed)
1389     AC_MSG_ERROR([mpi/config.links missing!])
1390 fi
1391 MPI_SFLAGS="$ac_cv_mpi_sflags"
1392 AC_SUBST(MPI_SFLAGS)
1393
1394 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
1395 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
1396 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
1397 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
1398 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
1399 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
1400 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
1401 AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
1402 AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
1403 AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
1404 AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
1405 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
1406 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
1407 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
1408 AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
1409 AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
1410 AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
1411 AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
1412
1413 if test mym4_isgit = "yes"; then
1414     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
1415               [Defined if this is not a regular release])
1416 fi
1417
1418
1419 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
1420
1421
1422 # This is handy for debugging so the compiler doesn't rearrange
1423 # things and eliminate variables.
1424 AC_ARG_ENABLE(optimization,
1425        AC_HELP_STRING([--disable-optimization],
1426                       [disable compiler optimization]),
1427                       [if test $enableval = no ; then
1428                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
1429                        fi])
1430
1431 # CFLAGS mangling when using gcc.
1432 if test "$GCC" = yes; then
1433     CFLAGS="$CFLAGS -Wall"
1434     if test "$USE_MAINTAINER_MODE" = "yes"; then
1435         CFLAGS="$CFLAGS -Wcast-align -Wshadow -Wstrict-prototypes"
1436         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
1437
1438         # If -Wno-missing-field-initializers is supported we can enable a
1439         # a bunch of really useful warnings.
1440         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
1441         _gcc_cflags_save=$CFLAGS
1442         CFLAGS="-Wno-missing-field-initializers"
1443         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
1444         AC_MSG_RESULT($_gcc_wopt)
1445         CFLAGS=$_gcc_cflags_save;
1446         if test x"$_gcc_wopt" = xyes ; then
1447           CFLAGS="$CFLAGS -W -Wextra -Wbad-function-cast"
1448           CFLAGS="$CFLAGS -Wwrite-strings"
1449           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
1450           CFLAGS="$CFLAGS -Wno-missing-field-initializers"
1451           CFLAGS="$CFLAGS -Wno-sign-compare"
1452         fi
1453
1454         AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
1455         _gcc_cflags_save=$CFLAGS
1456         CFLAGS="-Wpointer-arith"
1457         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
1458         AC_MSG_RESULT($_gcc_wopt)
1459         CFLAGS=$_gcc_cflags_save;
1460         if test x"$_gcc_wopt" = xyes ; then
1461           CFLAGS="$CFLAGS -Wpointer-arith"
1462         fi
1463     fi
1464
1465 fi
1466
1467 # Check whether as(1) supports a noeexecstack feature.  This test
1468 # includes an override option.
1469 CL_AS_NOEXECSTACK
1470
1471
1472 AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION)
1473 AC_SUBST(LIBGCRYPT_CONFIG_LIBS)
1474 AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS)
1475 AC_SUBST(LIBGCRYPT_CONFIG_HOST)
1476 AC_SUBST(LIBGCRYPT_THREAD_MODULES)
1477
1478 AC_CONFIG_COMMANDS([gcrypt-conf],[[
1479 chmod +x src/libgcrypt-config
1480 ]],[[
1481 prefix=$prefix
1482 exec_prefix=$exec_prefix
1483 libdir=$libdir
1484 datadir=$datadir
1485 DATADIRNAME=$DATADIRNAME
1486 ]])
1487
1488 #####################
1489 #### Conclusion. ####
1490 #####################
1491
1492 # Check that requested feature can actually be used and define
1493 # ENABLE_foo_SUPPORT macros.
1494
1495 if test x"$aesnisupport" = xyes ; then
1496   if test "$gcry_cv_gcc_inline_asm_ssse3" != "yes" ; then
1497     aesnisupport="no (unsupported by compiler)"
1498   fi
1499 fi
1500 if test x"$pclmulsupport" = xyes ; then
1501   if test "$gcry_cv_gcc_inline_asm_pclmul" != "yes" ; then
1502     pclmulsupport="no (unsupported by compiler)"
1503   fi
1504 fi
1505 if test x"$avxsupport" = xyes ; then
1506   if test "$gcry_cv_gcc_inline_asm_avx" != "yes" ; then
1507     avxsupport="no (unsupported by compiler)"
1508   fi
1509 fi
1510 if test x"$avx2support" = xyes ; then
1511   if test "$gcry_cv_gcc_inline_asm_avx2" != "yes" ; then
1512     avx2support="no (unsupported by compiler)"
1513   fi
1514 fi
1515 if test x"$neonsupport" = xyes ; then
1516   if test "$gcry_cv_gcc_inline_asm_neon" != "yes" ; then
1517     neonsupport="no (unsupported by compiler)"
1518   fi
1519 fi
1520
1521 if test x"$aesnisupport" = xyes ; then
1522   AC_DEFINE(ENABLE_AESNI_SUPPORT, 1,
1523             [Enable support for Intel AES-NI instructions.])
1524 fi
1525 if test x"$pclmulsupport" = xyes ; then
1526   AC_DEFINE(ENABLE_PCLMUL_SUPPORT, 1,
1527             [Enable support for Intel PCLMUL instructions.])
1528 fi
1529 if test x"$avxsupport" = xyes ; then
1530   AC_DEFINE(ENABLE_AVX_SUPPORT,1,
1531             [Enable support for Intel AVX instructions.])
1532 fi
1533 if test x"$avx2support" = xyes ; then
1534   AC_DEFINE(ENABLE_AVX2_SUPPORT,1,
1535             [Enable support for Intel AVX2 instructions.])
1536 fi
1537 if test x"$neonsupport" = xyes ; then
1538   AC_DEFINE(ENABLE_NEON_SUPPORT,1,
1539             [Enable support for ARM NEON instructions.])
1540 fi
1541
1542
1543 # Define conditional sources and config.h symbols depending on the
1544 # selected ciphers, pubkey-ciphers, digests, kdfs, and random modules.
1545
1546 LIST_MEMBER(arcfour, $enabled_ciphers)
1547 if test "$found" = "1"; then
1548    GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo"
1549    AC_DEFINE(USE_ARCFOUR, 1, [Defined if this module should be included])
1550
1551    case "${host}" in
1552       x86_64-*-*)
1553          # Build with the assembly implementation
1554          GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour-amd64.lo"
1555       ;;
1556    esac
1557 fi
1558
1559 LIST_MEMBER(blowfish, $enabled_ciphers)
1560 if test "$found" = "1" ; then
1561    GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo"
1562    AC_DEFINE(USE_BLOWFISH, 1, [Defined if this module should be included])
1563
1564    case "${host}" in
1565       x86_64-*-*)
1566          # Build with the assembly implementation
1567          GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish-amd64.lo"
1568       ;;
1569       arm*-*-*)
1570          # Build with the assembly implementation
1571          GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish-arm.lo"
1572       ;;
1573    esac
1574 fi
1575
1576 LIST_MEMBER(cast5, $enabled_ciphers)
1577 if test "$found" = "1" ; then
1578    GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo"
1579    AC_DEFINE(USE_CAST5, 1, [Defined if this module should be included])
1580
1581    case "${host}" in
1582       x86_64-*-*)
1583          # Build with the assembly implementation
1584          GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5-amd64.lo"
1585       ;;
1586       arm*-*-*)
1587          # Build with the assembly implementation
1588          GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5-arm.lo"
1589       ;;
1590    esac
1591 fi
1592
1593 LIST_MEMBER(des, $enabled_ciphers)
1594 if test "$found" = "1" ; then
1595    GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo"
1596    AC_DEFINE(USE_DES, 1, [Defined if this module should be included])
1597 fi
1598
1599 LIST_MEMBER(aes, $enabled_ciphers)
1600 if test "$found" = "1" ; then
1601    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo"
1602    AC_DEFINE(USE_AES, 1, [Defined if this module should be included])
1603
1604    case "${host}" in
1605       x86_64-*-*)
1606          # Build with the assembly implementation
1607          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-amd64.lo"
1608       ;;
1609       arm*-*-*)
1610          # Build with the assembly implementation
1611          GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael-arm.lo"
1612       ;;
1613    esac
1614 fi
1615
1616 LIST_MEMBER(twofish, $enabled_ciphers)
1617 if test "$found" = "1" ; then
1618    GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo"
1619    AC_DEFINE(USE_TWOFISH, 1, [Defined if this module should be included])
1620
1621    case "${host}" in
1622       x86_64-*-*)
1623          # Build with the assembly implementation
1624          GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish-amd64.lo"
1625       ;;
1626       arm*-*-*)
1627          # Build with the assembly implementation
1628          GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish-arm.lo"
1629       ;;
1630    esac
1631 fi
1632
1633 LIST_MEMBER(serpent, $enabled_ciphers)
1634 if test "$found" = "1" ; then
1635    GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo"
1636    AC_DEFINE(USE_SERPENT, 1, [Defined if this module should be included])
1637
1638    case "${host}" in
1639       x86_64-*-*)
1640          # Build with the SSE2 implementation
1641          GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-sse2-amd64.lo"
1642       ;;
1643    esac
1644
1645    if test x"$avx2support" = xyes ; then
1646       # Build with the AVX2 implementation
1647       GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-avx2-amd64.lo"
1648    fi
1649
1650    if test x"$neonsupport" = xyes ; then
1651       # Build with the NEON implementation
1652       GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent-armv7-neon.lo"
1653    fi
1654 fi
1655
1656 LIST_MEMBER(rfc2268, $enabled_ciphers)
1657 if test "$found" = "1" ; then
1658    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo"
1659    AC_DEFINE(USE_RFC2268, 1, [Defined if this module should be included])
1660 fi
1661
1662 LIST_MEMBER(seed, $enabled_ciphers)
1663 if test "$found" = "1" ; then
1664    GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo"
1665    AC_DEFINE(USE_SEED, 1, [Defined if this module should be included])
1666 fi
1667
1668 LIST_MEMBER(camellia, $enabled_ciphers)
1669 if test "$found" = "1" ; then
1670    GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia.lo camellia-glue.lo"
1671    AC_DEFINE(USE_CAMELLIA, 1, [Defined if this module should be included])
1672
1673    case "${host}" in
1674       arm*-*-*)
1675          # Build with the assembly implementation
1676          GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-arm.lo"
1677       ;;
1678    esac
1679
1680    if test x"$avxsupport" = xyes ; then
1681       if test x"$aesnisupport" = xyes ; then
1682         # Build with the AES-NI/AVX implementation
1683         GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-aesni-avx-amd64.lo"
1684       fi
1685    fi
1686
1687    if test x"$avx2support" = xyes ; then
1688       if test x"$aesnisupport" = xyes ; then
1689         # Build with the AES-NI/AVX2 implementation
1690         GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia-aesni-avx2-amd64.lo"
1691       fi
1692    fi
1693 fi
1694
1695 LIST_MEMBER(idea, $enabled_ciphers)
1696 if test "$found" = "1" ; then
1697    GCRYPT_CIPHERS="$GCRYPT_CIPHERS idea.lo"
1698    AC_DEFINE(USE_IDEA, 1, [Defined if this module should be included])
1699 fi
1700
1701 LIST_MEMBER(salsa20, $enabled_ciphers)
1702 if test "$found" = "1" ; then
1703    GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20.lo"
1704    AC_DEFINE(USE_SALSA20, 1, [Defined if this module should be included])
1705
1706    case "${host}" in
1707       x86_64-*-*)
1708          # Build with the assembly implementation
1709          GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20-amd64.lo"
1710       ;;
1711    esac
1712
1713    if test x"$neonsupport" = xyes ; then
1714      # Build with the NEON implementation
1715      GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20-armv7-neon.lo"
1716    fi
1717 fi
1718
1719 LIST_MEMBER(gost28147, $enabled_ciphers)
1720 if test "$found" = "1" ; then
1721    GCRYPT_CIPHERS="$GCRYPT_CIPHERS gost28147.lo"
1722    AC_DEFINE(USE_GOST28147, 1, [Defined if this module should be included])
1723 fi
1724
1725 LIST_MEMBER(dsa, $enabled_pubkey_ciphers)
1726 if test "$found" = "1" ; then
1727    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo"
1728    AC_DEFINE(USE_DSA, 1, [Defined if this module should be included])
1729 fi
1730
1731 LIST_MEMBER(rsa, $enabled_pubkey_ciphers)
1732 if test "$found" = "1" ; then
1733    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo"
1734    AC_DEFINE(USE_RSA, 1, [Defined if this module should be included])
1735 fi
1736
1737 LIST_MEMBER(elgamal, $enabled_pubkey_ciphers)
1738 if test "$found" = "1" ; then
1739    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo"
1740    AC_DEFINE(USE_ELGAMAL, 1, [Defined if this module should be included])
1741 fi
1742
1743 LIST_MEMBER(ecc, $enabled_pubkey_ciphers)
1744 if test "$found" = "1" ; then
1745    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS \
1746                           ecc.lo ecc-curves.lo ecc-misc.lo \
1747                           ecc-ecdsa.lo ecc-eddsa.lo ecc-gost.lo"
1748    AC_DEFINE(USE_ECC, 1, [Defined if this module should be included])
1749 fi
1750
1751 LIST_MEMBER(crc, $enabled_digests)
1752 if test "$found" = "1" ; then
1753    GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo"
1754    AC_DEFINE(USE_CRC, 1, [Defined if this module should be included])
1755 fi
1756
1757 LIST_MEMBER(gostr3411-94, $enabled_digests)
1758 if test "$found" = "1" ; then
1759    # GOST R 34.11-94 internally uses GOST 28147-89
1760    LIST_MEMBER(gost28147, $enabled_ciphers)
1761    if test "$found" = "1" ; then
1762       GCRYPT_DIGESTS="$GCRYPT_DIGESTS gostr3411-94.lo"
1763       AC_DEFINE(USE_GOST_R_3411_94, 1, [Defined if this module should be included])
1764    fi
1765 fi
1766
1767 LIST_MEMBER(stribog, $enabled_digests)
1768 if test "$found" = "1" ; then
1769    GCRYPT_DIGESTS="$GCRYPT_DIGESTS stribog.lo"
1770    AC_DEFINE(USE_GOST_R_3411_12, 1, [Defined if this module should be included])
1771 fi
1772
1773 LIST_MEMBER(md4, $enabled_digests)
1774 if test "$found" = "1" ; then
1775    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo"
1776    AC_DEFINE(USE_MD4, 1, [Defined if this module should be included])
1777 fi
1778
1779 LIST_MEMBER(md5, $enabled_digests)
1780 if test "$found" = "1" ; then
1781    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo"
1782    AC_DEFINE(USE_MD5, 1, [Defined if this module should be included])
1783 fi
1784
1785 LIST_MEMBER(sha256, $enabled_digests)
1786 if test "$found" = "1" ; then
1787    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo"
1788    AC_DEFINE(USE_SHA256, 1, [Defined if this module should be included])
1789
1790    case "${host}" in
1791       x86_64-*-*)
1792          # Build with the assembly implementation
1793          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-ssse3-amd64.lo"
1794          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-avx-amd64.lo"
1795          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256-avx2-bmi2-amd64.lo"
1796       ;;
1797    esac
1798 fi
1799
1800 LIST_MEMBER(sha512, $enabled_digests)
1801 if test "$found" = "1" ; then
1802    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo"
1803    AC_DEFINE(USE_SHA512, 1, [Defined if this module should be included])
1804
1805    case "${host}" in
1806       x86_64-*-*)
1807          # Build with the assembly implementation
1808          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-ssse3-amd64.lo"
1809          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx-amd64.lo"
1810          GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx2-bmi2-amd64.lo"
1811       ;;
1812    esac
1813
1814    if test x"$neonsupport" = xyes ; then
1815      # Build with the NEON implementation
1816      GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-armv7-neon.lo"
1817    fi
1818 fi
1819
1820 LIST_MEMBER(tiger, $enabled_digests)
1821 if test "$found" = "1" ; then
1822    GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo"
1823    AC_DEFINE(USE_TIGER, 1, [Defined if this module should be included])
1824 fi
1825
1826 LIST_MEMBER(whirlpool, $enabled_digests)
1827 if test "$found" = "1" ; then
1828    GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo"
1829    AC_DEFINE(USE_WHIRLPOOL, 1, [Defined if this module should be included])
1830 fi
1831
1832 # rmd160 and sha1 should be included always.
1833 GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo sha1.lo"
1834 AC_DEFINE(USE_RMD160, 1, [Defined if this module should be included])
1835 AC_DEFINE(USE_SHA1, 1,   [Defined if this module should be included])
1836
1837 case "${host}" in
1838   x86_64-*-*)
1839     # Build with the assembly implementation
1840     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-ssse3-amd64.lo"
1841     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-avx-amd64.lo"
1842     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-avx-bmi2-amd64.lo"
1843   ;;
1844   arm*-*-*)
1845     # Build with the assembly implementation
1846     GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1-armv7-neon.lo"
1847   ;;
1848 esac
1849
1850 LIST_MEMBER(scrypt, $enabled_kdfs)
1851 if test "$found" = "1" ; then
1852    GCRYPT_KDFS="$GCRYPT_KDFS scrypt.lo"
1853    AC_DEFINE(USE_SCRYPT, 1, [Defined if this module should be included])
1854 fi
1855
1856 LIST_MEMBER(linux, $random_modules)
1857 if test "$found" = "1" ; then
1858    GCRYPT_RANDOM="$GCRYPT_RANDOM rndlinux.lo"
1859    AC_DEFINE(USE_RNDLINUX, 1, [Defined if the /dev/random RNG should be used.])
1860 fi
1861
1862 LIST_MEMBER(unix, $random_modules)
1863 if test "$found" = "1" ; then
1864    GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo"
1865    AC_DEFINE(USE_RNDUNIX, 1, [Defined if the default Unix RNG should be used.])
1866    print_egd_notice=yes
1867 fi
1868
1869 LIST_MEMBER(egd, $random_modules)
1870 if test "$found" = "1" ; then
1871    GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo"
1872    AC_DEFINE(USE_RNDEGD, 1, [Defined if the EGD based RNG should be used.])
1873 fi
1874
1875 LIST_MEMBER(w32, $random_modules)
1876 if test "$found" = "1" ; then
1877    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo"
1878    AC_DEFINE(USE_RNDW32, 1,
1879              [Defined if the Windows specific RNG should be used.])
1880 fi
1881
1882 LIST_MEMBER(w32ce, $random_modules)
1883 if test "$found" = "1" ; then
1884    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32ce.lo"
1885    AC_DEFINE(USE_RNDW32CE, 1,
1886              [Defined if the WindowsCE specific RNG should be used.])
1887 fi
1888
1889 AC_SUBST([GCRYPT_CIPHERS])
1890 AC_SUBST([GCRYPT_PUBKEY_CIPHERS])
1891 AC_SUBST([GCRYPT_DIGESTS])
1892 AC_SUBST([GCRYPT_KDFS])
1893 AC_SUBST([GCRYPT_RANDOM])
1894
1895 AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers)
1896 AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers)
1897 AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests)
1898
1899 # For printing the configuration we need a colon separated list of
1900 # algorithm names.
1901 tmp=`echo "$enabled_ciphers" | tr ' ' : `
1902 AC_DEFINE_UNQUOTED(LIBGCRYPT_CIPHERS, "$tmp",
1903                    [List of available cipher algorithms])
1904 tmp=`echo "$enabled_pubkey_ciphers" | tr ' ' : `
1905 AC_DEFINE_UNQUOTED(LIBGCRYPT_PUBKEY_CIPHERS, "$tmp",
1906                    [List of available public key cipher algorithms])
1907 tmp=`echo "$enabled_digests" | tr ' ' : `
1908 AC_DEFINE_UNQUOTED(LIBGCRYPT_DIGESTS, "$tmp",
1909                    [List of available digest algorithms])
1910 tmp=`echo "$enabled_kdfs" | tr ' ' : `
1911 AC_DEFINE_UNQUOTED(LIBGCRYPT_KDFS, "$tmp",
1912                    [List of available KDF algorithms])
1913
1914
1915 #
1916 # Define conditional sources depending on the used hardware platform.
1917 # Note that all possible modules must also be listed in
1918 # src/Makefile.am (EXTRA_libgcrypt_la_SOURCES).
1919 #
1920 GCRYPT_HWF_MODULES=
1921 case "$mpi_cpu_arch" in
1922      x86)
1923         AC_DEFINE(HAVE_CPU_ARCH_X86, 1,   [Defined for the x86 platforms])
1924         GCRYPT_HWF_MODULES="hwf-x86.lo"
1925         ;;
1926      alpha)
1927         AC_DEFINE(HAVE_CPU_ARCH_ALPHA, 1, [Defined for Alpha platforms])
1928         ;;
1929      sparc)
1930         AC_DEFINE(HAVE_CPU_ARCH_SPARC, 1, [Defined for SPARC platforms])
1931         ;;
1932      mips)
1933         AC_DEFINE(HAVE_CPU_ARCH_MIPS, 1,  [Defined for MIPS platforms])
1934         ;;
1935      m68k)
1936         AC_DEFINE(HAVE_CPU_ARCH_M68K, 1,  [Defined for M68k platforms])
1937         ;;
1938      ppc)
1939         AC_DEFINE(HAVE_CPU_ARCH_PPC, 1,   [Defined for PPC platforms])
1940         ;;
1941      arm)
1942         AC_DEFINE(HAVE_CPU_ARCH_ARM, 1,   [Defined for ARM platforms])
1943         GCRYPT_HWF_MODULES="hwf-arm.lo"
1944         ;;
1945 esac
1946 AC_SUBST([GCRYPT_HWF_MODULES])
1947
1948
1949 #
1950 # Provide information about the build.
1951 #
1952 BUILD_REVISION="mym4_revision"
1953 AC_SUBST(BUILD_REVISION)
1954 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
1955                    [GIT commit id revision used to build this package])
1956
1957 changequote(,)dnl
1958 BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
1959 changequote([,])dnl
1960 BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
1961 AC_SUBST(BUILD_FILEVERSION)
1962
1963 BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
1964 AC_SUBST(BUILD_TIMESTAMP)
1965 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
1966                    [The time this package was configured for a build])
1967
1968
1969 # And create the files.
1970 AC_CONFIG_FILES([
1971 Makefile
1972 m4/Makefile
1973 compat/Makefile
1974 mpi/Makefile
1975 cipher/Makefile
1976 random/Makefile
1977 doc/Makefile
1978 src/Makefile
1979 src/gcrypt.h
1980 src/libgcrypt-config
1981 src/versioninfo.rc
1982 tests/Makefile
1983 ])
1984 AC_CONFIG_FILES([tests/hashtest-256g], [chmod +x tests/hashtest-256g])
1985 AC_OUTPUT
1986
1987
1988 detection_module="${GCRYPT_HWF_MODULES%.lo}"
1989 test -n "$detection_module" || detection_module="none"
1990
1991 # Give some feedback
1992 GCRY_MSG_SHOW([],[])
1993 GCRY_MSG_SHOW([Libgcrypt],[v${VERSION} has been configured as follows:])
1994 GCRY_MSG_SHOW([],[])
1995 GCRY_MSG_SHOW([Platform:                 ],[$PRINTABLE_OS_NAME ($host)])
1996 GCRY_MSG_SHOW([Hardware detection module:],[$detection_module])
1997 GCRY_MSG_WRAP([Enabled cipher algorithms:],[$enabled_ciphers])
1998 GCRY_MSG_WRAP([Enabled digest algorithms:],[$enabled_digests])
1999 GCRY_MSG_WRAP([Enabled kdf algorithms:   ],[$enabled_kdfs])
2000 GCRY_MSG_WRAP([Enabled pubkey algorithms:],[$enabled_pubkey_ciphers])
2001 GCRY_MSG_SHOW([Random number generator:  ],[$random])
2002 GCRY_MSG_SHOW([Using linux capabilities: ],[$use_capabilities])
2003 GCRY_MSG_SHOW([Try using Padlock crypto: ],[$padlocksupport])
2004 GCRY_MSG_SHOW([Try using AES-NI crypto:  ],[$aesnisupport])
2005 GCRY_MSG_SHOW([Try using Intel PCLMUL:   ],[$pclmulsupport])
2006 GCRY_MSG_SHOW([Try using DRNG (RDRAND):  ],[$drngsupport])
2007 GCRY_MSG_SHOW([Try using Intel AVX:      ],[$avxsupport])
2008 GCRY_MSG_SHOW([Try using Intel AVX2:     ],[$avx2support])
2009 GCRY_MSG_SHOW([Try using ARM NEON:       ],[$neonsupport])
2010 GCRY_MSG_SHOW([],[])
2011
2012 if test "$print_egd_notice" = "yes"; then
2013 cat <<G10EOF
2014
2015    The performance of the Unix random gatherer module (rndunix) is not
2016    very good and it does not keep the entropy pool over multiple
2017    invocations of Libgcrypt base applications.  The suggested way to
2018    overcome this problem is to use the
2019
2020                  Entropy Gathering Daemon (EGD)
2021
2022    which provides a entropy source for the whole system.  It is written
2023    in Perl and available at the GnuPG FTP servers.  To enable EGD you
2024    should rerun configure with the option "--enable-static-rnd=egd".
2025    For more information consult the GnuPG webpages:
2026
2027              http://www.gnupg.org/download.html#egd
2028
2029 G10EOF
2030 fi
2031
2032 if test "$gcry_cv_gcc_attribute_aligned" != "yes" ; then
2033 cat <<G10EOF
2034
2035    Please not that your compiler does not support the GCC style
2036    aligned attribute. Using this software may evoke bus errors.
2037
2038 G10EOF
2039 fi
2040
2041 if test -n "$gpl"; then
2042   echo "Please note that you are building a version of Libgcrypt with"
2043   echo "  $gpl"
2044   echo "included.  These parts are licensed under the GPL and thus the"
2045   echo "use of this library has to comply with the conditions of the GPL."
2046 fi