1 dnl Choose cc flags for compiling position independent code
3 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
5 AC_CACHE_VAL(lsh_cv_sys_ccpic,[
6 if test -z "$CCPIC" ; then
7 if test "$GCC" = yes ; then
9 bsdi4.*) CCPIC="-fPIC" ;;
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" ;;
21 darwin*) CCPIC="-fPIC" ;;
22 irix*) CCPIC="-share" ;;
24 freebsd*|netbsd*|openbsd*) CCPIC="-fPIC" ;;
25 sco*|sysv4.*) CCPIC="-KPIC -dy -Bdynamic" ;;
26 solaris*) CCPIC="-KPIC -Bdynamic" ;;
27 winnt*) CCPIC="-shared" ;;
33 CFLAGS="$CFLAGS $CCPIC"
34 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0;]])],
35 [lsh_cv_sys_ccpic="$CCPIC"], [lsh_cv_sys_ccpic=''])
38 CCPIC="$lsh_cv_sys_ccpic"
39 AC_MSG_RESULT($CCPIC)])
41 dnl LSH_PATH_ADD(path-id, directory)
42 AC_DEFUN([LSH_PATH_ADD],
45 if test -d "$2/." ; then
46 ac_real_dir=`cd $2 && pwd`
47 if test -n "$ac_real_dir" ; then
49 for old in $1_REAL_DIRS ; do
51 if test x$ac_real_dir = x$old ; then
56 if test $ac_found = yes ; then
57 AC_MSG_RESULT(already added)
60 # LDFLAGS="$LDFLAGS -L $2"
61 $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS"
62 $1_DIRS="$2 [$]$1_DIRS"
66 if test $ac_exists = no ; then
67 AC_MSG_RESULT(not found)
71 dnl LSH_RPATH_ADD(dir)
72 AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)])
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])
80 osf1*) RPATHFLAG="-rpath " ;;
81 irix6.*|irix5.*) RPATHFLAG="-rpath " ;;
83 if test "$TCC" = "yes"; then
84 # tcc doesn't know about -R
90 linux*|freebsd*) RPATHFLAG="-Wl,-rpath," ;;
94 if test x$RPATHFLAG = x ; then
97 AC_MSG_RESULT([using $RPATHFLAG])
100 RPATH_CANDIDATE_REAL_DIRS=''
101 RPATH_CANDIDATE_DIRS=''
103 AC_MSG_RESULT([Searching for libraries])
110 dnl Try to execute a main program, and if it fails, try adding some
113 AC_DEFUN([LSH_RPATH_FIX],
114 [if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
116 AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(int argc, char **argv) { return 0; }]])],
117 [ac_success=yes], [ac_success=no], [:])
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
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"
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; }]])],
132 ac_rpath_save_LDFLAGS="$LDFLAGS"
133 AC_MSG_RESULT([adding $RPATHFLAG$d])
135 [ac_remaining_dirs="$ac_remaining_dirs $d"], [:])
136 LDFLAGS="$ac_rpath_save_LDFLAGS"
139 RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
141 if test $ac_success = no ; then
142 AC_MSG_RESULT(failed)
147 dnl LSH_GCC_ATTRIBUTES
148 dnl Check for gcc's __attribute__ construction
150 AC_DEFUN([LSH_GCC_ATTRIBUTES],
151 [AC_CACHE_CHECK(for __attribute__,
153 [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
156 static void foo(void) __attribute__ ((noreturn));
158 static void __attribute__ ((noreturn))
164 [lsh_cv_c_attribute=yes],
165 [lsh_cv_c_attribute=no])])
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)
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__))
179 # define PRINTF_STYLE(f, a)
184 # Check for alloca, and include the standard blurb in config.h
185 AC_DEFUN([LSH_FUNC_ALLOCA],
187 AC_CHECK_HEADERS([malloc.h])
189 [/* AIX requires this to be the first thing in the file. */
197 # ifndef alloca /* predefined by HP cc +Olibcalls */
201 /* Needed for alloca on windows */
206 #else /* defined __GNUC__ */
210 /* Needed for alloca on windows, also with gcc */
218 dnl LSH_DEPENDENCY_TRACKING
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.
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])
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
238 enable_dependency_tracking=no
239 AC_MSG_WARN([Dependency tracking disabled, gcc-3.x is needed])
242 DEP_FLAGS='-MT $[]@ -MD -MP -MF $[]@.d'
247 enable_dependency_tracking=no
248 AC_MSG_WARN([Dependency tracking disabled])
252 AC_SUBST([DEP_FLAGS])
253 AC_SUBST([DEP_PROCESS])])
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.
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.
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.
267 AC_DEFUN([GMP_TRY_ASSEMBLE],
268 [cat >conftest.s <<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
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
284 dnl GMP_PROG_CC_FOR_BUILD
285 dnl ---------------------
286 dnl Establish CC_FOR_BUILD, a C compiler for the build system.
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
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])])
302 if test $cross_compiling = no ; then
305 for i in gcc cc c89 c99; do
306 GMP_PROG_CC_FOR_BUILD_WORKS($i,
310 if test -z "$CC_FOR_BUILD"; then
311 AC_MSG_ERROR([Cannot find a build system compiler])
314 if test "$CC_FOR_BUILD" = gcc ; then
315 CC_FOR_BUILD="$CC_FOR_BUILD -O -g"
319 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
320 AC_SUBST(CC_FOR_BUILD)
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.
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.
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
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
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
358 dnl GMP_PROG_EXEEXT_FOR_BUILD
359 dnl -------------------------
360 dnl Determine EXEEXT_FOR_BUILD, the build system executable suffix.
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.
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"
376 cat >conftest.c <<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
393 if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
394 AC_MSG_ERROR([Cannot determine executable suffix])
398 AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)
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,
417 [nettle_cv_asm_arm_neon=yes],
418 [nettle_cv_asm_arm_neon=no])])
419 enable_arm_neon="$nettle_cv_asm_arm_neon"
421 AC_MSG_CHECKING([if /proc/cpuinfo claims neon support])
422 if grep '^Features.*:.* neon' /proc/cpuinfo >/dev/null ; then
427 AC_MSG_RESULT($enable_arm_neon)
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([
446 typedef void void_func (void);
451 return (void_func *) foo_imp;
454 int foo (int x) __attribute__ ((ifunc("foo_resolv")));
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)
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.
473 dnl From Simon Josefsson
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.
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],
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
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
509 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
510 [have_ld_version_script=yes], [have_ld_version_script=no])
512 have_ld_version_script=no
515 LDFLAGS="$save_LDFLAGS"
516 AC_MSG_RESULT($have_ld_version_script)
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)
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.
532 dnl See also powerpc64/machine.m4 which uses the result of this
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,
541 [gmp_cv_asm_powerpc_r_registers=yes],
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"
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
558 nettle_cv_prog_valgrind=no
559 fi], [nettle_cv_prog_valgrind=no])])
560 if test "$nettle_cv_prog_valgrind" = yes ; then
565 AC_SUBST(IF_VALGRIND)