Subject: bug#12304: libtool parse of nagfor -Wl,-Wl,, gives incorrect result

From: Thomas Jahns <[email-masked]>
Date: Thu, 30 Aug 2012 12:32:09 +0200

Hello,

On 08/29/2012 01:56 PM, Thomas Jahns wrote:
> I'm not sure of the best way to address this unfortunate coincidence of compiler
> and libtool flags. My, perhaps naïve, idea would be to test whether an argument
> starting with -Wl, also matches $wl and, in case $wl does not equal "-Wl," pass
> the flag argument on to the linker unaltered.

I've now prepared a patch vs. the repository state that seems to work for me[1].

Regards, Thomas

[1] Tested with
- gfortran/gcc on Debian GNU/Linux 6.0.5 i386/x86_64
- nagfor/gcc on Debian GNU/Linux 6.0.5 i386/x86_64
- ifort/icc on Debian GNU/Linux 6.0.5 i386/x86_64
- xlf/xlc on AIX 6.1 Power6

P.S.: I'll try CentOS 5.6 Linux x86_64 with ifort/icc and nagfor/gcc and
gfortran/gcc next but can't say when I'll get around to that because I'll need
to fix an unrelated bug with mpxlf on AIX first.
-- 
Thomas Jahns
DKRZ GmbH, Department: Application software

Deutsches Klimarechenzentrum
Bundesstraße 45a
D-20146 Hamburg

Phone: +49-40-460094-151
Fax: +49-40-460094-270
Email: Thomas Jahns <[email-masked]>
From a5e3abd897e4e682aa72786a92435f7a5d95ea6f Mon Sep 17 00:00:00 2001
From: Thomas Jahns <[email-masked]>
Date: Thu, 30 Aug 2012 12:26:50 +0200
Subject: [PATCH] Fix handling of -Wl,-Wl,, argument prefix of NAG fortran
 compiler.

---
 build-aux/ltmain.m4sh |   32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/build-aux/ltmain.m4sh b/build-aux/ltmain.m4sh
index 1d71f0e..910094b 100644
--- a/build-aux/ltmain.m4sh
+++ b/build-aux/ltmain.m4sh
@@ -5041,20 +5041,26 @@ func_mode_link ()
 	;;
 
       -Wl,*)
-	func_stripname '-Wl,' '' "$arg"
-	args=$func_stripname_result
-	arg=
-	save_ifs=$IFS; IFS=,
-	for flag in $args; do
+        wlprefix=`expr length "$wl"`
+        wlprefix=`expr substr "$arg" 1 $wlprefix`
+        if test x"$wlprefix" = x"$wl" -a x"$wl" != x"-Wl," ; then
+          :
+        else
+	  func_stripname '-Wl,' '' "$arg"
+	  args=$func_stripname_result
+	  arg=
+	  save_ifs=$IFS; IFS=,
+	  for flag in $args; do
+	    IFS=$save_ifs
+            func_quote_for_eval "$flag"
+	    func_append arg " $wl$func_quote_for_eval_result"
+	    func_append compiler_flags " $wl$func_quote_for_eval_result"
+	    func_append linker_flags " $func_quote_for_eval_result"
+	  done
 	  IFS=$save_ifs
-          func_quote_for_eval "$flag"
-	  func_append arg " $wl$func_quote_for_eval_result"
-	  func_append compiler_flags " $wl$func_quote_for_eval_result"
-	  func_append linker_flags " $func_quote_for_eval_result"
-	done
-	IFS=$save_ifs
-	func_stripname ' ' '' "$arg"
-	arg=$func_stripname_result
+	  func_stripname ' ' '' "$arg"
+	  arg=$func_stripname_result
+        fi
 	;;
 
       -Xcompiler)
-- 
1.7.10