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