]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
compile: implement library search to support MSVC static linking
authorPeter Rosin <peda@lysator.liu.se>
Tue, 21 Sep 2010 18:59:54 +0000 (20:59 +0200)
committerPeter Rosin <peda@lysator.liu.se>
Tue, 21 Sep 2010 18:59:54 +0000 (20:59 +0200)
* lib/compile (func_cl_wrapper): Implement library search and
-static option so that the user can select whether to prefer
dll import libraries or static libraries.  This enables MSVC to
link against dlls generated by libtool without requiring libtool
or workarounds such as -lfoo.dll etc.  Makes the tests/static.at
test case in libtool pass.
* tests/compile3.test: Don't trip up if there happens to exist
a "foo" library in the library search path.
* tests/compile6.test: New test, verifying the library search.
* tests/Makefile.am (TESTS): Update.

Signed-off-by: Peter Rosin <peda@lysator.liu.se>
ChangeLog
lib/compile
tests/Makefile.am
tests/Makefile.in
tests/compile3.test
tests/compile6.test [new file with mode: 0755]

index 02f2fcd09fe386a50f6d4e5bdaf12a14fd22dfe3..d829a23e421db60434bcc2e5ad3ca10904c8aa56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-21  Peter Rosin  <peda@lysator.liu.se>
+
+       compile: implement library search to support MSVC static linking
+       * lib/compile (func_cl_wrapper): Implement library search and
+       -static option so that the user can select whether to prefer
+       dll import libraries or static libraries.  This enables MSVC to
+       link against dlls generated by libtool without requiring libtool
+       or workarounds such as -lfoo.dll etc.  Makes the tests/static.at
+       test case in libtool pass.
+       * tests/compile3.test: Don't trip up if there happens to exist
+       a "foo" library in the library search path.
+       * tests/compile6.test: New test, verifying the library search.
+       * tests/Makefile.am (TESTS): Update.
+
 2010-09-02  Peter Rosin  <peda@lysator.liu.se>
 
        Make ar-lib support backslashed files in archives.
index 77f8f317633890235f514db125c4da083e9ab2b0..46caccc37c94ed4c60ecfb00d67fd7a65bc617da 100755 (executable)
@@ -1,7 +1,7 @@
 #! /bin/sh
 # Wrapper for compilers which do not understand `-c -o'.
 
-scriptversion=2010-08-31.19; # UTC
+scriptversion=2010-09-21.14; # UTC
 
 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010 Free Software
 # Foundation, Inc.
@@ -80,10 +80,12 @@ func_file_conv ()
 }
 
 # func_cl_wrapper cl arg...
-# Adjust compile command to suite cl
+# Adjust compile command to suit cl
 func_cl_wrapper ()
 {
   # Assume a capable shell
+  lib_path=
+  shared=:
   linker_opts=
   for arg
   do
@@ -113,13 +115,41 @@ func_cl_wrapper ()
          shift
          ;;
        -l*)
-         set x "$@" "${1#-l}.lib"
+         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"
          shift
          ;;
        -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"
          ;;
+       -static)
+         shared=false
+         ;;
        -Wl,*)
          arg=${1#-Wl,}
          save_ifs="$IFS"; IFS=','
index 01acd768eac21b7a41d3fb77b9b08b51f67cb71b..816405af2c0a4ab8f3ec3ed402925169340c6b6e 100644 (file)
@@ -162,6 +162,7 @@ compile2.test \
 compile3.test \
 compile4.test \
 compile5.test \
+compile6.test \
 compile_f90_c_cxx.test \
 compile_f_c_cxx.test \
 cond.test \
index ff547a0fbde656f9276f40676f0c10e5cafb743c..e1b170a3d13bf61eda132b7cd9719b8fb61b3a33 100644 (file)
@@ -400,6 +400,7 @@ compile2.test \
 compile3.test \
 compile4.test \
 compile5.test \
+compile6.test \
 compile_f90_c_cxx.test \
 compile_f_c_cxx.test \
 cond.test \
index b77237b9392244b65a60543ff97a0f4c513f10b5..e376800c5d92ad38cc6ed988f5df94663c01b5c9 100755 (executable)
@@ -31,7 +31,7 @@ END
 chmod +x ./cl
 
 # Check if compile handles "-o foo", -I, -l, -L, -Xlinker -Wl,
-opts=`./compile ./cl foo.c -o foo -lbar -Lgazonk -Ibaz -Xlinker foobar -Wl,-foo,bar`
+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"
 
 # Check if compile handles "-o foo.obj"
diff --git a/tests/compile6.test b/tests/compile6.test
new file mode 100755 (executable)
index 0000000..0f09e84
--- /dev/null
@@ -0,0 +1,98 @@
+#! /bin/sh
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Make sure `compile' searches libraries correctly
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/compile" .
+
+# Use a dummy cl, since cl isn't readily available on all systems
+cat >cl <<'END'
+#! /bin/sh
+echo "$@"
+END
+
+chmod +x ./cl
+
+mkdir syslib
+:> syslib/foo.lib
+
+syslib=`pwd`/syslib
+LIB=$syslib
+export LIB
+
+mkdir lib
+:> lib/bar.lib
+:> lib/bar.dll.lib
+
+# Check if compile library search correctly
+opts=`./compile ./cl foo.c -o foo -Llib -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`
+test x"$opts" = x"foo.c -Fefoo lib/bar.lib $syslib/foo.lib -link -LIBPATH:lib"
+
+:> syslib/bar.lib
+:> syslib/bar.dll.lib
+
+# Check if compile finds bar.dll.lib in syslib
+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`
+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`
+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`
+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`
+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`
+test x"$opts" = x"foo.c -Fefoo lib2/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib2 -LIBPATH:lib"
+
+mkdir "sys  lib2"
+:> "sys  lib2/foo.dll.lib"
+
+syslib2="`pwd`/sys  lib2"
+LIB="$syslib2;$LIB"
+
+# Check if compile handles spaces in $LIB and that it prefers the order
+# in a multi-component $LIB.
+opts=`./compile ./cl foo.c -o foo -lfoo`
+test x"$opts" = x"foo.c -Fefoo $syslib2/foo.dll.lib"
+
+# Check if compile handles the 2nd directory in a multi-component $LIB.
+opts=`./compile ./cl foo.c -o foo -static -lfoo`
+test x"$opts" = x"foo.c -Fefoo $syslib/foo.lib"
+
+: