summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-01-25 01:57:08 +0100
committerBruno Haible <bruno@clisp.org>2010-01-25 01:57:08 +0100
commit71c045ff3f67af2324da06ac4b676805590ed316 (patch)
tree313348a6d86addb5a5f9cb22c8d2eea79a9e0d89 /m4
parent494a4d32e2e9ed6201c38ff3fa28ed38c5396644 (diff)
downloadgnulib-71c045ff3f67af2324da06ac4b676805590ed316.tar.gz
Fix tests for common <math.h> functions.
Diffstat (limited to 'm4')
-rw-r--r--m4/mathfunc.m423
-rw-r--r--m4/sqrt.m44
2 files changed, 17 insertions, 10 deletions
diff --git a/m4/mathfunc.m4 b/m4/mathfunc.m4
index 8d9d826f20..5e79d4581a 100644
--- a/m4/mathfunc.m4
+++ b/m4/mathfunc.m4
@@ -1,15 +1,21 @@
-# mathfunc.m4 serial 1
+# mathfunc.m4 serial 2
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
-# gl_MATHFUNC([sqrt])
-# tests whether the sqrt function is available in libc or libm. It sets
-# SQRT_LIBM to empty or "-lm" accordingly.
+# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES)
+# --------------------------------------------------
+# tests whether the function FUNC is available in libc or libm.
+# RETTYPE is the return type. PARAMTYPES is a parameter list, with parentheses.
+# It sets FUNC_LIBM to empty or "-lm" accordingly.
AC_DEFUN([gl_MATHFUNC],
[
+ dnl We need the RETTYPE and PARAMTYPES in order to force linking with the
+ dnl function. With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function
+ dnl are inlined by the compiler, therefore linking of these calls does not
+ dnl require -lm, but taking the function pointer of 'fabs' does.
m4_pushdef([func], [$1])
m4_pushdef([FUNC], [translit([$1],[abcdefghijklmnopqrstuvwxyz],
[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
@@ -22,8 +28,8 @@ AC_DEFUN([gl_MATHFUNC],
# define __NO_MATH_INLINES 1 /* for glibc */
#endif
#include <math.h>
- double x;]],
- [[return ]func[ (x) > 2 || ]func[ (x) < 0.4;]])],
+ $2 (*funcptr) $3 = ]func[;]],
+ [[return 0;]])],
[gl_cv_func_]func[_no_libm=yes],
[gl_cv_func_]func[_no_libm=no])
])
@@ -38,8 +44,8 @@ AC_DEFUN([gl_MATHFUNC],
# define __NO_MATH_INLINES 1 /* for glibc */
#endif
#include <math.h>
- double x;]],
- [[return ]func[ (x) > 2 || ]func[ (x) < 0.4;]])],
+ $2 (*funcptr) $3 = ]func[;]],
+ [[return 0;]])],
[gl_cv_func_]func[_in_libm=yes],
[gl_cv_func_]func[_in_libm=no])
LIBS="$save_LIBS"
@@ -48,6 +54,7 @@ AC_DEFUN([gl_MATHFUNC],
FUNC[]_LIBM=-lm
fi
fi
+ AC_SUBST(FUNC[_LIBM])
m4_popdef([FUNC])
m4_popdef([func])
])
diff --git a/m4/sqrt.m4 b/m4/sqrt.m4
index 947389a927..d87648cc9f 100644
--- a/m4/sqrt.m4
+++ b/m4/sqrt.m4
@@ -1,4 +1,4 @@
-# sqrt.m4 serial 1
+# sqrt.m4 serial 2
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -6,5 +6,5 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_SQRT],
[
- gl_MATHFUNC([sqrt])
+ gl_MATHFUNC([sqrt], [double], [(double)])
])