Properly quote AC_CHECK_DECLS' 4th argument.
[gnulib.git] / m4 / trunc.m4
1 # trunc.m4 serial 8
2 dnl Copyright (C) 2007, 2010-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_TRUNC],
8 [
9   m4_divert_text([DEFAULTS], [gl_trunc_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare trunc().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether trunc() is declared.
14   AC_CHECK_DECLS([trunc], , , [[#include <math.h>]])
15   if test "$ac_cv_have_decl_trunc" = yes; then
16     dnl Test whether trunc() can be used without libm.
17     TRUNC_LIBM=?
18     AC_LINK_IFELSE(
19       [AC_LANG_PROGRAM(
20          [[#ifndef __NO_MATH_INLINES
21            # define __NO_MATH_INLINES 1 /* for glibc */
22            #endif
23            #include <math.h>
24            double x;]],
25          [[x = trunc(x);]])],
26       [TRUNC_LIBM=])
27     if test "$TRUNC_LIBM" = "?"; then
28       save_LIBS="$LIBS"
29       LIBS="$LIBS -lm"
30       AC_LINK_IFELSE(
31         [AC_LANG_PROGRAM(
32            [[#ifndef __NO_MATH_INLINES
33              # define __NO_MATH_INLINES 1 /* for glibc */
34              #endif
35              #include <math.h>
36              double x;]],
37            [[x = trunc(x);]])],
38         [TRUNC_LIBM="-lm"])
39       LIBS="$save_LIBS"
40     fi
41     if test "$TRUNC_LIBM" = "?"; then
42       TRUNC_LIBM=
43     fi
44     m4_ifdef([gl_FUNC_TRUNC_IEEE], [
45       if test $gl_trunc_required = ieee && test $REPLACE_TRUNC = 0; then
46         AC_CACHE_CHECK([whether trunc works according to ISO C 99 with IEC 60559],
47           [gl_cv_func_trunc_ieee],
48           [
49             save_LIBS="$LIBS"
50             LIBS="$LIBS $TRUNC_LIBM"
51             AC_RUN_IFELSE(
52               [AC_LANG_SOURCE([[
53 #ifndef __NO_MATH_INLINES
54 # define __NO_MATH_INLINES 1 /* for glibc */
55 #endif
56 #include <math.h>
57 ]gl_DOUBLE_MINUS_ZERO_CODE[
58 ]gl_DOUBLE_SIGNBIT_CODE[
59 static double dummy (double f) { return 0; }
60 int main (int argc, char *argv[])
61 {
62   double (*my_trunc) (double) = argc ? trunc : dummy;
63   /* Test whether trunc (-0.0) is -0.0.  */
64   if (signbitd (minus_zerod) && !signbitd (my_trunc (minus_zerod)))
65     return 1;
66   return 0;
67 }
68               ]])],
69               [gl_cv_func_trunc_ieee=yes],
70               [gl_cv_func_trunc_ieee=no],
71               [gl_cv_func_trunc_ieee="guessing no"])
72             LIBS="$save_LIBS"
73           ])
74         case "$gl_cv_func_trunc_ieee" in
75           *yes) ;;
76           *) REPLACE_TRUNC=1 ;;
77         esac
78       fi
79     ])
80   else
81     HAVE_DECL_TRUNC=0
82   fi
83   if test $HAVE_DECL_TRUNC = 0 || test $REPLACE_TRUNC = 1; then
84     dnl No libraries are needed to link lib/trunc.c.
85     TRUNC_LIBM=
86   fi
87   AC_SUBST([TRUNC_LIBM])
88 ])