Allow wcwidth to return -1 in some more cases. Fixes test failure on Solaris 10.
[gnulib.git] / m4 / check-libm-func.m4
1 # check-libm.m4 serial 1
2 dnl Copyright (C) 2007 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 dnl 
7 dnl AC_CHECK_LIBM_FUNC (MATH_FUNCTION, INVOCATION, 
8 dnl                     [RUN-IF-FOUND], [RUN-IF-NOT-FOUND])
9 dnl
10 dnl Checks for a declaration of the given MATH_FUNCTION in <math.h>, and
11 dnl substitutes HAVE_DECL_<func> accordingly.  If a declaration is found,
12 dnl determines the needed library (if any), assigns it to <func>_LIBM, and
13 dnl executes RUN-IF-FOUND; otherwise, executes RUN-IF-NOT-FOUND.
14 dnl 
15 dnl INVOCATION should be a C statement that invokes MATH_FUNCTION, both
16 dnl using and assigning back to double variable 'x', e.g. "x = floor
17 dnl (x);".
18 AC_DEFUN([gl_CHECK_LIBM_FUNC],
19 [
20 m4_pushdef([FUNC_LIBM], m4_toupper([$1])[_LIBM])dnl
21 m4_pushdef([HAVE_DECL_FUNC], HAVE_DECL_[]m4_toupper([$1]))dnl
22   AC_CHECK_DECLS([$1], , , [#include <math.h>])
23   if test "$ac_cv_have_decl_$1" = yes; then
24     save_LIBS=$LIBS
25     FUNC_LIBM=?
26     for libm in "" "-lm"; do
27       LIBS="$save_LIBS $libm"
28       AC_TRY_LINK([
29          #ifndef __NO_MATH_INLINES
30          # define __NO_MATH_INLINES 1 /* for glibc */
31          #endif
32          #include <math.h>
33          double x;],
34         [$2],
35         [FUNC_LIBM=$libm
36 break])
37     done
38     LIBS=$save_LIBS
39     if test "$FUNC_LIBM" = "?"; then
40       FUNC_LIBM=
41     fi
42 m4_ifvaln([$3], [$3])dnl
43   else
44     HAVE_DECL_FUNC=
45     FUNC_LIBM=
46 m4_ifvaln([$4], [$4])dnl
47   fi
48   AC_SUBST(HAVE_DECL_FUNC)
49   AC_SUBST(FUNC_LIBM)
50 m4_popdef([FUNC_LIBM])
51 m4_popdef([HAVE_DECL_FUNC])])