[Title] Add packaging/nettle.spec to build nettle on OBS system
[external/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], [2.1], [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=4
14 LIBNETTLE_MINOR=0
15
16 LIBHOGWEED_MAJOR=2
17 LIBHOGWEED_MINOR=0
18
19 AC_CANONICAL_HOST
20
21 # Command line options
22 AC_ARG_WITH(include-path,
23   AC_HELP_STRING([--with-include-path], [A colon-separated list of directories to search for include files]),,
24   [with_include_path=''])
25
26 if test x$with_include_path != x ; then
27   CPPFLAGS="$CPPFLAGS -I`echo $with_include_path | sed 's/:/ -I/g'`"
28 fi
29
30 AC_ARG_WITH(lib-path,
31   AC_HELP_STRING([--with-lib-path], [A colon-separated list of directories to search for libraries]),,
32   [with_lib_path=''])
33
34 if test x$with_lib_path != x ; then
35   LDFLAGS="$LDFLAGS -L`echo $with_lib_path | sed 's/:/ -L/g'`"
36 fi
37
38 AC_ARG_ENABLE(public-key,
39   AC_HELP_STRING([--disable-public-key], [Disable public key algorithms]),,
40   [enable_public_key=yes])
41
42 AC_ARG_ENABLE(assembler,
43   AC_HELP_STRING([--disable-assembler],[Disable assembler code]),,
44   [enable_assembler=yes])
45
46 AC_ARG_ENABLE(shared,
47   AC_HELP_STRING([--enable-shared], [Build a shared library]),,
48   [enable_shared=no])
49
50 AC_ARG_ENABLE(pic,
51   AC_HELP_STRING([--disable-pic],
52   [Do not try to compile library files as position independent code]),,
53   [enable_pic=yes])
54
55 AC_ARG_ENABLE(openssl,
56   AC_HELP_STRING([--disable-openssl], [Do not include openssl glue in the benchmark program]),,
57   [enable_openssl=yes])
58   
59 LSH_RPATH_INIT([`echo $with_lib_path | sed 's/:/ /g'` \
60     `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \
61     /usr/local/lib /sw/local/lib /sw/lib \
62     /usr/gnu/lib /opt/gnu/lib /sw/gnu/lib /usr/freeware/lib /usr/pkg/lib])
63
64 # Checks for programs.
65 AC_PROG_CC
66
67 # When $CC foo.c -o foo creates both foo and foo.exe, autoconf picks
68 # up the foo.exe and sets exeext to .exe. That is correct for cygwin,
69 # which has some kind of magic link from foo to foo.exe, but not for
70 # rntcl. A better check for the cygwin case would check if the
71 # contents of foo and foo.exe are equal; in the rntcl case, foo is a
72 # sh script, and foo.exe is a windows executable.
73
74 if test "x$CC" = xrntcl ; then
75     AC_MSG_NOTICE([Compiling with rntcl; clearing EXEEXT and disabling assembler])
76     ac_exeext=''
77     ac_cv_exeext=''
78     EXEEXT=''
79     enable_assembler=no
80 fi
81
82 # Used by the testsuite only
83 AC_PROG_CXX
84
85 AC_LANG_PUSH(C++)
86 AC_TRY_COMPILE([],[return 0;],[CXX_TESTS='cxx-test$(EXEEXT)'], [CXX_TESTS=''])
87 AC_SUBST([CXX_TESTS])
88 AC_LANG_POP
89
90 AC_PROG_MAKE_SET
91 AC_PROG_RANLIB
92 AC_CHECK_TOOL(NM, nm, strings)
93 # Used only for the GNU-stack configure test.
94 AC_CHECK_TOOL(OBJDUMP, objdump, false)
95
96 if test "x$ac_cv_prog_cc_stdc" = xno ; then
97   AC_ERROR([the C compiler doesn't handle ANSI-C]) #'
98 fi
99
100 AC_PROG_INSTALL
101
102 # According to the autoconf manual, needs install-sh from
103 # autoconf-2.60 or automake-1.10 to avoid races.
104 AC_PROG_MKDIR_P
105
106 LSH_DEPENDENCY_TRACKING
107
108 if test x$enable_dependency_tracking = xyes ; then
109   # Since the makefiles use include to get the dependency files, we must
110   # make sure that the files exist. We generate some more files than are
111   # actually needed.
112
113   AC_CONFIG_COMMANDS([dummy-dep-files],
114   [(cd "$srcdir" && find . -name '*.c' -print) \
115  | sed 's/\.c$//' | (while read f; do echo > "$f.o.d"; echo > "$f.po.d"; done)
116 ])
117 fi
118
119 # Figure out ABI. Currently, configurable only be setting CFLAGS.
120 ABI=standard
121
122 case "$host_cpu" in
123   [x86_64 | amd64])
124     AC_TRY_COMPILE([
125 #if defined(__x86_64__) || defined(__arch64__)
126 #error 64-bit x86
127 #endif
128     ], [], [
129       ABI=32
130     ], [
131       ABI=64
132     ])
133     ;;
134   *sparc*)
135     AC_TRY_COMPILE([
136 #if defined(__sparcv9) || defined(__arch64__)
137 #error 64-bit sparc
138 #endif
139     ], [], [
140       ABI=32
141     ], [
142       ABI=64
143     ])
144     ;;
145 esac
146
147 if test "x$ABI" != xstandard ; then
148   AC_MSG_NOTICE([Compiler uses $ABI-bit ABI. To change, set CC.])
149   if test "$libdir" = '${exec_prefix}/lib' ; then
150     # Try setting a better default
151     case "$host_cpu:$host_os:$ABI" in
152       *:solaris*:32|*:sunos*:32)
153         libdir='${exec_prefix}/lib'
154         ;;
155       *:solaris*:64|*:sunos*:64)
156         libdir='${exec_prefix}/lib/64'
157         ;;
158       # According to the fhs, all architectures except IA64
159       # puts 32-bit libraries in lib, and 64-bit in lib64.
160       *:linux*:32)
161         libdir='${exec_prefix}/lib'
162         ;;
163       *:linux*:64)
164         libdir='${exec_prefix}/lib64'
165         ;;
166       # On freebsd, it seems 32-bit libraries are in lib32,
167       # and 64-bit in lib. Don't know about "kfreebsd", does
168       # it follow the Linux fhs conventions?
169       *:freebsd*:32)
170         libdir='${exec_prefix}/lib32'
171         ;;
172       *:freebsd*:64)
173         libdir='${exec_prefix}/lib'
174         ;;
175       *)
176         AC_MSG_WARN([Don't know where to install $ABI-bit libraries on this system.]); #'
177
178     esac
179     AC_MSG_NOTICE([Libraries to be installed in $libdir.])
180   fi
181 fi
182
183 # Select assembler code
184 asm_path=
185 case "$host_cpu" in
186   [i?86* | k[5-8]* | pentium* | athlon])
187     asm_path=x86
188     ;;
189   [x86_64 | amd64])
190     if test "$ABI" = 64 ; then
191       asm_path=x86_64
192     else
193       asm_path=x86
194     fi
195     ;;
196   *sparc*)
197     if test "$ABI" = 64 ; then
198       asm_path=sparc64
199     else
200       asm_path=sparc32
201     fi
202     ;;
203   *)
204     enable_assembler=no
205     ;;
206 esac
207
208 # echo "enable_assembler: $enable_assembler, asm_path: $asm_path"
209
210 if test "x$enable_assembler" = xyes ; then
211   if test -n "$asm_path"; then
212     AC_MSG_NOTICE([Looking for assembler files in $asm_path/.])
213     found=no
214     for tmp_f in aes-encrypt-internal.asm aes-decrypt-internal.asm \
215                  arcfour-crypt.asm camellia-crypt-internal.asm \
216                  md5-compress.asm sha1-compress.asm machine.m4; do
217 #       echo "Looking for $srcdir/$asm_path/$tmp_f"
218       if test -f "$srcdir/$asm_path/$tmp_f"; then
219 #        echo found
220         found=yes
221         AC_CONFIG_LINKS($tmp_f:$asm_path/$tmp_f)
222       fi
223     done
224     if test "$found" = no; then
225       enable_assembler=no
226       AC_MSG_WARN([No assembler files found.])
227     fi
228   fi
229 fi
230
231 LSH_CCPIC
232
233 SHLIBCFLAGS="$CCPIC"
234
235 case "$host_os" in
236   cygwin*)
237     LIBNETTLE_FORLINK='cygnettle-$(LIBNETTLE_MAJOR)-$(LIBNETTLE_MINOR).dll'
238     LIBNETTLE_SONAME=''
239     LIBNETTLE_FILE='libnettle.dll.a'
240     LIBNETTLE_LINK='$(CC) $(LDFLAGS) -shared -Wl,--out-implib=$(LIBNETTLE_LIBFILE) -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive'
241     LIBNETTLE_LIBS='-Wl,--no-whole-archive $(LIBS)'
242
243     LIBHOGWEED_FORLINK='cyghogweed-$(LIBHOGWEED_MAJOR)-$(LIBHOGWEED_MINOR).dll'
244     LIBHOGWEED_SONAME=''
245     LIBHOGWEED_FILE='libhogweed.dll.a'
246     LIBHOGWEED_LINK='$(CC) $(LDFLAGS) -shared -Wl,--out-implib=$(LIBHOGWEED_LIBFILE) -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--whole-archive'
247     LIBHOGWEED_LIBS='-Wl,--no-whole-archive $(LIBS)'
248     ;;
249   darwin*)
250     LIBNETTLE_FORLINK=libnettle.dylib
251     LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
252     LIBNETTLE_FILE='$(LIBNETTLE_SONAME).$(LIBNETTLE_MINOR)'
253     LIBNETTLE_LINK='$(CC) -dynamiclib $(LDFLAGS)'
254     LIBNETTLE_LIBS=''
255
256     LIBHOGWEED_FORLINK=libhogweed.dylib
257     LIBHOGWEED_SONAME='$(LIBHOGWEED_FORLINK).$(LIBHOGWEED_MAJOR)'
258     LIBHOGWEED_FILE='$(LIBHOGWEED_SONAME).$(LIBHOGWEED_MINOR)'
259     LIBHOGWEED_LINK='$(CC) -dynamiclib $(LDFLAGS)'
260     LIBHOGWEED_LIBS=''
261     ;;
262   *)
263     LIBNETTLE_FORLINK=libnettle.so
264     LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
265     LIBNETTLE_FILE='$(LIBNETTLE_SONAME).$(LIBNETTLE_MINOR)'
266     LIBNETTLE_LINK='$(CC) $(LDFLAGS) -shared -Wl,-soname=$(LIBNETTLE_SONAME)'
267     LIBNETTLE_LIBS=''
268
269     LIBHOGWEED_FORLINK=libhogweed.so
270     LIBHOGWEED_SONAME='$(LIBHOGWEED_FORLINK).$(LIBHOGWEED_MAJOR)'
271     LIBHOGWEED_FILE='$(LIBHOGWEED_SONAME).$(LIBHOGWEED_MINOR)'
272     LIBHOGWEED_LINK='$(CC) $(LDFLAGS) -L. -shared -Wl,-soname=$(LIBHOGWEED_SONAME)'
273     # Requested by debian, to make linking with only -lhogweed work
274     # (does not work in general, e.g., with static linking all of
275     # -lhogweed -lgmp -lnettle are still required). Also makes dlopen
276     # of libhogweed.so work, without having to use RTLD_GLOBAL.
277     # Depends on -L. above, to locate nettle.so.
278     LIBHOGWEED_LIBS='-lnettle -lgmp'
279     ;;
280 esac
281
282 if test "x$enable_pic" = xyes; then
283   CCPIC_MAYBE="$CCPIC"
284 else
285   CCPIC_MAYBE=''
286 fi
287 AC_SUBST([CCPIC_MAYBE])
288
289 ASM_SYMBOL_PREFIX=''
290 ASM_ELF_STYLE='no'
291 ASM_TYPE_FUNCTION=''
292 ASM_MARK_NOEXEC_STACK=''
293 ASM_ALIGN_LOG=''
294
295 if test x$enable_assembler = xyes ; then
296   AC_CACHE_CHECK([if globals are prefixed by underscore],
297   nettle_cv_asm_underscore,
298   [ # Default is no underscore
299     nettle_cv_asm_underscore=no
300     AC_COMPILE_IFELSE(
301       [int a_global_symbol;],
302       [ $NM conftest.$OBJEXT >conftest.out
303         if grep _a_global_symbol conftest.out >/dev/null ; then
304           nettle_cv_asm_underscore=yes
305         elif grep a_global_symbol conftest.out >/dev/null ; then
306           nettle_cv_asm_underscore=no
307         else
308           AC_MSG_WARN([nm doesn't list a_global_symbol at all])
309         fi],
310       [AC_MSG_WARN([test program with a single global could not be compiled!?])])])
311   if test x$nettle_cv_asm_underscore = xyes ; then
312     ASM_SYMBOL_PREFIX='_'
313   fi
314
315   AC_CACHE_CHECK([if we should use a .note.GNU-stack section],
316   nettle_cv_asm_gnu_stack,
317   [ # Default
318     nettle_cv_asm_gnu_stack=no
319
320     cat >conftest.c <<EOF
321 int foo() { return 0; }
322 EOF
323     nettle_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
324     if AC_TRY_EVAL(nettle_compile); then
325       cat conftest.out >&AC_FD_CC
326       $OBJDUMP -x conftest.o | grep '\.note\.GNU-stack' > /dev/null \
327       && nettle_cv_asm_gnu_stack=yes
328     else
329       cat conftest.out >&AC_FD_CC
330       echo "configure: failed program was:" >&AC_FD_CC
331       cat conftest.s >&AC_FD_CC
332     fi
333     rm -f conftest.*])
334   if test x$nettle_cv_asm_gnu_stack = xyes ; then
335     ASM_MARK_NOEXEC_STACK='.section .note.GNU-stack,"",@progbits'
336   fi
337
338   AC_CACHE_CHECK([for ELF-style .type,%function pseudo-ops],
339     [nettle_cv_asm_type_percent_function],
340     [GMP_TRY_ASSEMBLE([
341 .text
342 .globl foo
343 .type foo,%function
344 foo:
345 .Lend:
346
347 .size foo, .Lend - foo
348 ],
349        [nettle_cv_asm_type_percent_function=yes],
350        [nettle_cv_asm_type_percent_function=no])])
351
352 dnl Needs double quote for the # character
353   AC_CACHE_CHECK([[for ELF-style .type,#function pseudo-ops]],
354     [nettle_cv_asm_type_hash_function],
355     [GMP_TRY_ASSEMBLE([
356 .text
357 .globl foo
358 .type foo,#function
359 foo:
360 .Lend:
361
362 .size foo, .Lend - foo
363 ],
364        [nettle_cv_asm_type_hash_function=yes],
365        [nettle_cv_asm_type_hash_function=no])])
366
367   if test x$nettle_cv_asm_type_percent_function = xyes ; then
368     ASM_ELF_STYLE='yes'
369     ASM_TYPE_FUNCTION='%function'
370   else
371     if test x$nettle_cv_asm_type_hash_function = xyes ; then
372       ASM_ELF_STYLE='yes'
373       ASM_TYPE_FUNCTION='#function'
374     fi
375   fi
376   AC_CACHE_CHECK([if .align assembly directive is logarithmic],
377     [nettle_cv_asm_align_log],
378     [GMP_TRY_ASSEMBLE([
379 .align 3
380 ],
381        [nettle_cv_asm_align_log=yes],
382        [nettle_cv_asm_align_log=no])])
383   if test x$nettle_cv_asm_align_log = xyes ; then
384     ASM_ALIGN_LOG='yes'
385   fi
386 fi
387
388 AC_SUBST(ASM_SYMBOL_PREFIX)
389 AC_SUBST(ASM_ELF_STYLE)
390 AC_SUBST(ASM_TYPE_FUNCTION)
391 AC_SUBST(ASM_MARK_NOEXEC_STACK)
392 AC_SUBST(ASM_ALIGN_LOG)
393
394 AC_SUBST(SHLIBCFLAGS)
395
396 AC_SUBST(LIBNETTLE_MAJOR)
397 AC_SUBST(LIBNETTLE_MINOR)
398 AC_SUBST(LIBNETTLE_FORLINK)
399 AC_SUBST(LIBNETTLE_SONAME)
400 AC_SUBST(LIBNETTLE_FILE)
401 AC_SUBST(LIBNETTLE_LINK)
402 AC_SUBST(LIBNETTLE_LIBS)
403
404 AC_SUBST(LIBHOGWEED_MAJOR)
405 AC_SUBST(LIBHOGWEED_MINOR)
406 AC_SUBST(LIBHOGWEED_FORLINK)
407 AC_SUBST(LIBHOGWEED_SONAME)
408 AC_SUBST(LIBHOGWEED_FILE)
409 AC_SUBST(LIBHOGWEED_LINK)
410 AC_SUBST(LIBHOGWEED_LIBS)
411
412 AC_PATH_PROG(M4, m4, m4)
413
414 # Checks for typedefs, structures, and compiler characteristics.
415 AC_C_CONST
416 AC_C_INLINE
417 AC_TYPE_UID_T
418 AC_TYPE_SIZE_T
419 AC_HEADER_TIME
420 # Used by eratosthenes.c
421 AC_CHECK_SIZEOF(long)
422
423 AC_CHECK_HEADERS([openssl/blowfish.h openssl/des.h openssl/cast.h openssl/aes.h],,
424 [enable_openssl=no
425  break])
426
427 LSH_FUNC_ALLOCA
428
429 # Needed by the supplied memcmp.c
430 AC_C_BIGENDIAN
431 AC_REPLACE_FUNCS(memxor)
432
433 LSH_GCC_ATTRIBUTES
434
435 # According to Simon Josefsson, looking for uint32_t and friends in
436 # sys/types.h is needed on some systems, in particular cygwin.
437 AX_CREATE_STDINT_H([nettle-stdint.h], [sys/types.h])
438
439 # Check for file locking. We (AC_PROG_CC?) have already checked for
440 # sys/types.h and unistd.h.
441 AC_CACHE_CHECK([for fcntl file locking],
442                 nettle_cv_fcntl_locking,
443 [AC_TRY_COMPILE([
444 #if HAVE_SYS_TYPES_H
445 # include <sys/types.h>
446 #endif
447 #if HAVE_UNISTD_H
448 # include <unistd.h>
449 #endif
450 #include <fcntl.h>
451 ],[
452 int op = F_SETLKW;
453 struct flock fl;
454 ],
455 nettle_cv_fcntl_locking=yes,
456 nettle_cv_fcntl_locking=no)])
457
458 AH_TEMPLATE([HAVE_FCNTL_LOCKING], [Define if fcntl file locking is available])
459 if test "x$nettle_cv_fcntl_locking" = "xyes" ; then
460   AC_DEFINE(HAVE_FCNTL_LOCKING)
461 fi
462
463 # Checks for libraries
464 AC_CHECK_LIB(gmp, __gmpz_getlimbn,,
465     [AC_MSG_WARN(
466 [GNU MP not found, or not 3.1 or up, see http://www.swox.com/gmp.
467 Support for public key algorithms will be unavailable.])]
468     enable_public_key=no)
469
470 # Add -R flags needed to run programs linked with gmp
471 LSH_RPATH_FIX
472
473 AH_TEMPLATE([HAVE_MPZ_POWM_SEC], [Define if mpz_powm_sec is available (appeared in GMP-5)])
474 AC_CHECK_FUNC(__gmpz_powm_sec, [AC_DEFINE(HAVE_MPZ_POWM_SEC)])
475
476 AH_TEMPLATE([WITH_HOGWEED], [Defined if public key features are enabled])
477
478 if test "x$enable_public_key" = xyes ; then
479   AC_DEFINE(WITH_HOGWEED)
480   IF_HOGWEED=''
481 else
482   IF_HOGWEED='#'
483 fi
484
485 if test "x$enable_shared" = xyes ; then
486   IF_SHARED=''
487 else
488   IF_SHARED='#'
489 fi
490
491 AC_SUBST(IF_HOGWEED)
492 AC_SUBST(IF_SHARED)
493
494 OPENSSL_LIBFLAGS=''
495
496 # Check for openssl's libcrypto (used only for benchmarking)
497 if test x$enable_openssl = xyes ; then
498   AC_CHECK_LIB(crypto, BF_ecb_encrypt,
499     [OPENSSL_LIBFLAGS='-lcrypto'],
500     [enable_openssl=no])
501 fi
502
503 AH_TEMPLATE([WITH_OPENSSL],
504             [Define if you have openssl's libcrypto (used for benchmarking)])
505
506 if test x$enable_openssl = xyes ; then
507   AC_DEFINE(WITH_OPENSSL)
508 fi
509
510 AC_SUBST(OPENSSL_LIBFLAGS)
511
512 # Set these flags *last*, or else the test programs won't compile
513 if test x$GCC = xyes ; then
514   # Using -ggdb3 makes (some versions of) Redhat's gcc-2.96 dump core
515   if "$CC" --version | grep '^2\.96$' 1>/dev/null 2>&1; then
516     true
517   else
518     CFLAGS="$CFLAGS -ggdb3"
519   fi
520   # FIXME: It would be better to actually test if this option works and/or is needed.
521   # Or perhaps use -funsigned-char.
522   if "$CC" --version | grep 'gcc.* 4\.' 1>/dev/null 2>&1; then
523     CFLAGS="$CFLAGS -Wno-pointer-sign"
524   fi
525   CFLAGS="$CFLAGS -Wall -W \
526   -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
527   -Wpointer-arith -Wbad-function-cast -Wnested-externs"
528
529 # Don't enable -Wcast-align as it results in tons of warnings in the
530 # DES code. And when using stdio.
531 # Don't enable -Waggregate-return, as that causes warnings for glibc
532 # inttypes.h.
533 fi
534
535 AC_CONFIG_FILES([config.make config.m4 Makefile])
536 AC_CONFIG_FILES([tools/Makefile testsuite/Makefile examples/Makefile])
537
538 AC_OUTPUT
539