floor: Respect rules for use of AC_LIBOBJ.
[gnulib.git] / m4 / floor.m4
1 # floor.m4 serial 6
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_FLOOR],
8 [
9   m4_divert_text([DEFAULTS], [gl_floor_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Test whether floor() can be used without libm.
12   gl_FUNC_FLOOR_LIBS
13   if test "$FLOOR_LIBM" = "?"; then
14     FLOOR_LIBM=
15   fi
16   m4_ifdef([gl_FUNC_FLOOR_IEEE], [
17     if test $gl_floor_required = ieee && test $REPLACE_FLOOR = 0; then
18       AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559],
19         [gl_cv_func_floor_ieee],
20         [
21           save_LIBS="$LIBS"
22           LIBS="$LIBS $FLOOR_LIBM"
23           AC_RUN_IFELSE(
24             [AC_LANG_SOURCE([[
25 #ifndef __NO_MATH_INLINES
26 # define __NO_MATH_INLINES 1 /* for glibc */
27 #endif
28 #include <math.h>
29 ]gl_DOUBLE_MINUS_ZERO_CODE[
30 ]gl_DOUBLE_SIGNBIT_CODE[
31 int main()
32 {
33   /* Test whether floor (-0.0) is -0.0.  */
34   if (signbitd (minus_zerod) && !signbitd (floor (minus_zerod)))
35     return 1;
36   return 0;
37 }
38             ]])],
39             [gl_cv_func_floor_ieee=yes],
40             [gl_cv_func_floor_ieee=no],
41             [gl_cv_func_floor_ieee="guessing no"])
42           LIBS="$save_LIBS"
43         ])
44       case "$gl_cv_func_floor_ieee" in
45         *yes) ;;
46         *) REPLACE_FLOOR=1 ;;
47       esac
48     fi
49   ])
50   if test $REPLACE_FLOOR = 1; then
51     dnl No libraries are needed to link lib/floor.c.
52     FLOOR_LIBM=
53   fi
54   AC_SUBST([FLOOR_LIBM])
55 ])
56
57 # Determines the libraries needed to get the floor() function.
58 # Sets FLOOR_LIBM.
59 AC_DEFUN([gl_FUNC_FLOOR_LIBS],
60 [
61   gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
62     gl_cv_func_floor_libm=?
63     AC_LINK_IFELSE(
64       [AC_LANG_PROGRAM(
65          [[#ifndef __NO_MATH_INLINES
66            # define __NO_MATH_INLINES 1 /* for glibc */
67            #endif
68            #include <math.h>
69            double x;]],
70          [[x = floor(x);]])],
71       [gl_cv_func_floor_libm=])
72     if test "$gl_cv_func_floor_libm" = "?"; then
73       save_LIBS="$LIBS"
74       LIBS="$LIBS -lm"
75       AC_LINK_IFELSE(
76         [AC_LANG_PROGRAM(
77            [[#ifndef __NO_MATH_INLINES
78              # define __NO_MATH_INLINES 1 /* for glibc */
79              #endif
80              #include <math.h>
81              double x;]],
82            [[x = floor(x);]])],
83         [gl_cv_func_floor_libm="-lm"])
84       LIBS="$save_LIBS"
85     fi
86   ])
87   FLOOR_LIBM="$gl_cv_func_floor_libm"
88 ])