automake-patches
[Top][All Lists]
Advanced

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

[PATCH] compile: implement library search to support MSVC static linking


From: Peter Rosin
Subject: [PATCH] compile: implement library search to support MSVC static linking
Date: Tue, 21 Sep 2010 17:11:26 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2

Hi!

This is for the msvc branch.  This idea was previously discussed here:
http://lists.gnu.org/archive/html/libtool-patches/2010-09/msg00044.html

The implementation is simpler than I thought it would be though.

Cheers,
Peter


>From 3fa9c9010f755aa3294bd2d6a31298f01e76d0d3 Mon Sep 17 00:00:00 2001
From: Peter Rosin <address@hidden>
Date: Tue, 21 Sep 2010 16:55:25 +0200
Subject: [PATCH] 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.

Signed-off-by: Peter Rosin <address@hidden>
---
 ChangeLog           |   14 +++++++++
 lib/compile         |   36 ++++++++++++++++++++--
 tests/Makefile.am   |    1 +
 tests/Makefile.in   |    1 +
 tests/compile3.test |    2 +-
 tests/compile6.test |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 132 insertions(+), 4 deletions(-)
 create mode 100755 tests/compile6.test

diff --git a/ChangeLog b/ChangeLog
index 02f2fcd..d829a23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-21  Peter Rosin  <address@hidden>
+
+       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  <address@hidden>
 
        Make ar-lib support backslashed files in archives.
diff --git a/lib/compile b/lib/compile
index 77f8f31..46caccc 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 01acd76..816405a 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 ff547a0..e1b170a 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 b77237b..e376800 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 0000000..2af089d
--- /dev/null
+++ b/tests/compile6.test
@@ -0,0 +1,82 @@
+#! /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
+
+LIB=`pwd`/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 $LIB/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 $LIB/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 $LIB/bar.dll.lib $LIB/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 $LIB/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 $LIB/bar.lib $LIB/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 $LIB/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 $LIB/foo.lib -link 
-LIBPATH:lib2 -LIBPATH:lib"
+
+:
-- 
1.7.1





reply via email to

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