truncl: Fix autoconf test.
[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_TRY_LINK([
19        #ifndef __NO_MATH_INLINES
20        # define __NO_MATH_INLINES 1 /* for glibc */
21        #endif
22        #include <math.h>
23        long double x;],
24       [x = truncl(x);],
25       [TRUNCL_LIBM=])
26     if test "$TRUNCL_LIBM" = "?"; then
27       save_LIBS="$LIBS"
28       LIBS="$LIBS -lm"
29       AC_TRY_LINK([
30          #ifndef __NO_MATH_INLINES
31          # define __NO_MATH_INLINES 1 /* for glibc */
32          #endif
33          #include <math.h>
34          long double x;],
35         [x = truncl(x);],
36         [TRUNCL_LIBM="-lm"])
37       LIBS="$save_LIBS"
38     fi
39     if test "$TRUNCL_LIBM" = "?"; then
40       TRUNCL_LIBM=
41     fi
42     dnl Test whether truncl() works. It crashes on OSF/1 4.0d.
43     save_LIBS="$LIBS"
44     LIBS="$LIBS $TRUNCL_LIBM"
45     AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works],
46       [
47         AC_TRY_RUN([
48 #include <math.h>
49 long double x;
50 int main()
51 {
52   x = truncl (0.0L);
53   return 0;
54 }], [gl_cv_func_truncl_works=yes], [gl_cv_func_truncl_works=no],
55           [case "$host_os" in
56              osf4*) gl_cv_func_truncl_works="guessing no";;
57              *)     gl_cv_func_truncl_works="guessing yes";;
58            esac
59           ])
60       ])
61     LIBS="$save_LIBS"
62     case "$gl_cv_func_truncl_works" in
63       *yes) ;;
64       *) REPLACE_TRUNCL=1 ;;
65     esac
66   else
67     HAVE_DECL_TRUNCL=0
68   fi
69   if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
70     AC_LIBOBJ([truncl])
71     TRUNCL_LIBM=
72   fi
73   AC_SUBST([TRUNCL_LIBM])
74 ])