Merge branch 'upstream' into stable
[gnulib.git] / m4 / trunc.m4
1 # trunc.m4 serial 4
2 dnl Copyright (C) 2007, 2010 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   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   dnl Persuade glibc <math.h> to declare trunc().
11   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
12   dnl Test whether trunc() is declared.
13   AC_CHECK_DECLS([trunc], , , [#include <math.h>])
14   if test "$ac_cv_have_decl_trunc" = yes; then
15     dnl Test whether trunc() can be used without libm.
16     TRUNC_LIBM=?
17     AC_LINK_IFELSE(
18       [AC_LANG_PROGRAM(
19          [[#ifndef __NO_MATH_INLINES
20            # define __NO_MATH_INLINES 1 /* for glibc */
21            #endif
22            #include <math.h>
23            double x;]],
24          [[x = trunc(x);]])],
25       [TRUNC_LIBM=])
26     if test "$TRUNC_LIBM" = "?"; then
27       save_LIBS="$LIBS"
28       LIBS="$LIBS -lm"
29       AC_LINK_IFELSE(
30         [AC_LANG_PROGRAM(
31            [[#ifndef __NO_MATH_INLINES
32              # define __NO_MATH_INLINES 1 /* for glibc */
33              #endif
34              #include <math.h>
35              double x;]],
36            [[x = trunc(x);]])],
37         [TRUNC_LIBM="-lm"])
38       LIBS="$save_LIBS"
39     fi
40     if test "$TRUNC_LIBM" = "?"; then
41       TRUNC_LIBM=
42     fi
43   else
44     HAVE_DECL_TRUNC=0
45     AC_LIBOBJ([trunc])
46     TRUNC_LIBM=
47   fi
48   AC_SUBST([TRUNC_LIBM])
49 ])