]> git.ipfire.org Git - thirdparty/nettle.git/blob - aclocal.m4
Use NETTLE_OCTET_SIZE_TO_LIMB_SIZE macro.
[thirdparty/nettle.git] / aclocal.m4
1 dnl Choose cc flags for compiling position independent code
2 AC_DEFUN([LSH_CCPIC],
3 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
4 AC_MSG_CHECKING(CCPIC)
5 AC_CACHE_VAL(lsh_cv_sys_ccpic,[
6 if test -z "$CCPIC" ; then
7 if test "$GCC" = yes ; then
8 case "$host_os" in
9 bsdi4.*) CCPIC="-fPIC" ;;
10 bsdi*) CCPIC="" ;;
11 darwin*) CCPIC="-fPIC" ;;
12 freebsd*|netbsd*|openbsd*) CCPIC="-fPIC" ;;
13 # Could also use -fpic, depending on the number of symbol references
14 solaris*) CCPIC="-fPIC" ;;
15 cygwin*) CCPIC="" ;;
16 mingw32*) CCPIC="" ;;
17 *) CCPIC="-fpic" ;;
18 esac
19 else
20 case "$host_os" in
21 darwin*) CCPIC="-fPIC" ;;
22 irix*) CCPIC="-share" ;;
23 hpux*) CCPIC="+z"; ;;
24 freebsd*|netbsd*|openbsd*) CCPIC="-fPIC" ;;
25 sco*|sysv4.*) CCPIC="-KPIC -dy -Bdynamic" ;;
26 solaris*) CCPIC="-KPIC -Bdynamic" ;;
27 winnt*) CCPIC="-shared" ;;
28 *) CCPIC="" ;;
29 esac
30 fi
31 fi
32 OLD_CFLAGS="$CFLAGS"
33 CFLAGS="$CFLAGS $CCPIC"
34 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0;]])],
35 [lsh_cv_sys_ccpic="$CCPIC"], [lsh_cv_sys_ccpic=''])
36 CFLAGS="$OLD_CFLAGS"
37 ])
38 CCPIC="$lsh_cv_sys_ccpic"
39 AC_MSG_RESULT($CCPIC)])
40
41 dnl LSH_PATH_ADD(path-id, directory)
42 AC_DEFUN([LSH_PATH_ADD],
43 [AC_MSG_CHECKING($2)
44 ac_exists=no
45 if test -d "$2/." ; then
46 ac_real_dir=`cd $2 && pwd`
47 if test -n "$ac_real_dir" ; then
48 ac_exists=yes
49 for old in $1_REAL_DIRS ; do
50 ac_found=no
51 if test x$ac_real_dir = x$old ; then
52 ac_found=yes;
53 break;
54 fi
55 done
56 if test $ac_found = yes ; then
57 AC_MSG_RESULT(already added)
58 else
59 AC_MSG_RESULT(added)
60 # LDFLAGS="$LDFLAGS -L $2"
61 $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS"
62 $1_DIRS="$2 [$]$1_DIRS"
63 fi
64 fi
65 fi
66 if test $ac_exists = no ; then
67 AC_MSG_RESULT(not found)
68 fi
69 ])
70
71 dnl LSH_RPATH_ADD(dir)
72 AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)])
73
74 dnl LSH_RPATH_INIT(candidates)
75 AC_DEFUN([LSH_RPATH_INIT],
76 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
77 AC_MSG_CHECKING([for -R flag])
78 RPATHFLAG=''
79 case "$host_os" in
80 osf1*) RPATHFLAG="-rpath " ;;
81 irix6.*|irix5.*) RPATHFLAG="-rpath " ;;
82 solaris*)
83 if test "$TCC" = "yes"; then
84 # tcc doesn't know about -R
85 RPATHFLAG="-Wl,-R,"
86 else
87 RPATHFLAG=-R
88 fi
89 ;;
90 linux*|freebsd*) RPATHFLAG="-Wl,-rpath," ;;
91 *) RPATHFLAG="" ;;
92 esac
93
94 if test x$RPATHFLAG = x ; then
95 AC_MSG_RESULT(none)
96 else
97 AC_MSG_RESULT([using $RPATHFLAG])
98 fi
99
100 RPATH_CANDIDATE_REAL_DIRS=''
101 RPATH_CANDIDATE_DIRS=''
102
103 AC_MSG_RESULT([Searching for libraries])
104
105 for d in $1 ; do
106 LSH_RPATH_ADD($d)
107 done
108 ])
109
110 dnl Try to execute a main program, and if it fails, try adding some
111 dnl -R flag.
112 dnl LSH_RPATH_FIX
113 AC_DEFUN([LSH_RPATH_FIX],
114 [if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
115 ac_success=no
116 AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(int argc, char **argv) { return 0; }]])],
117 [ac_success=yes], [ac_success=no], [:])
118
119 if test $ac_success = no ; then
120 AC_MSG_CHECKING([Running simple test program failed. Trying -R flags])
121 dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS
122 ac_remaining_dirs=''
123 ac_rpath_save_LDFLAGS="$LDFLAGS"
124 for d in $RPATH_CANDIDATE_DIRS ; do
125 if test $ac_success = yes ; then
126 ac_remaining_dirs="$ac_remaining_dirs $d"
127 else
128 LDFLAGS="$RPATHFLAG$d $LDFLAGS"
129 dnl echo LDFLAGS = $LDFLAGS
130 AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(int argc, char **argv) { return 0; }]])],
131 [ac_success=yes
132 ac_rpath_save_LDFLAGS="$LDFLAGS"
133 AC_MSG_RESULT([adding $RPATHFLAG$d])
134 ],
135 [ac_remaining_dirs="$ac_remaining_dirs $d"], [:])
136 LDFLAGS="$ac_rpath_save_LDFLAGS"
137 fi
138 done
139 RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
140 fi
141 if test $ac_success = no ; then
142 AC_MSG_RESULT(failed)
143 fi
144 fi
145 ])
146
147 dnl LSH_GCC_ATTRIBUTES
148 dnl Check for gcc's __attribute__ construction
149
150 AC_DEFUN([LSH_GCC_ATTRIBUTES],
151 [AC_CACHE_CHECK(for __attribute__,
152 lsh_cv_c_attribute,
153 [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
154 #include <stdlib.h>
155
156 static void foo(void) __attribute__ ((noreturn));
157
158 static void __attribute__ ((noreturn))
159 foo(void)
160 {
161 exit(1);
162 }
163 ]], [[]])],
164 [lsh_cv_c_attribute=yes],
165 [lsh_cv_c_attribute=no])])
166
167 AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__])
168 if test "x$lsh_cv_c_attribute" = "xyes"; then
169 AC_DEFINE(HAVE_GCC_ATTRIBUTE)
170 fi
171
172 AH_BOTTOM(
173 [#if __GNUC__ && HAVE_GCC_ATTRIBUTE
174 # define NORETURN __attribute__ ((__noreturn__))
175 # define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a)))
176 # define UNUSED __attribute__ ((__unused__))
177 #else
178 # define NORETURN
179 # define PRINTF_STYLE(f, a)
180 # define UNUSED
181 #endif
182 ])])
183
184 # Check for alloca, and include the standard blurb in config.h
185 AC_DEFUN([LSH_FUNC_ALLOCA],
186 [AC_FUNC_ALLOCA
187 AC_CHECK_HEADERS([malloc.h])
188 AH_BOTTOM(
189 [/* AIX requires this to be the first thing in the file. */
190 #ifndef __GNUC__
191 # if HAVE_ALLOCA_H
192 # include <alloca.h>
193 # else
194 # ifdef _AIX
195 #pragma alloca
196 # else
197 # ifndef alloca /* predefined by HP cc +Olibcalls */
198 char *alloca ();
199 # endif
200 # endif
201 /* Needed for alloca on windows */
202 # if HAVE_MALLOC_H
203 # include <malloc.h>
204 # endif
205 # endif
206 #else /* defined __GNUC__ */
207 # if HAVE_ALLOCA_H
208 # include <alloca.h>
209 # else
210 /* Needed for alloca on windows, also with gcc */
211 # if HAVE_MALLOC_H
212 # include <malloc.h>
213 # endif
214 # endif
215 #endif
216 ])])
217
218 dnl LSH_DEPENDENCY_TRACKING
219
220 dnl Defines compiler flags DEP_FLAGS to generate dependency
221 dnl information, and DEP_PROCESS that is any shell commands needed for
222 dnl massaging the dependency information further. Dependencies are
223 dnl generated as a side effect of compilation. Dependency files
224 dnl themselves are not treated as targets.
225
226 AC_DEFUN([LSH_DEPENDENCY_TRACKING],
227 [AC_ARG_ENABLE(dependency_tracking,
228 AS_HELP_STRING([--disable-dependency-tracking], [Disable dependency tracking. Dependency tracking doesn't work with BSD make]),,
229 [enable_dependency_tracking=yes])
230
231 DEP_FLAGS=''
232 DEP_PROCESS='true'
233 if test x$enable_dependency_tracking = xyes ; then
234 if test x$GCC = xyes ; then
235 gcc_version=`gcc --version | head -1`
236 case "$gcc_version" in
237 2.*|*[[!0-9.]]2.*)
238 enable_dependency_tracking=no
239 AC_MSG_WARN([Dependency tracking disabled, gcc-3.x is needed])
240 ;;
241 *)
242 DEP_FLAGS='-MT $[]@ -MD -MP -MF $[]@.d'
243 DEP_PROCESS='true'
244 ;;
245 esac
246 else
247 enable_dependency_tracking=no
248 AC_MSG_WARN([Dependency tracking disabled])
249 fi
250 fi
251
252 AC_SUBST([DEP_FLAGS])
253 AC_SUBST([DEP_PROCESS])])
254
255 dnl GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
256 dnl ----------------------------------------------------------
257 dnl Attempt to assemble the given code.
258 dnl Do "action-success" if this succeeds, "action-fail" if not.
259 dnl
260 dnl conftest.o and conftest.out are available for inspection in
261 dnl "action-success". If either action does a "break" out of a loop then
262 dnl an explicit "rm -f conftest*" will be necessary.
263 dnl
264 dnl This is not unlike AC_COMPILE_IFELSE, but there's no default includes or
265 dnl anything in "asm-code", everything wanted must be given explicitly.
266
267 AC_DEFUN([GMP_TRY_ASSEMBLE],
268 [cat >conftest.s <<EOF
269 [$1]
270 EOF
271 gmp_assemble="$CC $CFLAGS $CPPFLAGS $ASM_FLAGS -c conftest.s >conftest.out 2>&1"
272 if AC_TRY_EVAL(gmp_assemble); then
273 cat conftest.out >&AS_MESSAGE_LOG_FD
274 ifelse([$2],,:,[$2])
275 else
276 cat conftest.out >&AS_MESSAGE_LOG_FD
277 echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
278 cat conftest.s >&AS_MESSAGE_LOG_FD
279 ifelse([$3],,:,[$3])
280 fi
281 rm -f conftest*
282 ])
283
284 dnl GMP_PROG_CC_FOR_BUILD
285 dnl ---------------------
286 dnl Establish CC_FOR_BUILD, a C compiler for the build system.
287 dnl
288 dnl If CC_FOR_BUILD is set then it's expected to work, likewise the old
289 dnl style HOST_CC, otherwise some likely candidates are tried, the same as
290 dnl configfsf.guess.
291
292 AC_DEFUN([GMP_PROG_CC_FOR_BUILD],
293 [AC_REQUIRE([AC_PROG_CC])
294 if test -n "$CC_FOR_BUILD"; then
295 GMP_PROG_CC_FOR_BUILD_WORKS($CC_FOR_BUILD,,
296 [AC_MSG_ERROR([Specified CC_FOR_BUILD doesn't seem to work])])
297 elif test -n "$HOST_CC"; then
298 GMP_PROG_CC_FOR_BUILD_WORKS($HOST_CC,
299 [CC_FOR_BUILD=$HOST_CC],
300 [AC_MSG_ERROR([Specified HOST_CC doesn't seem to work])])
301 else
302 if test $cross_compiling = no ; then
303 CC_FOR_BUILD="$CC"
304 else
305 for i in gcc cc c89 c99; do
306 GMP_PROG_CC_FOR_BUILD_WORKS($i,
307 [CC_FOR_BUILD=$i
308 break])
309 done
310 if test -z "$CC_FOR_BUILD"; then
311 AC_MSG_ERROR([Cannot find a build system compiler])
312 fi
313 fi
314 if test "$CC_FOR_BUILD" = gcc ; then
315 CC_FOR_BUILD="$CC_FOR_BUILD -O -g"
316 fi
317 fi
318
319 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
320 AC_SUBST(CC_FOR_BUILD)
321 ])
322
323
324 dnl GMP_PROG_CC_FOR_BUILD_WORKS(cc/cflags[,[action-if-good][,action-if-bad]])
325 dnl -------------------------------------------------------------------------
326 dnl See if the given cc/cflags works on the build system.
327 dnl
328 dnl It seems easiest to just use the default compiler output, rather than
329 dnl figuring out the .exe or whatever at this stage.
330
331 AC_DEFUN([GMP_PROG_CC_FOR_BUILD_WORKS],
332 [AC_MSG_CHECKING([build system compiler $1])
333 # remove anything that might look like compiler output to our "||" expression
334 rm -f conftest* a.out b.out a.exe a_out.exe
335 cat >conftest.c <<EOF
336 int
337 main ()
338 {
339 return 0;
340 }
341 EOF
342 gmp_compile="$1 conftest.c"
343 cc_for_build_works=no
344 if AC_TRY_EVAL(gmp_compile); then
345 if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&AS_MESSAGE_LOG_FD 2>&1; then
346 cc_for_build_works=yes
347 fi
348 fi
349 rm -f conftest* a.out b.out a.exe a_out.exe
350 AC_MSG_RESULT($cc_for_build_works)
351 if test "$cc_for_build_works" = yes; then
352 ifelse([$2],,:,[$2])
353 else
354 ifelse([$3],,:,[$3])
355 fi
356 ])
357
358 dnl GMP_PROG_EXEEXT_FOR_BUILD
359 dnl -------------------------
360 dnl Determine EXEEXT_FOR_BUILD, the build system executable suffix.
361 dnl
362 dnl The idea is to find what "-o conftest$foo" will make it possible to run
363 dnl the program with ./conftest. On Unix-like systems this is of course
364 dnl nothing, for DOS it's ".exe", or for a strange RISC OS foreign file
365 dnl system cross compile it can be ",ff8" apparently. Not sure if the
366 dnl latter actually applies to a build-system executable, maybe it doesn't,
367 dnl but it won't hurt to try.
368
369 AC_DEFUN([GMP_PROG_EXEEXT_FOR_BUILD],
370 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
371 AC_CACHE_CHECK([for build system executable suffix],
372 gmp_cv_prog_exeext_for_build,
373 [if test $cross_compiling = no ; then
374 gmp_cv_prog_exeext_for_build="$EXEEXT"
375 else
376 cat >conftest.c <<EOF
377 int
378 main ()
379 {
380 return 0;
381 }
382 EOF
383 for i in .exe ,ff8 ""; do
384 gmp_compile="$CC_FOR_BUILD conftest.c -o conftest$i"
385 if AC_TRY_EVAL(gmp_compile); then
386 if (./conftest) 2>&AS_MESSAGE_LOG_FD; then
387 gmp_cv_prog_exeext_for_build=$i
388 break
389 fi
390 fi
391 done
392 rm -f conftest*
393 if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
394 AC_MSG_ERROR([Cannot determine executable suffix])
395 fi
396 fi
397 ])
398 AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)
399 ])
400
401 dnl NETTLE_CHECK_ARM_NEON
402 dnl ---------------------
403 dnl Check if ARM Neon instructions should be used.
404 dnl Obeys enable_arm_neon, which should be set earlier.
405 AC_DEFUN([NETTLE_CHECK_ARM_NEON],
406 [if test "$enable_arm_neon" = auto ; then
407 if test "$cross_compiling" = yes ; then
408 dnl Check if compiler/assembler accepts it,
409 dnl without an explicit .fpu neon directive.
410 AC_CACHE_CHECK([if assembler accepts Neon instructions],
411 nettle_cv_asm_arm_neon,
412 [GMP_TRY_ASSEMBLE([
413 .text
414 foo:
415 vmlal.u32 q1, d0, d1
416 ],
417 [nettle_cv_asm_arm_neon=yes],
418 [nettle_cv_asm_arm_neon=no])])
419 enable_arm_neon="$nettle_cv_asm_arm_neon"
420 else
421 AC_MSG_CHECKING([if /proc/cpuinfo claims neon support])
422 if grep '^Features.*:.* neon' /proc/cpuinfo >/dev/null ; then
423 enable_arm_neon=yes
424 else
425 enable_arm_neon=no
426 fi
427 AC_MSG_RESULT($enable_arm_neon)
428 fi
429 fi
430 ])
431
432 dnl NETTLE_CHECK_IFUNC
433 dnl ------------------
434 dnl Check if __attribute__ ((ifunc(...))) works
435 AC_DEFUN([NETTLE_CHECK_IFUNC],
436 [AC_REQUIRE([AC_PROG_CC])
437 AC_CACHE_CHECK([for ifunc support],
438 nettle_cv_link_ifunc,
439 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
440 static int
441 foo_imp(int x)
442 {
443 return 1;
444 }
445
446 typedef void void_func (void);
447
448 static void_func *
449 foo_resolv(void)
450 {
451 return (void_func *) foo_imp;
452 }
453
454 int foo (int x) __attribute__ ((ifunc("foo_resolv")));
455 ],[
456 return foo(0);
457
458 ])],
459 [nettle_cv_link_ifunc=yes],
460 [nettle_cv_link_ifunc=no])])
461 AH_TEMPLATE([HAVE_LINK_IFUNC], [Define if compiler and linker supports __attribute__ ifunc])
462 if test "x$nettle_cv_link_ifunc" = xyes ; then
463 AC_DEFINE(HAVE_LINK_IFUNC)
464 fi
465 ])
466
467 # ld-version-script.m4 serial 3
468 dnl Copyright (C) 2008-2014 Free Software Foundation, Inc.
469 dnl This file is free software; the Free Software Foundation
470 dnl gives unlimited permission to copy and/or distribute it,
471 dnl with or without modifications, as long as this notice is preserved.
472
473 dnl From Simon Josefsson
474
475 # FIXME: The test below returns a false positive for mingw
476 # cross-compiles, 'local:' statements does not reduce number of
477 # exported symbols in a DLL. Use --disable-ld-version-script to work
478 # around the problem.
479
480 # gl_LD_VERSION_SCRIPT
481 # --------------------
482 # Check if LD supports linker scripts, and define automake conditional
483 # HAVE_LD_VERSION_SCRIPT if so.
484 AC_DEFUN([LD_VERSION_SCRIPT],
485 [
486 AC_ARG_ENABLE([ld-version-script],
487 AS_HELP_STRING([--enable-ld-version-script],
488 [enable linker version script (default is enabled when possible)]),
489 [have_ld_version_script=$enableval], [])
490 if test -z "$have_ld_version_script"; then
491 AC_MSG_CHECKING([if LD -Wl,--version-script works])
492 save_LDFLAGS="$LDFLAGS"
493 LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
494 cat > conftest.map <<EOF
495 foo
496 EOF
497 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
498 [accepts_syntax_errors=yes], [accepts_syntax_errors=no])
499 if test "$accepts_syntax_errors" = no; then
500 cat > conftest.map <<EOF
501 VERS_1 {
502 global: sym;
503 };
504
505 VERS_2 {
506 global: sym;
507 } VERS_1;
508 EOF
509 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
510 [have_ld_version_script=yes], [have_ld_version_script=no])
511 else
512 have_ld_version_script=no
513 fi
514 rm -f conftest.map
515 LDFLAGS="$save_LDFLAGS"
516 AC_MSG_RESULT($have_ld_version_script)
517 fi
518 if test "$have_ld_version_script" = "yes";then
519 EXTRA_LINKER_FLAGS="-Wl,--version-script=libnettle.map"
520 AC_SUBST(EXTRA_LINKER_FLAGS)
521 EXTRA_HOGWEED_LINKER_FLAGS="-Wl,--version-script=libhogweed.map"
522 AC_SUBST(EXTRA_HOGWEED_LINKER_FLAGS)
523 fi
524 ])
525
526 dnl GMP_ASM_POWERPC_R_REGISTERS
527 dnl ---------------------------
528 dnl Determine whether the assembler takes powerpc registers with an "r" as
529 dnl in "r6", or as plain "6". The latter is standard, but NeXT, Rhapsody,
530 dnl and MacOS-X require the "r" forms.
531 dnl
532 dnl See also powerpc64/machine.m4 which uses the result of this
533 dnl test.
534
535 AC_DEFUN([GMP_ASM_POWERPC_R_REGISTERS],
536 [AC_CACHE_CHECK([if the assembler needs r on registers],
537 gmp_cv_asm_powerpc_r_registers,
538 [GMP_TRY_ASSEMBLE(
539 [ $gmp_cv_asm_text
540 mtctr r6],
541 [gmp_cv_asm_powerpc_r_registers=yes],
542 [GMP_TRY_ASSEMBLE(
543 [ .text
544 mtctr 6],
545 [gmp_cv_asm_powerpc_r_registers=no],
546 [AC_MSG_ERROR([neither "mtctr 6" nor "mtctr r6" works])])])])
547 ASM_PPC_WANT_R_REGISTERS="$gmp_cv_asm_powerpc_r_registers"
548 ])
549
550 # Check if valgrind supports the platform we are compiling for.
551 AC_DEFUN([NETTLE_PROG_VALGRIND],
552 [AC_CACHE_CHECK([if valgrind is working],
553 nettle_cv_prog_valgrind,
554 [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
555 if valgrind -q ./conftest$EXEEXT 2>&AS_MESSAGE_LOG_FD; then
556 nettle_cv_prog_valgrind=yes
557 else
558 nettle_cv_prog_valgrind=no
559 fi], [nettle_cv_prog_valgrind=no])])
560 if test "$nettle_cv_prog_valgrind" = yes ; then
561 IF_VALGRIND=''
562 else
563 IF_VALGRIND='#'
564 fi
565 AC_SUBST(IF_VALGRIND)
566 ])