Modernize AC_TRY_LINK invocations.
[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_TRY_RUN([
50 #include <math.h>
51 long double x;
52 int main()
53 {
54   x = truncl (0.0L);
55   return 0;
56 }], [gl_cv_func_truncl_works=yes], [gl_cv_func_truncl_works=no],
57           [case "$host_os" in
58              osf4*) gl_cv_func_truncl_works="guessing no";;
59              *)     gl_cv_func_truncl_works="guessing yes";;
60            esac
61           ])
62       ])
63     LIBS="$save_LIBS"
64     case "$gl_cv_func_truncl_works" in
65       *yes) ;;
66       *) REPLACE_TRUNCL=1 ;;
67     esac
68   else
69     HAVE_DECL_TRUNCL=0
70   fi
71   if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then
72     AC_LIBOBJ([truncl])
73     TRUNCL_LIBM=
74   fi
75   AC_SUBST([TRUNCL_LIBM])
76 ])