diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rwxr-xr-x | lib/compile | 36 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/Makefile.in | 1 | ||||
-rwxr-xr-x | tests/compile3.test | 2 | ||||
-rwxr-xr-x | tests/compile6.test | 98 |
6 files changed, 148 insertions, 4 deletions
@@ -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. diff --git a/lib/compile b/lib/compile index 77f8f3176..46caccc37 100755 --- a/lib/compile +++ b/lib/compile @@ -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=',' diff --git a/tests/Makefile.am b/tests/Makefile.am index 01acd768e..816405af2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/Makefile.in b/tests/Makefile.in index ff547a0fb..e1b170a3d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 \ diff --git a/tests/compile3.test b/tests/compile3.test index b77237b93..e376800c5 100755 --- a/tests/compile3.test +++ b/tests/compile3.test @@ -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 index 000000000..0f09e84db --- /dev/null +++ b/tests/compile6.test @@ -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" + +: |