havelib: Add static libraries to LIBS in the right order.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Apr 2010 16:06:48 +0000 (18:06 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Apr 2010 16:06:48 +0000 (18:06 +0200)
ChangeLog
m4/lib-link.m4

index 58d16d2accd8ac95087563e54595d191e7e5d722..ae381cb4f6277b3974801db405d0157c7fb2bb81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-04-11  Bruno Haible  <bruno@clisp.org>
+
+       havelib: Add static libraries to LIBS in the right order.
+       * m4/lib-link.m4 (AC_LIB_HAVE_LINKFLAGS): When $LIB[]NAME contains no
+       -l options, prepend it to $LIBS, instead of appending it to $LIBS.
+
 2010-04-11  Bruno Haible  <bruno@clisp.org>
 
        libunistring: Detect libunistring also when it depends on libiconv.
 2010-04-11  Bruno Haible  <bruno@clisp.org>
 
        libunistring: Detect libunistring also when it depends on libiconv.
index 90e1ac9170d3418035f0c6a299d16ae8aadcebee..c73bd8e3a478ce61292aaa298d42aad15c9d348a 100644 (file)
@@ -1,4 +1,4 @@
-# lib-link.m4 serial 20 (gettext-0.18)
+# lib-link.m4 serial 21 (gettext-0.18)
 dnl Copyright (C) 2001-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 Copyright (C) 2001-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,
@@ -74,7 +74,17 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
 
   AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
     ac_save_LIBS="$LIBS"
 
   AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
     ac_save_LIBS="$LIBS"
-    LIBS="$LIBS $LIB[]NAME"
+    dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS,
+    dnl because these -l options might require -L options that are present in
+    dnl LIBS. -l options benefit only from the -L options listed before it.
+    dnl Otherwise, add it to the front of LIBS, because it may be a static
+    dnl library that depends on another static library that is present in LIBS.
+    dnl Static libraries benefit only from the static libraries listed after
+    dnl it.
+    case " $LIB[]NAME" in
+      *" -l"*) LIBS="$LIBS $LIB[]NAME" ;;
+      *)       LIBS="$LIB[]NAME $LIBS" ;;
+    esac
     AC_TRY_LINK([$3], [$4],
       [ac_cv_lib[]Name=yes],
       [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])
     AC_TRY_LINK([$3], [$4],
       [ac_cv_lib[]Name=yes],
       [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])'])