From b4349b948ba2c352187158e241334abda6e473e9 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 20 Jan 2010 11:55:20 +0100
Subject: [PATCH] Avoid duplicate -lm.

---
 ChangeLog    | 17 +++++++++++++++++
 m4/acosl.m4  | 13 +++++++++++--
 m4/asinl.m4  |  8 ++++++--
 m4/atanl.m4  |  8 ++++++--
 m4/cosl.m4   | 18 ++++++++++++++++--
 m4/isnan.m4  | 19 +++++++++++++++++--
 m4/logl.m4   | 18 ++++++++++++++++--
 m4/round.m4  | 16 +++++++++++++---
 m4/roundf.m4 | 14 ++++++++++++--
 m4/roundl.m4 | 16 +++++++++++++---
 m4/sinl.m4   | 18 ++++++++++++++++--
 m4/sqrtl.m4  | 23 +++++++++++++++++++++--
 m4/tanl.m4   | 18 ++++++++++++++++--
 13 files changed, 180 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a5e0da60b9..444f5b6aa5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2010-01-20  Bruno Haible  <bruno@clisp.org>
+
+	Avoid duplicate -lm.
+	* m4/isnan.m4 (gl_ISNAN): Avoid duplicate -lm in $ISNAN_LIBM.
+	* m4/round.m4 (gl_FUNC_ROUND): Avoid duplicate -lm in $ROUND_LIBM.
+	* m4/roundf.m4 (gl_FUNC_ROUNDF): Avoid duplicate -lm in $ROUNDF_LIBM.
+	* m4/roundl.m4 (gl_FUNC_ROUNDL): Avoid duplicate -lm in $ROUNDL_LIBM.
+	* m4/acosl.m4 (gl_FUNC_ACOSL): Avoid duplicate -lm in $ACOSL_LIBM.
+	* m4/cosl.m4 (gl_FUNC_COSL): Avoid duplicate -lm in $COSL_LIBM.
+	* m4/logl.m4 (gl_FUNC_LOGL): Avoid duplicate -lm in $LOGL_LIBM.
+	* m4/sinl.m4 (gl_FUNC_SINL): Avoid duplicate -lm in $SINL_LIBM.
+	* m4/sqrtl.m4 (gl_FUNC_SQRTL): Avoid duplicate -lm in $SQRTL_LIBM.
+	* m4/tanl.m4 (gl_FUNC_TANL): Avoid duplicate -lm in $TANL_LIBM.
+	* m4/asinl.m4 (gl_FUNC_ASINL): Same change, for consistency.
+	* m4/atanl.m4 (gl_FUNC_ATANL): Likewise.
+	Reported by Paolo Bonzini.
+
 2010-01-19  Bruno Haible  <bruno@clisp.org>
 
 	langinfo, nl_langinfo: Relicense under LGPLv2+.
diff --git a/m4/acosl.m4 b/m4/acosl.m4
index 0e57df5b25..66cbd6cd9e 100644
--- a/m4/acosl.m4
+++ b/m4/acosl.m4
@@ -1,4 +1,4 @@
-# acosl.m4 serial 1
+# acosl.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,
@@ -54,7 +54,16 @@ AC_DEFUN([gl_FUNC_ACOSL],
     AC_LIBOBJ([acosl])
     AC_REQUIRE([gl_FUNC_ASINL])
     AC_REQUIRE([gl_FUNC_SQRTL])
-    ACOSL_LIBM="$ASINL_LIBM $SQRTL_LIBM"
+    dnl Append $ASINL_LIBM to ACOSL_LIBM, avoiding gratuitous duplicates.
+    case " $ACOSL_LIBM " in
+      *" $ASINL_LIBM "*) ;;
+      *) ACOSL_LIBM="$ACOSL_LIBM $ASINL_LIBM" ;;
+    esac
+    dnl Append $SQRTL_LIBM to ACOSL_LIBM, avoiding gratuitous duplicates.
+    case " $ACOSL_LIBM " in
+      *" $SQRTL_LIBM "*) ;;
+      *) ACOSL_LIBM="$ACOSL_LIBM $SQRTL_LIBM" ;;
+    esac
   fi
   AC_SUBST([ACOSL_LIBM])
 ])
diff --git a/m4/asinl.m4 b/m4/asinl.m4
index f2281a2327..1f5bc6df4a 100644
--- a/m4/asinl.m4
+++ b/m4/asinl.m4
@@ -1,4 +1,4 @@
-# asinl.m4 serial 1
+# asinl.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,
@@ -53,7 +53,11 @@ AC_DEFUN([gl_FUNC_ASINL],
     HAVE_ASINL=0
     AC_LIBOBJ([asinl])
     AC_REQUIRE([gl_FUNC_SQRTL])
-    ASINL_LIBM="$SQRTL_LIBM"
+    dnl Append $SQRTL_LIBM to ASINL_LIBM, avoiding gratuitous duplicates.
+    case " $ASINL_LIBM " in
+      *" $SQRTL_LIBM "*) ;;
+      *) ASINL_LIBM="$ASINL_LIBM $SQRTL_LIBM" ;;
+    esac
   fi
   AC_SUBST([ASINL_LIBM])
 ])
diff --git a/m4/atanl.m4 b/m4/atanl.m4
index 507f22b8ba..28cf7b3a81 100644
--- a/m4/atanl.m4
+++ b/m4/atanl.m4
@@ -1,4 +1,4 @@
-# atanl.m4 serial 1
+# atanl.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,
@@ -53,7 +53,11 @@ AC_DEFUN([gl_FUNC_ATANL],
     HAVE_ATANL=0
     AC_LIBOBJ([atanl])
     AC_REQUIRE([gl_FUNC_ISNANL])
-    ATANL_LIBM="$ISNANL_LIBM"
+    dnl Append $ISNANL_LIBM to ATANL_LIBM, avoiding gratuitous duplicates.
+    case " $ATANL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) ATANL_LIBM="$ATANL_LIBM $ISNANL_LIBM" ;;
+    esac
   fi
   AC_SUBST([ATANL_LIBM])
 ])
diff --git a/m4/cosl.m4 b/m4/cosl.m4
index 460d0f0024..74c9e7c6d5 100644
--- a/m4/cosl.m4
+++ b/m4/cosl.m4
@@ -1,4 +1,4 @@
-# cosl.m4 serial 1
+# cosl.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,
@@ -57,7 +57,21 @@ AC_DEFUN([gl_FUNC_COSL],
     AC_REQUIRE([gl_FUNC_ISNANL])
     AC_REQUIRE([gl_FUNC_FLOOR])
     AC_REQUIRE([gl_FUNC_FLOORL])
-    COSL_LIBM="$ISNANL_LIBM $FLOOR_LIBM $FLOORL_LIBM"
+    dnl Append $ISNANL_LIBM to COSL_LIBM, avoiding gratuitous duplicates.
+    case " $COSL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) COSL_LIBM="$COSL_LIBM $ISNANL_LIBM" ;;
+    esac
+    dnl Append $FLOOR_LIBM to COSL_LIBM, avoiding gratuitous duplicates.
+    case " $COSL_LIBM " in
+      *" $FLOOR_LIBM "*) ;;
+      *) COSL_LIBM="$COSL_LIBM $FLOOR_LIBM" ;;
+    esac
+    dnl Append $FLOORL_LIBM to COSL_LIBM, avoiding gratuitous duplicates.
+    case " $COSL_LIBM " in
+      *" $FLOORL_LIBM "*) ;;
+      *) COSL_LIBM="$COSL_LIBM $FLOORL_LIBM" ;;
+    esac
   fi
   AC_SUBST([COSL_LIBM])
 ])
diff --git a/m4/isnan.m4 b/m4/isnan.m4
index 848c2f9b92..eb61d56678 100644
--- a/m4/isnan.m4
+++ b/m4/isnan.m4
@@ -1,4 +1,4 @@
-# isnan.m4 serial 2
+# isnan.m4 serial 3
 dnl Copyright (C) 2007-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,
@@ -18,7 +18,22 @@ AC_DEFUN([gl_ISNAN],
      && test $gl_func_isnand = yes \
      && test $gl_func_isnanl = yes; then
     AC_MSG_RESULT([yes])
-    ISNAN_LIBM="$ISNANF_LIBM $ISNAND_LIBM $ISNANL_LIBM"
+    ISNAN_LIBM=
+    dnl Append $ISNANF_LIBM to ISNAN_LIBM, avoiding gratuitous duplicates.
+    case " $ISNAN_LIBM " in
+      *" $ISNANF_LIBM "*) ;;
+      *) ISNAN_LIBM="$ISNAN_LIBM $ISNANF_LIBM" ;;
+    esac
+    dnl Append $ISNAND_LIBM to ISNAN_LIBM, avoiding gratuitous duplicates.
+    case " $ISNAN_LIBM " in
+      *" $ISNAND_LIBM "*) ;;
+      *) ISNAN_LIBM="$ISNAN_LIBM $ISNAND_LIBM" ;;
+    esac
+    dnl Append $ISNANL_LIBM to ISNAN_LIBM, avoiding gratuitous duplicates.
+    case " $ISNAN_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) ISNAN_LIBM="$ISNAN_LIBM $ISNANL_LIBM" ;;
+    esac
   else
     AC_MSG_RESULT([no])
     REPLACE_ISNAN=1
diff --git a/m4/logl.m4 b/m4/logl.m4
index 196dcbdaa1..eab591e2e3 100644
--- a/m4/logl.m4
+++ b/m4/logl.m4
@@ -1,4 +1,4 @@
-# logl.m4 serial 1
+# logl.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,
@@ -55,7 +55,21 @@ AC_DEFUN([gl_FUNC_LOGL],
     AC_REQUIRE([gl_FUNC_FREXPL])
     AC_REQUIRE([gl_FUNC_ISNANL])
     AC_REQUIRE([gl_FUNC_FLOORL])
-    LOGL_LIBM="$FREXPL_LIBM $ISNANL_LIBM $FLOORL_LIBM"
+    dnl Append $FREXPL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates.
+    case " $LOGL_LIBM " in
+      *" $FREXPL_LIBM "*) ;;
+      *) LOGL_LIBM="$LOGL_LIBM $FREXPL_LIBM" ;;
+    esac
+    dnl Append $ISNANL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates.
+    case " $LOGL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) LOGL_LIBM="$LOGL_LIBM $ISNANL_LIBM" ;;
+    esac
+    dnl Append $FLOORL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates.
+    case " $LOGL_LIBM " in
+      *" $FLOORL_LIBM "*) ;;
+      *) LOGL_LIBM="$LOGL_LIBM $FLOORL_LIBM" ;;
+    esac
   fi
   AC_SUBST([LOGL_LIBM])
 ])
diff --git a/m4/round.m4 b/m4/round.m4
index 2e13b44570..8860e0151b 100644
--- a/m4/round.m4
+++ b/m4/round.m4
@@ -1,5 +1,5 @@
-# round.m4 serial 6
-dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+# round.m4 serial 7
+dnl Copyright (C) 2007, 2009-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.
@@ -56,7 +56,17 @@ int main()
     AC_LIBOBJ([round])
     gl_FUNC_FLOOR_LIBS
     gl_FUNC_CEIL_LIBS
-    ROUND_LIBM="$FLOOR_LIBM $CEIL_LIBM"
+    ROUND_LIBM=
+    dnl Append $FLOOR_LIBM to ROUND_LIBM, avoiding gratuitous duplicates.
+    case " $ROUND_LIBM " in
+      *" $FLOOR_LIBM "*) ;;
+      *) ROUND_LIBM="$ROUND_LIBM $FLOOR_LIBM" ;;
+    esac
+    dnl Append $CEIL_LIBM to ROUND_LIBM, avoiding gratuitous duplicates.
+    case " $ROUND_LIBM " in
+      *" $CEIL_LIBM "*) ;;
+      *) ROUND_LIBM="$ROUND_LIBM $CEIL_LIBM" ;;
+    esac
   fi
   AC_SUBST([ROUND_LIBM])
 ])
diff --git a/m4/roundf.m4 b/m4/roundf.m4
index 6614241e74..b246d0432d 100644
--- a/m4/roundf.m4
+++ b/m4/roundf.m4
@@ -1,4 +1,4 @@
-# roundf.m4 serial 7
+# roundf.m4 serial 8
 dnl Copyright (C) 2007-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,
@@ -59,7 +59,17 @@ int main()
       if test "$FLOORF_LIBM" != '?' && test "$CEILF_LIBM" != '?'; then
         AC_DEFINE([HAVE_FLOORF_AND_CEILF], [1],
           [Define if the both the floorf() and ceilf() functions exist.])
-        ROUNDF_LIBM="$FLOORF_LIBM $CEILF_LIBM"
+        ROUNDF_LIBM=
+        dnl Append $FLOORF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
+        case " $ROUNDF_LIBM " in
+          *" $FLOORF_LIBM "*) ;;
+          *) ROUNDF_LIBM="$ROUNDF_LIBM $FLOORF_LIBM" ;;
+        esac
+        dnl Append $CEILF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
+        case " $ROUNDF_LIBM " in
+          *" $CEILF_LIBM "*) ;;
+          *) ROUNDF_LIBM="$ROUNDF_LIBM $CEILF_LIBM" ;;
+        esac
       else
         ROUNDF_LIBM=
       fi
diff --git a/m4/roundl.m4 b/m4/roundl.m4
index 66bdd00907..3011c37846 100644
--- a/m4/roundl.m4
+++ b/m4/roundl.m4
@@ -1,5 +1,5 @@
-# roundl.m4 serial 5
-dnl Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+# roundl.m4 serial 6
+dnl Copyright (C) 2007, 2009-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.
@@ -24,7 +24,17 @@ AC_DEFUN([gl_FUNC_ROUNDL],
       if test "$FLOORL_LIBM" != '?' && test "$CEILL_LIBM" != '?'; then
         AC_DEFINE([HAVE_FLOORL_AND_CEILL], [1],
           [Define if the both the floorl() and ceill() functions exist.])
-        ROUNDL_LIBM="$FLOORL_LIBM $CEILL_LIBM"
+        ROUNDL_LIBM=
+        dnl Append $FLOORL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
+        case " $ROUNDL_LIBM " in
+          *" $FLOORL_LIBM "*) ;;
+          *) ROUNDL_LIBM="$ROUNDL_LIBM $FLOORL_LIBM" ;;
+        esac
+        dnl Append $CEILL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
+        case " $ROUNDL_LIBM " in
+          *" $CEILL_LIBM "*) ;;
+          *) ROUNDL_LIBM="$ROUNDL_LIBM $CEILL_LIBM" ;;
+        esac
       else
         ROUNDL_LIBM=
       fi
diff --git a/m4/sinl.m4 b/m4/sinl.m4
index 12393264b6..c9c0e5c48e 100644
--- a/m4/sinl.m4
+++ b/m4/sinl.m4
@@ -1,4 +1,4 @@
-# sinl.m4 serial 1
+# sinl.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,
@@ -57,7 +57,21 @@ AC_DEFUN([gl_FUNC_SINL],
     AC_REQUIRE([gl_FUNC_ISNANL])
     AC_REQUIRE([gl_FUNC_FLOOR])
     AC_REQUIRE([gl_FUNC_FLOORL])
-    SINL_LIBM="$ISNANL_LIBM $FLOOR_LIBM $FLOORL_LIBM"
+    dnl Append $ISNANL_LIBM to SINL_LIBM, avoiding gratuitous duplicates.
+    case " $SINL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) SINL_LIBM="$SINL_LIBM $ISNANL_LIBM" ;;
+    esac
+    dnl Append $FLOOR_LIBM to SINL_LIBM, avoiding gratuitous duplicates.
+    case " $SINL_LIBM " in
+      *" $FLOOR_LIBM "*) ;;
+      *) SINL_LIBM="$SINL_LIBM $FLOOR_LIBM" ;;
+    esac
+    dnl Append $FLOORL_LIBM to SINL_LIBM, avoiding gratuitous duplicates.
+    case " $SINL_LIBM " in
+      *" $FLOORL_LIBM "*) ;;
+      *) SINL_LIBM="$SINL_LIBM $FLOORL_LIBM" ;;
+    esac
   fi
   AC_SUBST([SINL_LIBM])
 ])
diff --git a/m4/sqrtl.m4 b/m4/sqrtl.m4
index 7a29f9ad4f..21b1c6835d 100644
--- a/m4/sqrtl.m4
+++ b/m4/sqrtl.m4
@@ -1,4 +1,4 @@
-# sqrtl.m4 serial 1
+# sqrtl.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,
@@ -56,7 +56,26 @@ AC_DEFUN([gl_FUNC_SQRTL],
     AC_REQUIRE([gl_FUNC_FREXPL])
     AC_REQUIRE([gl_FUNC_LDEXPL])
     AC_REQUIRE([gl_FUNC_SQRT])
-    SQRTL_LIBM="$ISNANL_LIBM $FREXPL_LIBM $LDEXPL_LIBM $SQRT_LIBM"
+    dnl Append $ISNANL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates.
+    case " $SQRTL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) SQRTL_LIBM="$SQRTL_LIBM $ISNANL_LIBM" ;;
+    esac
+    dnl Append $FREXPL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates.
+    case " $SQRTL_LIBM " in
+      *" $FREXPL_LIBM "*) ;;
+      *) SQRTL_LIBM="$SQRTL_LIBM $FREXPL_LIBM" ;;
+    esac
+    dnl Append $LDEXPL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates.
+    case " $SQRTL_LIBM " in
+      *" $LDEXPL_LIBM "*) ;;
+      *) SQRTL_LIBM="$SQRTL_LIBM $LDEXPL_LIBM" ;;
+    esac
+    dnl Append $SQRT_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates.
+    case " $SQRTL_LIBM " in
+      *" $SQRT_LIBM "*) ;;
+      *) SQRTL_LIBM="$SQRTL_LIBM $SQRT_LIBM" ;;
+    esac
   fi
   AC_SUBST([SQRTL_LIBM])
 ])
diff --git a/m4/tanl.m4 b/m4/tanl.m4
index 8f4ee101ab..0e785057fd 100644
--- a/m4/tanl.m4
+++ b/m4/tanl.m4
@@ -1,4 +1,4 @@
-# tanl.m4 serial 1
+# tanl.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,
@@ -56,7 +56,21 @@ AC_DEFUN([gl_FUNC_TANL],
     AC_REQUIRE([gl_FUNC_ISNANL])
     AC_REQUIRE([gl_FUNC_FLOOR])
     AC_REQUIRE([gl_FUNC_FLOORL])
-    TANL_LIBM="$ISNANL_LIBM $FLOOR_LIBM $FLOORL_LIBM"
+    dnl Append $ISNANL_LIBM to TANL_LIBM, avoiding gratuitous duplicates.
+    case " $TANL_LIBM " in
+      *" $ISNANL_LIBM "*) ;;
+      *) TANL_LIBM="$TANL_LIBM $ISNANL_LIBM" ;;
+    esac
+    dnl Append $FLOOR_LIBM to TANL_LIBM, avoiding gratuitous duplicates.
+    case " $TANL_LIBM " in
+      *" $FLOOR_LIBM "*) ;;
+      *) TANL_LIBM="$TANL_LIBM $FLOOR_LIBM" ;;
+    esac
+    dnl Append $FLOORL_LIBM to TANL_LIBM, avoiding gratuitous duplicates.
+    case " $TANL_LIBM " in
+      *" $FLOORL_LIBM "*) ;;
+      *) TANL_LIBM="$TANL_LIBM $FLOORL_LIBM" ;;
+    esac
   fi
   AC_SUBST([TANL_LIBM])
 ])
-- 
2.30.2