Merge branch 'stable'
[gnulib.git] / m4 / truncl.m4
1 # truncl.m4 serial 5
2 dnl Copyright (C) 2007-2008, 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_TRUNCL],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11   dnl Persuade glibc <math.h> to declare truncl().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether truncl() is declared.
14   AC_CHECK_DECLS([truncl], , , [#include <math.h>])
15   if test "$ac_cv_have_decl_truncl" = yes; then
16     dnl Test whether truncl() can be used without libm.
17     TRUNCL_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            long double x;]],
25          [[x = truncl(x);]])],
26       [TRUNCL_LIBM=])
27     if test "$TRUNCL_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              long double x;]],
37            [[x = truncl(x);]])],
38         [TRUNCL_LIBM="-lm"])
39       LIBS="$save_LIBS"
40     fi
41     if test "$TRUNCL_LIBM" = "?"; then
42       TRUNCL_LIBM=
43     fi
44     dnl Test whether truncl() works. It crashes on OSF/1 4.0d.
45     save_LIBS="$LIBS"
46     LIBS="$LIBS $TRUNCL_LIBM"
47     AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works],
48       [
49         AC_RUN_IFELSE(
50           [AC_LANG_SOURCE([[
51 #include <math.h>
52 long double x;
53 int main()
54 {
55   x = truncl (0.0L);
56   return 0;
57 }]])],
58           [gl_cv_func_truncl_works=yes],
59           [gl_cv_func_truncl_works=no],
60           [case "$host_os" in
61              osf4*) gl_cv_func_truncl_works="guessing no";;
62              *)     gl_cv_func_truncl_works="guessing yes";;
63            esac
64           ])
65       ])
66     LIBS="$save_LIBS"
67     case "$gl_cv_func_truncl_works" in
68       *yes) ;;
69       *) REPLACE_TRUNCL=1 ;;
70     esac
71   else
72     HAVE_DECL_TRUNCL=0
73   fi
74   if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
75     AC_LIBOBJ([truncl])
76     TRUNCL_LIBM=
77   fi
78   AC_SUBST([TRUNCL_LIBM])
79 ])