automake-patches
[Top][All Lists]
Advanced

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

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


From: Ralf Wildenhues
Subject: Re: [PATCH] compile: implement library search to support MSVC static linking
Date: Tue, 21 Sep 2010 19:56:49 +0200
User-agent: Mutt/1.5.20 (2010-08-04)

Hi Peter,

* Peter Rosin wrote on Tue, Sep 21, 2010 at 05:11:26PM CEST:
> This is for the msvc branch.  This idea was previously discussed here:
> http://lists.gnu.org/archive/html/libtool-patches/2010-09/msg00044.html

> 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.

Nice work.  Please ping Gary if you want the resulting compile script to
end up in the next Libtool, after merging msvc to master, and after
addressing the nits below.

> --- a/lib/compile
> +++ b/lib/compile

> @@ -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=:

Your -static is position-dependent.  With libtool in place, that is not
going to appear anyway (lt_prog_compiler_pic empty for this compiler),
but for the non-libtool case, that is something to improve (later?).

This is more akin to -Bstatic.  But we can and should add these details
later.

> @@ -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

You are careful here to retain spaces in directory names; the testsuite
should probably exercise that to make sure it isn't broken later.

> +         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"

In this case, may the library still be found by the compiler through
-LIBPATH?

>         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
> +       ;;

> --- 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"

> --- /dev/null
> +++ b/tests/compile6.test

> +# 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

I find the use of $LIB below in the test a bit weird, given that it is
supposed to contain a path, not a directory.  Maybe for clarity rather

  syslib=`pwd`/syslib
  LIB=$syslib
  export LIB

and s/LIB\//syslib\//g below?

Trying more than one directory in $LIB and maybe directory with spaces
in the name in $LIB would be nice.

> +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"
> +
> +:

Thanks,
Ralf



reply via email to

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