compile: support libfoo.a naming when wrapping Microsoft tools
authorPeter Rosin <peda@lysator.liu.se>
Wed, 3 Oct 2012 22:08:26 +0000 (00:08 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 14 Oct 2012 10:53:57 +0000 (12:53 +0200)
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 <peda@lysator.liu.se>
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/compile
t/compile4.sh
t/compile6.sh

index 7b4a9a7..718dc6d 100755 (executable)
@@ -1,7 +1,7 @@
 #! /bin/sh
 # Wrapper for compilers which do not understand '-c -o'.
 
-scriptversion=2012-03-05.13; # UTC
+scriptversion=2012-10-14.11; # UTC
 
 # Copyright (C) 1999-2012 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
@@ -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
 
index 2e275a3..e5b5c57 100755 (executable)
@@ -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.
index ee47c17..529f22c 100755 (executable)
@@ -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"