Merge branch 'stable'
[gnulib.git] / m4 / floorl.m4
1 # floorl.m4 serial 7
2 dnl Copyright (C) 2007, 2009-2011 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_FLOORL],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   dnl Persuade glibc <math.h> to declare floorl().
11   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
12   dnl Test whether floorl() is declared.
13   AC_CHECK_DECLS([floorl], , , [#include <math.h>])
14   if test "$ac_cv_have_decl_floorl" = yes; then
15     dnl Test whether floorl() can be used without libm.
16     gl_FUNC_FLOORL_LIBS
17     if test "$FLOORL_LIBM" = "?"; then
18       dnl Sun C 5.0 on Solaris declares floorl() and has it in the system-wide
19       dnl libm.so, but not in the libm.so that the compiler uses.
20       REPLACE_FLOORL=1
21     fi
22   else
23     HAVE_DECL_FLOORL=0
24   fi
25   if test $HAVE_DECL_FLOORL = 0 || test $REPLACE_FLOORL = 1; then
26     AC_LIBOBJ([floorl])
27     FLOORL_LIBM=
28   fi
29   AC_SUBST([FLOORL_LIBM])
30 ])
31
32 # Determines the libraries needed to get the floorl() function.
33 # Sets FLOORL_LIBM.
34 AC_DEFUN([gl_FUNC_FLOORL_LIBS],
35 [
36   gl_CACHE_VAL_SILENT([gl_cv_func_floorl_libm], [
37     gl_cv_func_floorl_libm=?
38     AC_LINK_IFELSE(
39       [AC_LANG_PROGRAM(
40          [[#ifndef __NO_MATH_INLINES
41            # define __NO_MATH_INLINES 1 /* for glibc */
42            #endif
43            #include <math.h>
44            long double x;]],
45          [[x = floorl(x);]])],
46       [gl_cv_func_floorl_libm=])
47     if test "$gl_cv_func_floorl_libm" = "?"; then
48       save_LIBS="$LIBS"
49       LIBS="$LIBS -lm"
50       AC_LINK_IFELSE(
51         [AC_LANG_PROGRAM(
52            [[#ifndef __NO_MATH_INLINES
53              # define __NO_MATH_INLINES 1 /* for glibc */
54              #endif
55              #include <math.h>
56              long double x;]],
57            [[x = floorl(x);]])],
58         [gl_cv_func_floorl_libm="-lm"])
59       LIBS="$save_LIBS"
60     fi
61   ])
62   FLOORL_LIBM="$gl_cv_func_floorl_libm"
63 ])