Subject: broken handling of spaces after -{L,R,l}

From: Michael <[email-masked]>
Date: Thu, 3 Mar 2016 09:40:39 +0100

Hi,

in m4/libtool.m4, the handling of spaces after -{L,R,l} for parsing
linker commands looks as follows:

  case $prev$p in
    -L* | -R* | -l*)
      # Some compilers place space between "-{L,R}" and the path.
      # Remove the space.
      if test x-L = "$p" ||
         test x-R = "$p"; then
         prev=$p
         continue
      fi

This seems to be broken for two reasons:
1. The case handling captures -l, but the following tests consider only
-L and -R.
2. The tests for equality use an x on the left side, but not on the
right side.

A working code should look as follows (patch is attached):

  case $prev$p in
    -L* | -R* | -l*)
      # Some compilers place space between "-{L,R,l}" and the path.
      # Remove the space.
      if test x-L = "x$p" ||
         test x-R = "x$p" ||
         test x-l = "x$p"; then
         prev=$p
         continue
      fi

I stumbled across this bug when using gfortran (5.3.1) which emits the
following (valid) line:

  Driving: gfortran -v conftest.o -l gfortran -l m -shared-libgcc

The current (broken) libtool leads to "-l -l" in the "postdeps_FC"
variable. After the fix, the correct "-lgfortran -lm" appears.

Best regards,
Michael
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index ee292af..8349119 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -7557,10 +7557,11 @@ if AC_TRY_EVAL(ac_compile); then
     case $prev$p in
 
     -L* | -R* | -l*)
-       # Some compilers place space between "-{L,R}" and the path.
+       # Some compilers place space between "-{L,R,l}" and the path.
        # Remove the space.
-       if test x-L = "$p" ||
-          test x-R = "$p"; then
+       if test x-L = "x$p" ||
+          test x-R = "x$p" ||
+          test x-l = "x$p"; then
 	 prev=$p
 	 continue
        fi