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