automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] scripts: support -I <dir> -L <dir> and -l <lib> for cl in compil


From: Peter Rosin
Subject: [PATCH] scripts: support -I <dir> -L <dir> and -l <lib> for cl in compile
Date: Mon, 5 Mar 2012 14:25:25 +0100

POSIX mandates that the compiler accepts a space between the -I,
-l and -L options and their respective arguments.

* lib/compile (func_cl_dashl): New function with factored out code
for implementing the -l option for the cl wrapper.
(func_cl_dashL): New function with factored out code implementing
the -L option for the cl wrapper.
(func_cl_wrapper): Use func_cl_dashl to implement both -l <lib>
and -l<lib>, and func_cl_dashL to implement both -L <dir> and
-L<dir>.  Also add support for -I <dir>.
(scriptversion): Update.
* tests/compile4.test: Prefer -L <dir> over -L<dir>.
* tests/compile5.test: Likewise.
* tests/compile6.test: Likewise.
* tests/compile3.test: Likewise.  Also add checks for the new
-I <dir> and -l <lib> formats while keeping a check for the no
longer preferred -L<dir> format.
* NEWS: Update.
---
 NEWS                |    4 ++
 lib/compile         |   91 ++++++++++++++++++++++++++++++++++----------------
 tests/compile3.test |   12 +++---
 tests/compile4.test |    2 +-
 tests/compile5.test |    2 +-
 tests/compile6.test |   14 ++++----
 6 files changed, 81 insertions(+), 44 deletions(-)

Hi!

I noticed that some expect the compiler to accept a space between
the option letter and the option argument.  Looking at POSIX, this
seems like an acceptable expectation, if not even preferred.  So,
here's an update for the compile script when used to wrap MSVC.  I
didn't update the testsuite to prefer -l <lib> (with a space) since
I haven't seen that in practice anywhere.

Ok for msvc and merges into master/branch-1.11?

Cheers,
Peter

diff --git a/NEWS b/NEWS
index 442b303..f4b2465 100644
--- a/NEWS
+++ b/NEWS
@@ -115,6 +115,10 @@ New in 1.11.0a:
     action is now a synonym for "r" (replace).  Also, the script has been
     ignoring the "v" (verbose) modifier already since Automake 1.11.3.
 
+  - When the 'compile' script is used to wrap MSVC, it now accepts an
+    optional space between the -I, -L and -l options and their respective
+    arguments, for better POSIX compiliance.
+
 Bugs fixed in 1.11.0a:
 
 * Bugs introduced by 1.11.2:
diff --git a/lib/compile b/lib/compile
index b1f4749..862a14e 100755
--- a/lib/compile
+++ b/lib/compile
@@ -1,7 +1,7 @@
 #! /bin/sh
 # Wrapper for compilers which do not understand '-c -o'.
 
-scriptversion=2012-01-04.17; # UTC
+scriptversion=2012-03-05.13; # UTC
 
 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
 # Software Foundation, Inc.
@@ -79,6 +79,48 @@ func_file_conv ()
   esac
 }
 
+# func_cl_dashL linkdir
+# Make cl look for libraries in LINKDIR
+func_cl_dashL ()
+{
+  func_file_conv "$1"
+  if test -z "$lib_path"; then
+    lib_path=$file
+  else
+    lib_path="$lib_path;$file"
+  fi
+  linker_opts="$linker_opts -LIBPATH:$file"
+}
+
+# func_cl_dashl library
+# Do a library search-path lookup for cl
+func_cl_dashl ()
+{
+  lib=$1
+  found=no
+  save_IFS=$IFS
+  IFS=';'
+  for dir in $lib_path $LIB
+  do
+    IFS=$save_IFS
+    if $shared && test -f "$dir/$lib.dll.lib"; then
+      found=yes
+      lib=$dir/$lib.dll.lib
+      break
+    fi
+    if test -f "$dir/$lib.lib"; then
+      found=yes
+      lib=$dir/$lib.lib
+      break
+    fi
+  done
+  IFS=$save_IFS
+
+  if test "$found" != yes; then
+    lib=$lib.lib
+  fi
+}
+
 # func_cl_wrapper cl arg...
 # Adjust compile command to suit cl
 func_cl_wrapper ()
@@ -109,43 +151,34 @@ func_cl_wrapper ()
              ;;
          esac
          ;;
+       -I)
+         eat=1
+         func_file_conv "$2" mingw
+         set x "$@" -I"$file"
+         shift
+         ;;
        -I*)
          func_file_conv "${1#-I}" mingw
          set x "$@" -I"$file"
          shift
          ;;
+       -l)
+         eat=1
+         func_cl_dashl "$2"
+         set x "$@" "$lib"
+         shift
+         ;;
        -l*)
-         lib=${1#-l}
-         found=no
-         save_IFS=$IFS
-         IFS=';'
-         for dir in $lib_path $LIB
-         do
-           IFS=$save_IFS
-           if $shared && test -f "$dir/$lib.dll.lib"; then
-             found=yes
-             set x "$@" "$dir/$lib.dll.lib"
-             break
-           fi
-           if test -f "$dir/$lib.lib"; then
-             found=yes
-             set x "$@" "$dir/$lib.lib"
-             break
-           fi
-         done
-         IFS=$save_IFS
-
-         test "$found" != yes && set x "$@" "$lib.lib"
+         func_cl_dashl "${1#-l}"
+         set x "$@" "$lib"
          shift
          ;;
+       -L)
+         eat=1
+         func_cl_dashL "$2"
+         ;;
        -L*)
-         func_file_conv "${1#-L}"
-         if test -z "$lib_path"; then
-           lib_path=$file
-         else
-           lib_path="$lib_path;$file"
-         fi
-         linker_opts="$linker_opts -LIBPATH:$file"
+         func_cl_dashL "${1#-L}"
          ;;
        -static)
          shared=false
diff --git a/tests/compile3.test b/tests/compile3.test
index 15064a6..b27fc65 100755
--- a/tests/compile3.test
+++ b/tests/compile3.test
@@ -32,23 +32,23 @@ END
 chmod +x ./cl
 
 # Check if compile handles "-o foo", -I, -l, -L, -Xlinker -Wl,
-opts=`LIB= ./compile ./cl foo.c -o foo -lbar -Lgazonk -Ibaz -Xlinker foobar 
-Wl,-foo,bar`
-test x"$opts" = x"foo.c -Fefoo bar.lib -Ibaz -link -LIBPATH:gazonk foobar -foo 
bar"
+opts=`LIB= ./compile ./cl foo.c -o foo -lbar -l bar2 -Lgazonk -L food -Ibaz -I 
zardoz -Xlinker foobar -Wl,-foo,bar`
+test x"$opts" = x"foo.c -Fefoo bar.lib bar2.lib -Ibaz -Izardoz -link 
-LIBPATH:gazonk -LIBPATH:food foobar -foo bar"
 
 # Check if compile handles "-o foo.obj"
-opts=`./compile ./cl -c foo.c -o foo.obj -Ibaz`
+opts=`./compile ./cl -c foo.c -o foo.obj -I baz`
 test x"$opts" = x"-c foo.c -Fofoo.obj -Ibaz"
 
 # Check if compile handles "-o foo.o"
-opts=`./compile ./cl -c foo.c -o foo.o -Ibaz`
+opts=`./compile ./cl -c foo.c -o foo.o -I baz`
 test x"$opts" = x"-c foo.c -Fofoo.o -Ibaz"
 
 # Check if compile handles "foo.cc" as C++.
-opts=`./compile ./cl -c foo.cc -o foo.o -Ibaz`
+opts=`./compile ./cl -c foo.cc -o foo.o -I baz`
 test x"$opts" = x"-c -Tpfoo.cc -Fofoo.o -Ibaz"
 
 # Check if compile clears the "eat" variable properly.
-opts=`eat=1 ./compile ./cl -c foo.c -o foo.obj -Ibaz`
+opts=`eat=1 ./compile ./cl -c foo.c -o foo.obj -I baz`
 test x"$opts" = x"-c foo.c -Fofoo.obj -Ibaz"
 
 :
diff --git a/tests/compile4.test b/tests/compile4.test
index 0b3e981..03bec23 100755
--- a/tests/compile4.test
+++ b/tests/compile4.test
@@ -79,7 +79,7 @@ if test -f sub/libfoo.a; then
   cp sub/libfoo.a sub/foo.lib
 fi
 
-./compile cl $CFLAGS $LDFLAGS -L"$absfoodir" "$absmainobj" -o main -lfoo
+./compile cl $CFLAGS $LDFLAGS -L "$absfoodir" "$absmainobj" -o main -lfoo
 
 ./main
 
diff --git a/tests/compile5.test b/tests/compile5.test
index cd1468f..fc679fe 100755
--- a/tests/compile5.test
+++ b/tests/compile5.test
@@ -68,7 +68,7 @@ pwd=`pwd`
 # Check if "compile cl" transforms absolute file names to
 # host format (e.g /somewhere -> c:/msys/1.0/somewhere).
 
-res=`./compile ./cl -L"$pwd" | sed -e 's/-link -LIBPATH://'`
+res=`./compile ./cl -L "$pwd" | sed -e 's/-link -LIBPATH://'`
 
 case $res in
   ?:[\\/]*)
diff --git a/tests/compile6.test b/tests/compile6.test
index f45a534..e4b9e8f 100755
--- a/tests/compile6.test
+++ b/tests/compile6.test
@@ -43,11 +43,11 @@ mkdir lib
 :> lib/bar.dll.lib
 
 # Check if compile library search correctly
-opts=`./compile ./cl foo.c -o foo -Llib -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link 
-LIBPATH:lib"
 
 # Check if -static makes compile avoid bar.dll.lib
-opts=`./compile ./cl foo.c -o foo -Llib -static -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib -static -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo lib/bar.lib $syslib/foo.lib -link -LIBPATH:lib"
 
 :> syslib/bar.lib
@@ -58,27 +58,27 @@ opts=`./compile ./cl foo.c -o foo -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo $syslib/bar.dll.lib $syslib/foo.lib"
 
 # Check if compile prefers -L over $LIB
-opts=`./compile ./cl foo.c -o foo -Llib -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link 
-LIBPATH:lib"
 
 mkdir lib2
 :> lib2/bar.dll.lib
 
 # Check if compile avoids bar.dll.lib in lib2 when -static
-opts=`./compile ./cl foo.c -o foo -Llib2 -static -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib2 -static -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo $syslib/bar.lib $syslib/foo.lib -link 
-LIBPATH:lib2"
 
 # Check if compile gets two different bar libraries when -static
 # is added in the middle
-opts=`./compile ./cl foo.c -o foo -Llib2 -Llib -lbar -static -lbar`
+opts=`./compile ./cl foo.c -o foo -L lib2 -L lib -lbar -static -lbar`
 test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib lib/bar.lib -link 
-LIBPATH:lib2 -LIBPATH:lib"
 
 # Check if compile gets the correct bar.dll.lib
-opts=`./compile ./cl foo.c -o foo -Llib -Llib2 -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib -L lib2 -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link 
-LIBPATH:lib -LIBPATH:lib2"
 
 # Check if compile gets the correct bar.dll.lib
-opts=`./compile ./cl foo.c -o foo -Llib2 -Llib -lbar -lfoo`
+opts=`./compile ./cl foo.c -o foo -L lib2 -L lib -lbar -lfoo`
 test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib $syslib/foo.lib -link 
-LIBPATH:lib2 -LIBPATH:lib"
 
 mkdir "sys  lib2"
-- 
1.7.9




reply via email to

[Prev in Thread] Current Thread [Next in Thread]