>From f54c5b1304766778b691aa88475a10c68e41f058 Mon Sep 17 00:00:00 2001 From: Peter Rosin Date: Thu, 4 Oct 2012 00:08:26 +0200 Subject: [PATCH] compile: support libfoo.a naming when wrapping Microsoft tools There is a future plan to provide some means to have Automake create static libraries that are named differently depending on the system [1]. The background is that everyone has always named static libraries libfoo.a, except the Redmond crowd who names them foo.lib, and you have to jump through hoops to have Automake create libraries named foo.lib in the land of non-GNU Windows while still creating libfoo.a everywhere else. However, there is probably no sane way to accomplish that system dependent naming discussed in [1] without user intervention, which makes it necessary to support the classic libfoo.a naming when using Microsoft tools in the best possible way, for the benefit of all projects today and for future projects not opting in to whatever scheme is selected for the problem at hand. [1] http://lists.gnu.org/archive/html/automake/2012-09/msg00028.html * lib/compile (func_cl_dashl): As a last resort, match -lfoo with libfoo.a, if that file exist on the library search path. * t/compile4.sh: Remove obsolescent workaround for the above. * t/compile6.sh: Extend to check that libbaz.a is indeed found when baz.lib and baz.dll.lib does not exist and that bar.lib and bar.dll.lib are preferred over libbar.a. Signed-off-by: Peter Rosin --- lib/compile | 7 ++++++- t/compile4.sh | 8 -------- t/compile6.sh | 10 +++++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/compile b/lib/compile index 7b4a9a7..45cf039 100755 --- a/lib/compile +++ b/lib/compile @@ -1,7 +1,7 @@ #! /bin/sh # Wrapper for compilers which do not understand '-c -o'. -scriptversion=2012-03-05.13; # UTC +scriptversion=2012-10-03.22; # UTC # Copyright (C) 1999-2012 Free Software Foundation, Inc. # Written by Tom Tromey . @@ -112,6 +112,11 @@ func_cl_dashl () lib=$dir/$lib.lib break fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi done IFS=$save_IFS diff --git a/t/compile4.sh b/t/compile4.sh index 2e275a3..e5b5c57 100755 --- a/t/compile4.sh +++ b/t/compile4.sh @@ -70,14 +70,6 @@ $MAKE ./compile cl $CPPFLAGS $CFLAGS -c -o "$absmainobj" "$absmainc" -# cl expects archives to be named foo.lib, not libfoo.a so -# make a simple copy here if needed. This is a severe case -# of badness, but ignore that since this is not what is -# being tested here... -if test -f sub/libfoo.a; then - cp sub/libfoo.a sub/foo.lib -fi - # POSIX mandates that the compiler accepts a space between the -I, # -l and -L options and their respective arguments. Traditionally, # this should work also without a space. Try both usages. diff --git a/t/compile6.sh b/t/compile6.sh index ee47c17..529f22c 100755 --- a/t/compile6.sh +++ b/t/compile6.sh @@ -47,6 +47,8 @@ for sp in '' ' '; do mkdir lib : > lib/bar.lib : > lib/bar.dll.lib + : > lib/libbar.a + : > lib/libbaz.a # Check if compile library search correctly opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo) @@ -58,6 +60,7 @@ for sp in '' ' '; do : > syslib/bar.lib : > syslib/bar.dll.lib + : > syslib/libbar.a # Check if compile finds bar.dll.lib in syslib opts=$(./compile ./cl foo.c -o foo -l${sp}bar -l${sp}foo) @@ -67,6 +70,11 @@ for sp in '' ' '; do opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}bar -l${sp}foo) test x"$opts" = x"foo.c -Fefoo lib/bar.dll.lib $syslib/foo.lib -link -LIBPATH:lib" + # Check if compile falls back to finding classic libname.a style libraries + # when name.lib or name.dll.lib isn't available. + opts=$(./compile ./cl foo.c -o foo -L${sp}lib -l${sp}baz) + test x"$opts" = x"foo.c -Fefoo lib/libbaz.a -link -LIBPATH:lib" + mkdir lib2 : > lib2/bar.dll.lib @@ -93,7 +101,7 @@ for sp in '' ' '; do syslib2="$(pwd)/sys lib2" LIB="$syslib2;$LIB" - # Check if compile handles spaces in $LIB and that it prefers the order + # Check if compile handles spaces in $LIB and that it obeys the order # in a multi-component $LIB. opts=$(./compile ./cl foo.c -o foo -l${sp}foo) test x"$opts" = x"foo.c -Fefoo $syslib2/foo.dll.lib" -- 1.7.9