3d804dbf5e97e92ce16ff47cce51002af18ad2d0
[platform/upstream/nettle.git] / configure.ac
1 dnl -*- mode: shell-script; sh-indentation: 2; -*-
2
3 dnl Process this file with autoconf to produce a configure script.
4
5 AC_INIT([nettle], [3.2], [nettle-bugs@lists.lysator.liu.se])
6 AC_PREREQ(2.61)
7 AC_CONFIG_SRCDIR([arcfour.c])
8 # Needed to stop autoconf from looking for files in parent directories.
9 AC_CONFIG_AUX_DIR([.])
10
11 AC_CONFIG_HEADER([config.h])
12
13 LIBNETTLE_MAJOR=6
14 LIBNETTLE_MINOR=2
15
16 LIBHOGWEED_MAJOR=4
17 LIBHOGWEED_MINOR=2
18
19 dnl Note double square brackets, for extra m4 quoting.
20 MAJOR_VERSION=`echo $PACKAGE_VERSION | sed 's/^\([[^.]]*\)\..*/\1/'`
21 MINOR_VERSION=`echo $PACKAGE_VERSION | sed 's/^[[^.]]*\.\([[0-9]]*\).*/\1/'`
22 AC_SUBST([MAJOR_VERSION])
23 AC_SUBST([MINOR_VERSION])
24
25 AC_CANONICAL_HOST
26
27 # Command line options
28 AC_ARG_WITH(include-path,
29   AC_HELP_STRING([--with-include-path], [A colon-separated list of directories to search for include files]),,
30   [with_include_path=''])
31
32 if test x$with_include_path != x ; then
33   CPPFLAGS="$CPPFLAGS -I`echo $with_include_path | sed 's/:/ -I/g'`"
34 fi
35
36 AC_ARG_WITH(lib-path,
37   AC_HELP_STRING([--with-lib-path], [A colon-separated list of directories to search for libraries]),,
38   [with_lib_path=''])
39
40 if test x$with_lib_path != x ; then
41   LDFLAGS="$LDFLAGS -L`echo $with_lib_path | sed 's/:/ -L/g'`"
42 fi
43
44 AC_ARG_ENABLE(public-key,
45   AC_HELP_STRING([--disable-public-key], [Disable public key algorithms]),,
46   [enable_public_key=yes])
47
48 AC_ARG_ENABLE(assembler,
49   AC_HELP_STRING([--disable-assembler],[Disable assembler code]),,
50   [enable_assembler=yes])
51
52 AC_ARG_ENABLE(static,
53   AC_HELP_STRING([--disable-static], [Do not build any static library]),,
54   [enable_static=yes])
55
56 AC_ARG_ENABLE(shared,
57   AC_HELP_STRING([--disable-shared], [Do not build any shared library]),,
58   [enable_shared=yes])
59
60 AC_ARG_ENABLE(pic,
61   AC_HELP_STRING([--disable-pic],
62   [Do not try to compile library files as position independent code]),,
63   [enable_pic=yes])
64
65 AC_ARG_ENABLE(openssl,
66   AC_HELP_STRING([--disable-openssl], [Do not include openssl glue in the benchmark program]),,
67   [enable_openssl=yes])
68
69 AC_ARG_ENABLE(gcov,
70   AC_HELP_STRING([--enable-gcov], [Instrument for gcov (requires a modern gcc)]),,
71   [enable_gcov=no])
72
73 AC_ARG_ENABLE(documentation,
74   AC_HELP_STRING([--disable-documentation], [Omit building and installing the documentation. (default=auto)]),,
75   [enable_documentation=auto])
76
77 AC_ARG_ENABLE(fat, AC_HELP_STRING([--enable-fat], [Enable fat library build (default=no)]),,
78   [enable_fat=no])
79
80 AC_ARG_ENABLE(arm-neon,
81   AC_HELP_STRING([--enable-arm-neon], [Enable ARM Neon assembly. (default=auto)]),,
82   [enable_arm_neon=auto])
83
84 AC_ARG_ENABLE(x86-aesni,
85   AC_HELP_STRING([--enable-x86-aesni], [Enable x86_64 aes instructions. (default=no)]),,
86   [enable_x86_aesni=no])
87
88 AC_ARG_ENABLE(mini-gmp,
89   AC_HELP_STRING([--enable-mini-gmp], [Enable mini-gmp, used instead of libgmp.]),,
90   [enable_mini_gmp=no])
91
92 if test "x$enable_mini_gmp" = xyes ; then
93   NETTLE_USE_MINI_GMP=1
94   HOGWEED_EXTRA_SYMBOLS="mpz_*;gmp_*;mpn_*;"
95 else
96   NETTLE_USE_MINI_GMP=0
97   HOGWEED_EXTRA_SYMBOLS=""
98 fi
99 AC_SUBST([NETTLE_USE_MINI_GMP])
100 AC_SUBST([HOGWEED_EXTRA_SYMBOLS])
101
102 LSH_RPATH_INIT([`echo $with_lib_path | sed 's/:/ /g'` \
103     `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \
104     /usr/local/lib /sw/local/lib /sw/lib \
105     /usr/gnu/lib /opt/gnu/lib /sw/gnu/lib /usr/freeware/lib /usr/pkg/lib])
106
107 # Checks for programs.
108 AC_PROG_CC
109
110 NETTLE_CHECK_IFUNC
111
112 # When $CC foo.c -o foo creates both foo and foo.exe, autoconf picks
113 # up the foo.exe and sets exeext to .exe. That is correct for cygwin,
114 # which has some kind of magic link from foo to foo.exe, but not for
115 # rntcl. A better check for the cygwin case would check if the
116 # contents of foo and foo.exe are equal; in the rntcl case, foo is a
117 # sh script, and foo.exe is a windows executable.
118
119 if test "x$CC" = xrntcl ; then
120     AC_MSG_NOTICE([Compiling with rntcl; clearing EXEEXT and disabling assembler])
121     ac_exeext=''
122     ac_cv_exeext=''
123     EXEEXT=''
124     enable_assembler=no
125 fi
126
127 # Used by the testsuite only
128 AC_PROG_CXX
129
130 AC_LANG_PUSH(C++)
131 AC_TRY_COMPILE([],[return 0;],[IF_CXX=''], [IF_CXX='#'])
132 AC_SUBST([IF_CXX])
133 AC_LANG_POP
134
135 LD_VERSION_SCRIPT
136
137 AC_PROG_MAKE_SET
138 AC_PROG_RANLIB
139 AC_CHECK_TOOL(NM, nm, strings)
140 # Used only for the GNU-stack configure test.
141 AC_CHECK_TOOL(OBJDUMP, objdump, false)
142 AC_CHECK_TOOL(AR, ar, false)
143
144 if test "x$ac_cv_prog_cc_stdc" = xno ; then
145   AC_ERROR([the C compiler doesn't handle ANSI-C]) #'
146 fi
147
148 AC_PROG_INSTALL
149
150 # According to the autoconf manual, needs install-sh from
151 # autoconf-2.60 or automake-1.10 to avoid races.
152 AC_PROG_MKDIR_P
153
154 AC_PROG_LN_S
155
156 # Compiler tests for the build system
157 GMP_PROG_CC_FOR_BUILD
158 GMP_PROG_EXEEXT_FOR_BUILD
159
160 LSH_DEPENDENCY_TRACKING
161
162 if test x$enable_dependency_tracking = xyes ; then
163   # Since the makefiles use include to get the dependency files, we must
164   # make sure that the files exist. We generate some more files than are
165   # actually needed.
166
167   AC_CONFIG_COMMANDS([dummy-dep-files],
168   [(cd "$srcdir" && find . '(' -name '*.c' -o -name '*.cxx' ')' -print) \
169  | sed 's/\.cx*$//' | (while read f; do \
170       test -f "$f.o.d" || echo > "$f.o.d"; \
171    done)
172 ])
173 fi
174
175 if test "x$enable_gcov" = "xyes"; then
176   CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs"
177 fi
178
179 # Checks for typedefs, structures, and compiler characteristics.
180 AC_C_CONST
181 AC_C_INLINE
182 AC_TYPE_UID_T
183 AC_TYPE_SIZE_T
184 AC_HEADER_TIME
185 AC_CHECK_SIZEOF(long)
186 AC_CHECK_SIZEOF(size_t)
187
188 AC_CHECK_HEADERS([openssl/blowfish.h openssl/des.h openssl/cast.h openssl/aes.h openssl/ecdsa.h],,
189 [enable_openssl=no
190  break])
191
192 # For use by the testsuite
193 AC_CHECK_HEADERS([valgrind/memcheck.h])
194 AC_CHECK_HEADERS([dlfcn.h])
195 AC_CHECK_LIB([dl], [dlopen],
196              [AC_DEFINE([HAVE_LIBDL], 1,
197                         [Define to 1 if you have dlopen (with -ldl).])])
198
199 LSH_FUNC_ALLOCA
200 LSH_FUNC_STRERROR
201 # getenv_secure is used for fat overrides,
202 # getline is used in the testsuite
203 AC_CHECK_FUNCS(secure_getenv getline)
204 AC_C_BIGENDIAN
205
206 LSH_GCC_ATTRIBUTES
207
208 # According to Simon Josefsson, looking for uint32_t and friends in
209 # sys/types.h is needed on some systems, in particular cygwin.
210 AX_CREATE_STDINT_H([nettle-stdint.h], [sys/types.h])
211
212 # Check for file locking. We (AC_PROG_CC?) have already checked for
213 # sys/types.h and unistd.h.
214 AC_CACHE_CHECK([for fcntl file locking],
215                 nettle_cv_fcntl_locking,
216 [AC_TRY_COMPILE([
217 #if HAVE_SYS_TYPES_H
218 # include <sys/types.h>
219 #endif
220 #if HAVE_UNISTD_H
221 # include <unistd.h>
222 #endif
223 #include <fcntl.h>
224 ],[
225 int op = F_SETLKW;
226 struct flock fl;
227 ],
228 nettle_cv_fcntl_locking=yes,
229 nettle_cv_fcntl_locking=no)])
230
231 AH_TEMPLATE([HAVE_FCNTL_LOCKING], [Define if fcntl file locking is available])
232 if test "x$nettle_cv_fcntl_locking" = "xyes" ; then
233   AC_DEFINE(HAVE_FCNTL_LOCKING)
234 fi
235
236 # Checks for libraries
237 if test "x$enable_public_key" = "xyes" ; then
238   if test "x$enable_mini_gmp" = "xno" ; then
239     AC_CHECK_LIB(gmp, __gmpz_getlimbn,,
240         [AC_MSG_WARN(
241     [GNU MP not found, or not 3.1 or up, see http://gmplib.org/.
242     Support for public key algorithms will be unavailable.])]
243         enable_public_key=no)
244
245     # Add -R flags needed to run programs linked with gmp
246     LSH_RPATH_FIX
247   fi
248 fi
249
250 nettle_cv_gmp_numb_bits=0
251 if test "x$enable_public_key" = "xyes" ; then
252   # Check for gmp limb size
253   if test "x$enable_mini_gmp" = "xyes" ; then
254     AC_MSG_CHECKING([for mini-gmp limb size])
255     # With mini-gmp, mp_limb_t is always unsigned long.
256     AC_COMPUTE_INT(nettle_cv_gmp_numb_bits, [(sizeof(unsigned long) * CHAR_BIT)],
257         [#include <limits.h>],
258         [AC_MSG_FAILURE([cannot find value of GMP_NUMB_BITS])])
259
260     AC_MSG_RESULT([$nettle_cv_gmp_numb_bits bits])
261   else
262     AC_MSG_CHECKING([for GMP limb size])
263     AC_COMPUTE_INT(nettle_cv_gmp_numb_bits, [GMP_NUMB_BITS],
264         [#include <gmp.h>],
265         [AC_MSG_FAILURE([cannot find value of GMP_NUMB_BITS])])
266
267     AC_MSG_RESULT([$nettle_cv_gmp_numb_bits bits])
268   fi
269 fi
270
271 GMP_NUMB_BITS="$nettle_cv_gmp_numb_bits"
272 AC_SUBST([GMP_NUMB_BITS])
273
274 # Figure out ABI. Currently, configurable only by setting CFLAGS.
275 ABI=standard
276
277 case "$host_cpu" in
278   [x86_64 | amd64])
279     AC_TRY_COMPILE([
280 #if defined(__x86_64__) || defined(__arch64__)
281 #error 64-bit x86
282 #endif
283     ], [], [
284       ABI=32
285     ], [
286       ABI=64
287     ])
288     ;;
289   *sparc*)
290     AC_TRY_COMPILE([
291 #if defined(__sparcv9) || defined(__arch64__)
292 #error 64-bit sparc
293 #endif
294     ], [], [
295       ABI=32
296     ], [
297       ABI=64
298     ])
299     ;;
300   *mips*)
301     AC_TRY_COMPILE([
302 #if defined(__sgi) && defined(__LP64__)
303 #error 64-bit mips
304 #endif
305     ], [], [
306       ABI=32
307     ], [
308       ABI=64
309     ])
310     ;;
311 esac
312
313 if test "x$ABI" != xstandard ; then
314   AC_MSG_NOTICE([Compiler uses $ABI-bit ABI. To change, set CC.])
315   if test "$libdir" = '${exec_prefix}/lib' ; then
316     # Try setting a better default
317     case "$host_cpu:$host_os:$ABI" in
318       *:solaris*:32|*:sunos*:32)
319         libdir='${exec_prefix}/lib'
320         ;;
321       *:solaris*:64|*:sunos*:64)
322         libdir='${exec_prefix}/lib/64'
323         ;;
324       # Linux conventions are a mess... According to the Linux File
325       # Hierarchy Standard, all architectures except IA64 puts 32-bit
326       # libraries in lib, and 64-bit in lib64. Some distributions,
327       # e.g., Fedora and Gentoo, adhere to this standard, while at
328       # least Debian has decided to put 64-bit libraries in lib and
329       # 32-bit libraries in lib32.
330       
331       # We try to figure out the convention, except if we're cross
332       # compiling. We use lib${ABI} if /usr/lib${ABI} exists and
333       # appears to not be a symlink to a different name.
334       *:linux*:32|*:linux*:64)
335         if test "$cross_compiling" = yes ; then
336           AC_MSG_WARN([Cross compiling for linux. Can't guess if libraries go in lib${ABI} or lib.]); dnl '
337         else
338           # The dash builtin pwd tries to be "helpful" and remember
339           # symlink names. Use -P option, and hope it's portable enough.
340           test -d /usr/lib${ABI} \
341             && (cd /usr/lib${ABI} && pwd -P | grep >/dev/null "/lib${ABI}"'$') \
342             && libdir='${exec_prefix}/'"lib${ABI}"
343         fi
344         ;;
345       # On freebsd, it seems 32-bit libraries are in lib32,
346       # and 64-bit in lib. Don't know about "kfreebsd", does
347       # it follow the Linux fhs conventions?
348       *:freebsd*:32)
349         libdir='${exec_prefix}/lib32'
350         ;;
351       *:freebsd*:64)
352         libdir='${exec_prefix}/lib'
353         ;;
354       *:irix*:32)
355         libdir='${exec_prefix}/lib32'
356         ;;
357       *:irix*:64)
358         libdir='${exec_prefix}/lib64'
359         ;;
360       *)
361         AC_MSG_WARN([Don't know where to install $ABI-bit libraries on this system.]); dnl '
362
363     esac
364     AC_MSG_NOTICE([Libraries to be installed in $libdir.])
365   fi
366 fi
367
368 OPT_NETTLE_SOURCES=""
369
370 # Select assembler code
371 asm_path=
372 if test "x$enable_assembler" = xyes ; then
373   case "$host_cpu" in
374     [i?86* | k[5-8]* | pentium* | athlon])
375       asm_path=x86
376       ;;
377     [x86_64 | amd64])
378       if test "$ABI" = 64 ; then
379         asm_path=x86_64
380         if test "x$enable_fat" = xyes ; then
381           asm_path="x86_64/fat $asm_path"
382           OPT_NETTLE_SOURCES="fat-x86_64.c $OPT_NETTLE_SOURCES"
383         elif test "x$enable_x86_aesni" = xyes ; then
384           asm_path="x86_64/aesni $asm_path"
385         fi
386       else
387         asm_path=x86
388       fi
389       ;;
390     *sparc*)
391       if test "$ABI" = 64 ; then
392         asm_path=sparc64
393       else
394         asm_path=sparc32
395       fi
396       ;;
397     arm*)
398       asm_path=arm
399       if test "x$enable_fat" = xyes ; then
400         asm_path="arm/fat $asm_path"
401         OPT_NETTLE_SOURCES="fat-arm.c $OPT_NETTLE_SOURCES"
402       else
403         case "$host_cpu" in
404           armv6* | armv7*)
405             NETTLE_CHECK_ARM_NEON
406
407             asm_path="arm/v6 arm"
408       
409             if test "x$enable_arm_neon" = xyes ; then
410               asm_path="arm/neon $asm_path"
411             fi
412             ;;
413         esac
414       fi
415       ;;
416     *)
417       enable_assembler=no
418       ;;
419   esac
420 fi
421
422 # Files which replace a C source file (or otherwise don't correspond
423 # to a new object file).
424 asm_replace_list="aes-encrypt-internal.asm aes-decrypt-internal.asm \
425                 arcfour-crypt.asm camellia-crypt-internal.asm \
426                 md5-compress.asm memxor.asm memxor3.asm \
427                 poly1305-internal.asm \
428                 chacha-core-internal.asm \
429                 salsa20-crypt.asm salsa20-core-internal.asm \
430                 serpent-encrypt.asm serpent-decrypt.asm \
431                 sha1-compress.asm sha256-compress.asm sha512-compress.asm \
432                 sha3-permute.asm umac-nh.asm umac-nh-n.asm machine.m4"
433
434 # Assembler files which generate additional object files if they are used.
435 asm_nettle_optional_list="gcm-hash8.asm cpuid.asm \
436   aes-encrypt-internal-2.asm aes-decrypt-internal-2.asm memxor-2.asm \
437   salsa20-core-internal-2.asm sha1-compress-2.asm sha256-compress-2.asm \
438   sha3-permute-2.asm sha512-compress-2.asm \
439   umac-nh-n-2.asm umac-nh-2.asm"
440
441 asm_hogweed_optional_list=""
442 if test "x$enable_public_key" = "xyes" ; then
443   asm_hogweed_optional_list="ecc-192-modp.asm ecc-224-modp.asm \
444     ecc-25519-modp.asm ecc-256-redc.asm ecc-384-modp.asm ecc-521-modp.asm"
445 fi
446
447 OPT_NETTLE_OBJS=""
448 OPT_HOGWEED_OBJS=""
449
450 asm_file_list=""
451
452 if test "x$enable_assembler" = xyes ; then
453   if test -n "$asm_path"; then
454     AC_MSG_NOTICE([Looking for assembler files in $asm_path.])
455     for tmp_f in $asm_replace_list ; do
456       for asm_dir in $asm_path ; do
457         if test -f "$srcdir/$asm_dir/$tmp_f"; then
458           asm_file_list="$asm_file_list $tmp_f"
459           AC_CONFIG_LINKS($tmp_f:$asm_dir/$tmp_f)
460           break
461         fi
462       done
463     done
464     dnl Workaround for AC_CONFIG_LINKS, which complains if we use the
465     dnl same destination argument $tmp_f multiple times.
466     for tmp_n in $asm_nettle_optional_list ; do
467       dnl Note extra pair of [] in sed expression
468       tmp_b=`echo "$tmp_n" | sed 's/\.[[^.]]*$//'`
469       for asm_dir in $asm_path ; do
470         if test -f "$srcdir/$asm_dir/$tmp_n"; then
471           asm_file_list="$asm_file_list $tmp_n"
472           AC_CONFIG_LINKS($tmp_n:$asm_dir/$tmp_n)
473           while read tmp_func ; do
474             AC_DEFINE_UNQUOTED(HAVE_NATIVE_$tmp_func)
475             eval HAVE_NATIVE_$tmp_func=yes
476           done <<EOF
477 [`sed -n 's/^.*[^       ]*PROLOGUE(_*\(nettle_\)*\([^)]*\)).*$/\2/p' < "$srcdir/$asm_dir/$tmp_n"`]
478 EOF
479           OPT_NETTLE_OBJS="$OPT_NETTLE_OBJS $tmp_b"'.$(OBJEXT)'
480           break
481         fi
482       done
483     done        
484     for tmp_h in $asm_hogweed_optional_list ; do
485       dnl Note extra pair of [] in sed expression
486       tmp_b=`echo "$tmp_h" | sed 's/\.[[^.]]*$//'`
487       for asm_dir in $asm_path ; do
488         if test -f "$srcdir/$asm_dir/$tmp_h"; then
489           dnl Note double square brackets, for extra m4 quoting.
490           tmp_bits=`grep GMP_NUMB_BITS "$srcdir/$asm_dir/$tmp_h" \
491             | sed 's/^.*GMP_NUMB_BITS(\([[0-9]]*\)).*$/\1/'`
492           if test "$tmp_bits" && test "$tmp_bits" != "${GMP_NUMB_BITS}" ; then
493              AC_MSG_WARN([skipping $tmp_h, because GMP_NUMB_BITS != $tmp_bits])
494              continue
495           fi
496           asm_file_list="$asm_file_list $tmp_h"
497           AC_CONFIG_LINKS($tmp_h:$asm_dir/$tmp_h)
498           while read tmp_func ; do
499             AC_DEFINE_UNQUOTED(HAVE_NATIVE_$tmp_func)
500             eval HAVE_NATIVE_$tmp_func=yes
501           done <<EOF
502 [`sed -n 's/[^  ]*PROLOGUE(_*\(nettle_\)*\([^)]*\)).*$/\2/p' < "$srcdir/$asm_dir/$tmp_h"`]
503 EOF
504           OPT_HOGWEED_OBJS="$OPT_HOGWEED_OBJS $tmp_b"'.$(OBJEXT)'
505           break
506         fi
507       done
508     done        
509     if test -z "$asm_file_list"; then
510       enable_assembler=no
511       AC_MSG_WARN([No assembler files found.])
512     fi
513   fi
514   case "$host_os" in
515     darwin*)
516       ASM_RODATA='.section __TEXT,__const'
517       ;;
518     *)
519       ASM_RODATA='.section .rodata'
520       ;;
521   esac
522 fi
523
524 AC_SUBST([OPT_NETTLE_OBJS])
525 AC_SUBST([OPT_HOGWEED_OBJS])
526 AC_SUBST([OPT_NETTLE_SOURCES])
527 AC_SUBST([ASM_RODATA])
528 if test "x$enable_assembler" = xyes ; then
529   IF_ASM=''
530 else
531   IF_ASM='#'
532 fi
533 AC_SUBST([IF_ASM])
534
535 AH_VERBATIM([HAVE_NATIVE],
536 [/* Define to 1 each of the following for which a native (ie. CPU specific)
537     implementation of the corresponding routine exists.  */
538 #undef HAVE_NATIVE_ecc_192_modp
539 #undef HAVE_NATIVE_ecc_192_redc
540 #undef HAVE_NATIVE_ecc_224_modp
541 #undef HAVE_NATIVE_ecc_224_redc
542 #undef HAVE_NATIVE_ecc_25519_modp
543 #undef HAVE_NATIVE_ecc_256_modp
544 #undef HAVE_NATIVE_ecc_256_redc
545 #undef HAVE_NATIVE_ecc_384_modp
546 #undef HAVE_NATIVE_ecc_384_redc
547 #undef HAVE_NATIVE_ecc_521_modp
548 #undef HAVE_NATIVE_ecc_521_redc
549 #undef HAVE_NATIVE_gcm_hash8
550 #undef HAVE_NATIVE_salsa20_core
551 #undef HAVE_NATIVE_sha1_compress
552 #undef HAVE_NATIVE_sha256_compress
553 #undef HAVE_NATIVE_sha512_compress
554 #undef HAVE_NATIVE_sha3_permute
555 #undef HAVE_NATIVE_umac_nh
556 #undef HAVE_NATIVE_umac_nh_n])
557
558 if test "x$enable_pic" = xyes; then
559     LSH_CCPIC
560 else
561     CCPIC=''
562 fi
563 AC_SUBST(CCPIC)
564
565 IF_DLL='#'
566 LIBNETTLE_FILE_SRC='$(LIBNETTLE_FORLINK)'
567 LIBHOGWEED_FILE_SRC='$(LIBHOGWEED_FORLINK)'
568 EMULATOR=''
569 W64_ABI=no
570
571 case "$host_os" in
572   mingw32*|cygwin*)
573     # The actual DLLs, e.g. libnettle-$major-$minor.dll, are normally
574     # installed into the bin dir (or more exactly $libdir/../bin, for
575     # automake), while libnettle.dll.a, which is a stub file for
576     # linking to the DLL, is installed into the lib dir.
577     case "$host_os" in
578       mingw32*)
579         LIBNETTLE_FORLINK='libnettle-$(LIBNETTLE_MAJOR)-$(LIBNETTLE_MINOR).dll'
580         LIBHOGWEED_FORLINK='libhogweed-$(LIBHOGWEED_MAJOR)-$(LIBHOGWEED_MINOR).dll'
581         ;;
582       cygwin*)
583         LIBNETTLE_FORLINK='cygnettle-$(LIBNETTLE_MAJOR)-$(LIBNETTLE_MINOR).dll'
584         LIBHOGWEED_FORLINK='cyghogweed-$(LIBHOGWEED_MAJOR)-$(LIBHOGWEED_MINOR).dll'
585         ;;
586     esac
587     if test "x$cross_compiling" = xyes ; then
588         case "$ABI" in
589             64)
590                 EMULATOR=wine64
591                 ;;
592             *)
593                 EMULATOR=wine
594                 ;;
595         esac
596     fi
597     if test "x$ABI" = x64 ; then
598         W64_ABI=yes
599     fi
600     LIBNETTLE_SONAME=''
601     LIBNETTLE_FILE='libnettle.dll.a'
602     LIBNETTLE_FILE_SRC='$(LIBNETTLE_FILE)'
603     LIBNETTLE_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,--out-implib=$(LIBNETTLE_FILE) -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive'
604     LIBNETTLE_LIBS='-Wl,--no-whole-archive $(LIBS)'
605
606     LIBHOGWEED_SONAME=''
607     LIBHOGWEED_FILE='libhogweed.dll.a'
608     LIBHOGWEED_FILE_SRC='$(LIBHOGWEED_FILE)'
609     LIBHOGWEED_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,--out-implib=$(LIBHOGWEED_FILE) -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive'
610     LIBHOGWEED_LIBS='-Wl,--no-whole-archive $(LIBS) libnettle.dll.a'
611     IF_DLL=''
612     ;;
613   darwin*)
614     LIBNETTLE_FORLINK=libnettle.dylib
615     LIBNETTLE_SONAME='libnettle.$(LIBNETTLE_MAJOR).dylib'
616     LIBNETTLE_FILE='libnettle.$(LIBNETTLE_MAJOR).$(LIBNETTLE_MINOR).dylib'
617     LIBNETTLE_LINK='$(CC) $(CFLAGS) -dynamiclib $(LDFLAGS) -install_name ${libdir}/$(LIBNETTLE_SONAME) -compatibility_version $(LIBNETTLE_MAJOR) -current_version $(LIBNETTLE_MAJOR).$(LIBNETTLE_MINOR)'
618     LIBNETTLE_LIBS=''
619
620     LIBHOGWEED_FORLINK=libhogweed.dylib
621     LIBHOGWEED_SONAME='libhogweed.$(LIBHOGWEED_MAJOR).dylib'
622     LIBHOGWEED_FILE='libhogweed.$(LIBHOGWEED_MAJOR).$(LIBHOGWEED_MINOR).dylib'
623     LIBHOGWEED_LINK='$(CC) $(CFLAGS) -dynamiclib -L. $(LDFLAGS) -install_name ${libdir}/$(LIBHOGWEED_SONAME) -compatibility_version $(LIBHOGWEED_MAJOR) -current_version $(LIBHOGWEED_MAJOR).$(LIBHOGWEED_MINOR)'
624     LIBHOGWEED_LIBS='-lnettle $(LIBS)'
625     ;;
626   solaris*)
627     # Sun's ld uses -h to set the soname, and this option is passed
628     # through by both Sun's compiler and gcc. Might not work with GNU
629     # ld, but it's unusual to use GNU ld on Solaris.
630     LIBNETTLE_FORLINK=libnettle.so
631     LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
632     LIBNETTLE_FILE='$(LIBNETTLE_SONAME).$(LIBNETTLE_MINOR)'
633     LIBNETTLE_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -G -h $(LIBNETTLE_SONAME)'
634     LIBNETTLE_LIBS=''
635
636     LIBHOGWEED_FORLINK=libhogweed.so
637     LIBHOGWEED_SONAME='$(LIBHOGWEED_FORLINK).$(LIBHOGWEED_MAJOR)'
638     LIBHOGWEED_FILE='$(LIBHOGWEED_SONAME).$(LIBHOGWEED_MINOR)'
639     LIBHOGWEED_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -G -h $(LIBHOGWEED_SONAME)'
640     LIBHOGWEED_LIBS='libnettle.so $(LIBS)'
641     ;;
642   *)
643     LIBNETTLE_FORLINK=libnettle.so
644     LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
645     LIBNETTLE_FILE='$(LIBNETTLE_SONAME).$(LIBNETTLE_MINOR)'
646     LIBNETTLE_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname=$(LIBNETTLE_SONAME)'
647     LIBNETTLE_LIBS=''
648
649     LIBHOGWEED_FORLINK=libhogweed.so
650     LIBHOGWEED_SONAME='$(LIBHOGWEED_FORLINK).$(LIBHOGWEED_MAJOR)'
651     LIBHOGWEED_FILE='$(LIBHOGWEED_SONAME).$(LIBHOGWEED_MINOR)'
652     LIBHOGWEED_LINK='$(CC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname=$(LIBHOGWEED_SONAME)'
653     # Requested by debian, to make linking with only -lhogweed work
654     # (does not work in general, e.g., with static linking all of
655     # -lhogweed -lgmp -lnettle are still required). Also makes dlopen
656     # of libhogweed.so work, without having to use RTLD_GLOBAL.
657     LIBHOGWEED_LIBS='libnettle.so $(LIBS)'
658     ;;
659 esac
660
661 ASM_SYMBOL_PREFIX=''
662 ASM_ELF_STYLE='no'
663 ASM_COFF_STYLE='no'
664 # GNU as default is to use @
665 ASM_TYPE_FUNCTION='@function'
666 ASM_TYPE_PROGBITS='@progbits'
667 ASM_MARK_NOEXEC_STACK=''
668 ASM_ALIGN_LOG=''
669
670 if test x$enable_assembler = xyes ; then
671   AC_CACHE_CHECK([if globals are prefixed by underscore],
672   nettle_cv_asm_underscore,
673   [ # Default is no underscore
674     nettle_cv_asm_underscore=no
675     AC_COMPILE_IFELSE(
676       [AC_LANG_SOURCE([int a_global_symbol;])],
677       [ $NM conftest.$OBJEXT >conftest.out
678         if grep _a_global_symbol conftest.out >/dev/null ; then
679           nettle_cv_asm_underscore=yes
680         elif grep a_global_symbol conftest.out >/dev/null ; then
681           nettle_cv_asm_underscore=no
682         else
683           AC_MSG_WARN([nm does not list a_global_symbol at all])
684         fi],
685       [AC_MSG_WARN([test program with a single global could not be compiled!?])])])
686   if test x$nettle_cv_asm_underscore = xyes ; then
687     ASM_SYMBOL_PREFIX='_'
688   fi
689
690   AC_CACHE_CHECK([for ELF-style .type,%function pseudo-ops],
691     [nettle_cv_asm_type_percent_function],
692     [GMP_TRY_ASSEMBLE([
693 .text
694 .globl foo
695 .type foo,%function
696 foo:
697 .Lend:
698
699 .size foo, .Lend - foo
700 ],
701        [nettle_cv_asm_type_percent_function=yes],
702        [nettle_cv_asm_type_percent_function=no])])
703
704 dnl Needs double quote for the # character
705   AC_CACHE_CHECK([[for ELF-style .type,#function pseudo-ops]],
706     [nettle_cv_asm_type_hash_function],
707     [GMP_TRY_ASSEMBLE([
708 .text
709 .globl foo
710 .type foo,#function
711 foo:
712 .Lend:
713
714 .size foo, .Lend - foo
715 ],
716        [nettle_cv_asm_type_hash_function=yes],
717        [nettle_cv_asm_type_hash_function=no])])
718
719   if test x$nettle_cv_asm_type_percent_function = xyes ; then
720     ASM_ELF_STYLE='yes'
721     ASM_TYPE_FUNCTION='%function'
722     ASM_TYPE_PROGBITS='%progbits'
723   else
724     if test x$nettle_cv_asm_type_hash_function = xyes ; then
725       ASM_ELF_STYLE='yes'
726       ASM_TYPE_FUNCTION='#function'
727       ASM_TYPE_PROGBITS='#progbits'
728     fi
729   fi
730
731   AC_CACHE_CHECK([for COFF-style .type directive],
732     [nettle_cv_asm_coff_type],
733       [GMP_TRY_ASSEMBLE([
734 .text
735 .globl _foo
736 .def _foo
737 .scl 2
738 .type 32
739 .endef
740 _foo:
741 ],
742         [nettle_cv_asm_coff_type=yes],
743         [nettle_cv_asm_coff_type=no])])
744   if test "x$nettle_cv_asm_coff_type" = "xyes" ; then
745     ASM_COFF_STYLE=yes
746   fi
747
748   AC_CACHE_CHECK([if we should use a .note.GNU-stack section],
749   nettle_cv_asm_gnu_stack,
750   [ # Default
751     nettle_cv_asm_gnu_stack=no
752
753     cat >conftest.c <<EOF
754 int foo() { return 0; }
755 EOF
756     nettle_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
757     if AC_TRY_EVAL(nettle_compile); then
758       cat conftest.out >&AC_FD_CC
759       $OBJDUMP -x conftest.o | grep '\.note\.GNU-stack' > /dev/null \
760       && nettle_cv_asm_gnu_stack=yes
761     else
762       cat conftest.out >&AC_FD_CC
763       echo "configure: failed program was:" >&AC_FD_CC
764       cat conftest.s >&AC_FD_CC
765     fi
766     rm -f conftest.*])
767   if test x$nettle_cv_asm_gnu_stack = xyes ; then
768     ASM_MARK_NOEXEC_STACK='.section .note.GNU-stack,"",TYPE_PROGBITS'
769   fi
770
771   AC_CACHE_CHECK([if .align assembly directive is logarithmic],
772     [nettle_cv_asm_align_log],
773     [GMP_TRY_ASSEMBLE([
774 .align 3
775 ],
776        [nettle_cv_asm_align_log=yes],
777        [nettle_cv_asm_align_log=no])])
778   ASM_ALIGN_LOG="$nettle_cv_asm_align_log"
779 fi
780
781 AC_SUBST(ASM_SYMBOL_PREFIX)
782 AC_SUBST(ASM_ELF_STYLE)
783 AC_SUBST(ASM_COFF_STYLE)
784 AC_SUBST(ASM_TYPE_FUNCTION)
785 AC_SUBST(ASM_TYPE_PROGBITS)
786 AC_SUBST(ASM_MARK_NOEXEC_STACK)
787 AC_SUBST(ASM_ALIGN_LOG)
788 AC_SUBST(W64_ABI)
789 AC_SUBST(EMULATOR)
790
791 AC_SUBST(LIBNETTLE_MAJOR)
792 AC_SUBST(LIBNETTLE_MINOR)
793 AC_SUBST(LIBNETTLE_FORLINK)
794 AC_SUBST(LIBNETTLE_SONAME)
795 AC_SUBST(LIBNETTLE_FILE)
796 AC_SUBST(LIBNETTLE_FILE_SRC)
797 AC_SUBST(LIBNETTLE_LINK)
798 AC_SUBST(LIBNETTLE_LIBS)
799
800 AC_SUBST(LIBHOGWEED_MAJOR)
801 AC_SUBST(LIBHOGWEED_MINOR)
802 AC_SUBST(LIBHOGWEED_FORLINK)
803 AC_SUBST(LIBHOGWEED_SONAME)
804 AC_SUBST(LIBHOGWEED_FILE)
805 AC_SUBST(LIBHOGWEED_FILE_SRC)
806 AC_SUBST(LIBHOGWEED_LINK)
807 AC_SUBST(LIBHOGWEED_LIBS)
808
809 AC_PATH_PROG(M4, m4, m4)
810
811 AH_TEMPLATE([WITH_HOGWEED], [Defined if public key features are enabled])
812
813 if test "x$enable_public_key" = xyes ; then
814   AC_DEFINE(WITH_HOGWEED)
815   IF_HOGWEED=''
816 else
817   IF_HOGWEED='#'
818 fi
819
820 if test "x$enable_static" = xyes ; then
821   IF_STATIC=''
822 else
823   IF_STATIC='#'
824 fi
825
826 IF_DLOPEN_TEST='#'
827 if test "x$enable_shared" = xyes ; then
828   IF_SHARED=''
829   IF_NOT_SHARED='#'
830   if test "x$ac_cv_lib_dl_dlopen" = xyes ; then
831     IF_DLOPEN_TEST=''
832   fi
833 else
834   IF_SHARED='#'
835   IF_NOT_SHARED=''
836 fi
837
838 # Documentation tools
839 if test "x$enable_documentation" != "xno"; then
840   AC_PATH_PROG(MAKEINFO, makeinfo, not-found)
841
842   if test "x$MAKEINFO" != "xnot-found"; then
843     enable_documentation=yes
844     AC_SUBST(MAKEINFO)
845   else
846     if test "x$enable_documentation" == "xauto" ; then
847       enable_documentation=no
848     else
849       AC_MSG_ERROR([Cannot find 'makeinfo', required for documentation.])
850     fi
851   fi
852 fi
853
854 if test "x$enable_documentation" = "xyes" ; then
855   IF_DOCUMENTATION=''
856 else
857   IF_DOCUMENTATION='#'
858 fi
859
860 if test "x$enable_mini_gmp" = "xyes" ; then
861   IF_MINI_GMP=''
862 else
863   IF_MINI_GMP='#'
864 fi
865   
866 AC_SUBST(IF_HOGWEED)
867 AC_SUBST(IF_STATIC)
868 AC_SUBST(IF_SHARED)
869 AC_SUBST(IF_NOT_SHARED)
870 AC_SUBST(IF_DLOPEN_TEST)
871 AC_SUBST(IF_DOCUMENTATION)
872 AC_SUBST(IF_DLL)
873 AC_SUBST(IF_MINI_GMP)
874
875 OPENSSL_LIBFLAGS=''
876
877 # Check for openssl's libcrypto (used only for benchmarking)
878 if test x$enable_openssl = xyes ; then
879   AC_CHECK_LIB(crypto, BF_ecb_encrypt,
880     [OPENSSL_LIBFLAGS='-lcrypto'],
881     [enable_openssl=no])
882 fi
883
884 AH_TEMPLATE([WITH_OPENSSL],
885             [Define if you have openssl's libcrypto (used for benchmarking)]) dnl'
886
887 if test x$enable_openssl = xyes ; then
888   AC_DEFINE(WITH_OPENSSL)
889 fi
890
891 AC_SUBST(OPENSSL_LIBFLAGS)
892
893 AH_BOTTOM(
894 [#if defined(__x86_64__) || defined(__arch64__)
895 # define HAVE_NATIVE_64_BIT 1
896 #else
897 /* Needs include of <limits.h> before use. */
898 # define HAVE_NATIVE_64_BIT (SIZEOF_LONG * CHAR_BIT >= 64)
899 #endif
900 ])
901
902 # clock_gettime is in librt on *-*-osf5.1 and on glibc, so add -lrt to
903 # BENCH_LIBS if needed. On linux (tested on x86_32, 2.6.26),
904 # clock_getres reports ns accuracy, while in a quick test on osf
905 # clock_getres said only 1 millisecond.
906
907 old_LIBS="$LIBS"
908 AC_SEARCH_LIBS(clock_gettime, rt, [
909   AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define if clock_gettime is available])])
910 BENCH_LIBS="$LIBS"
911 LIBS="$old_LIBS"
912
913 AC_SUBST(BENCH_LIBS)
914
915 # Set these flags *last*, or else the test programs won't compile
916 if test x$GCC = xyes ; then
917   # Using -ggdb3 makes (some versions of) Redhat's gcc-2.96 dump core
918   if $CC --version | grep '^2\.96$' 1>/dev/null 2>&1; then
919     true
920   else
921     CFLAGS="$CFLAGS -ggdb3"
922   fi
923   # FIXME: It would be better to actually test if this option works and/or is needed.
924   # Or perhaps use -funsigned-char.
925   if $CC --version | grep 'gcc.* 4\.' 1>/dev/null 2>&1; then
926     CFLAGS="$CFLAGS -Wno-pointer-sign"
927   fi
928   CFLAGS="$CFLAGS -Wall -W \
929   -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
930   -Wpointer-arith -Wbad-function-cast -Wnested-externs"
931
932 # Don't enable -Wcast-align as it results in tons of warnings in the
933 # DES code. And when using stdio.
934 # Don't enable -Waggregate-return, as that causes warnings for glibc
935 # inttypes.h.
936 fi
937
938 AC_CONFIG_FILES([config.make config.m4 Makefile version.h])
939 AC_CONFIG_FILES([tools/Makefile testsuite/Makefile examples/Makefile])
940 AC_CONFIG_FILES([nettle.pc hogweed.pc libnettle.map libhogweed.map])
941
942 AC_OUTPUT
943
944 AC_MSG_NOTICE([summary of build options:
945
946   Version:           ${PACKAGE_STRING}
947   Host type:         ${host}
948   ABI:               ${ABI}
949   Assembly files:    ${asm_path:-none}
950   Install prefix:    ${prefix}
951   Library directory: ${libdir}
952   Compiler:          ${CC}
953   Static libraries:  ${enable_static}
954   Shared libraries:  ${enable_shared}
955   Public key crypto: ${enable_public_key}
956   Using mini-gmp:    ${enable_mini_gmp}
957   Documentation:     ${enable_documentation}
958 ])