Hi Chuck,

Den 2010-06-22 14:04 skrev Charles Wilson:
On 6/22/2010 7:53 AM, Peter Rosin wrote:
I added compile5.test. I don't think $build is part of the equation
for the purpose of this test, and the only supported $host at this
point is mingw. Is it what you had in mind?

Well, if $build is cygwin, then it'll work, because cygwin always has
cygcheck.  If $build is mingw (actually "msys" in its normal 'pretend
I'm mingw' mode) then it'll work, because cmd always exists, and sed is
part of the base msys installation.

However, if $build is anything else, then it'll work IF and only IF
winepath is present.  That's not a given.  I don't think the test should
FAIL just because wine is not installed; I think it should be skipped.

Ok, compile5 now skips if not on mingw/cygwin and winepath is not present.

Finally, if $host is anything other than $mingw, then the tests should
be skipped, too.  Right?

Right, but that was already the case I think.

Thanks for reviewing!

Cheers,
Peter
commit 9526413ac23e6db00ae79a15f05be83612eac596
Author: Peter Rosin <peda@lysator.liu.se>
Date:   Tue Jun 22 15:24:48 2010 +0200

    Wrap some MSVC options in the compile script.
    
    * lib/compile: MSVC supports naming the output file, the option
    is just not called -o, so transform -o into the appropriate form
    for MSVC. Also wrap some other options while at it (-L, -l, -Wl,
    -Xlinker and -I) and convert file names to windows form where
    needed for those options to make MSVC more usable in an
    autotooled environment.
    * doc/automake.texi (Auxiliary Programs): Document the above
    extension of the compile script.
    * NEWS: Updated.
    * tests/defs.in: New required entry 'cl'.
    * tests/compile3.test: New test.
    * tests/compile4.test: New test.
    * tests/compile5.test: New test.
    * tests/Makefile.am: Update.

diff --git a/ChangeLog b/ChangeLog
index a754652..1ba55e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-06-22  Peter Rosin  <peda@lysator.liu.se>
+
+	Wrap some MSVC options in the compile script.
+	* lib/compile: MSVC supports naming the output file, the option
+	is just not called -o, so transform -o into the appropriate form
+	for MSVC. Also wrap some other options while at it (-L, -l, -Wl,
+	-Xlinker and -I) and convert file names to windows form where
+	needed for those options to make MSVC more usable in an
+	autotooled environment.
+	* doc/automake.texi (Auxiliary Programs): Document the above
+	extension of the compile script.
+	* NEWS: Updated.
+	* tests/defs.in: New required entry 'cl'.
+	* tests/compile3.test: New test.
+	* tests/compile4.test: New test.
+	* tests/compile5.test: New test.
+	* tests/Makefile.am: Update.
+
 2010-06-20  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
 	Modernize, improve and extend tests `suffix*.test'.
diff --git a/NEWS b/NEWS
index 13b28c0..ae290d5 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ New in 1.11a:
 
   - automake now generates silenced rules for texinfo outputs.
 
+  - The `compile' script now converts some options for MSVC for a better
+    user experience.
+
 * New targets:
 
   - New `cscope' target to build a cscope database for the source tree.
diff --git a/doc/automake.texi b/doc/automake.texi
index f5ccca1..491fafe 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -2169,7 +2169,11 @@ These two files are used for de-ANSI-fication support (obsolete
 @item compile
 This is a wrapper for compilers that do not accept options @option{-c}
 and @option{-o} at the same time.  It is only used when absolutely
-required.  Such compilers are rare.
+required.  Such compilers are rare, with the Microsoft C/C++ Compiler
+as the most notable exception. This wrapper also makes the following
+common options available for that compiler, while performing file name
+translation where needed: @option{-I}, @option{-L}, @option{-l},
+@option{-Wl,} and @option{-Xlinker}.
 
 @item config.guess
 @itemx config.sub
diff --git a/lib/compile b/lib/compile
index c0096a7..aace3d2 100755
--- a/lib/compile
+++ b/lib/compile
@@ -1,9 +1,9 @@
 #! /bin/sh
 # Wrapper for compilers which do not understand `-c -o'.
 
-scriptversion=2009-10-06.20; # UTC
+scriptversion=2010-06-22.06; # UTC
 
-# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010  Free Software
 # Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
@@ -29,6 +29,121 @@ scriptversion=2009-10-06.20; # UTC
 # bugs to <bug-automake@gnu.org> or send patches to
 # <automake-patches@gnu.org>.
 
+nl='
+'
+
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent tools from complaining about whitespace usage.
+IFS=" ""	$nl"
+
+file_conv=
+
+# func_file_conv build_file
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Win32 hosts.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[^/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+	# lazily determine how to convert abs files
+	case `uname -s` in
+	  MINGW*)
+	    file_conv=mingw
+	    ;;
+	  CYGWIN*)
+	    file_conv=cygwin
+	    ;;
+	  *)
+	    file_conv=wine
+	    ;;
+	esac
+      fi
+      case $file_conv in
+	mingw)
+	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+	  ;;
+	cygwin)
+	  file=`cygpath -m "$file" || echo "$file"`
+	  ;;
+	wine)
+	  file=`winepath -w "$file" || echo "$file"`
+	  ;;
+      esac
+      ;;
+  esac
+}
+
+# func_cl_wrapper cl arg...
+# Adjust compile command to suite cl
+func_cl_wrapper ()
+{
+  # Assume a capable shell
+  linker_opts=
+  for arg
+  do
+    if test -n "$eat"; then
+      eat=
+    else
+      case $1 in
+	-o)
+	  # configure might choose to run compile as `compile cc -o foo foo.c'.
+	  eat=1
+	  case $2 in
+	    *.o | *.[oO][bB][jJ])
+	      func_file_conv "$2"
+	      set x "$@" -Fo"$file"
+	      shift
+	      ;;
+	    *)
+	      func_file_conv "$2"
+	      set x "$@" -Fe"$file"
+	      shift
+	      ;;
+	  esac
+	  ;;
+	-I*)
+	  func_file_conv "${1#-I}"
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-l*)
+	  set x "$@" "${1#-l}.lib"
+	  shift
+	  ;;
+	-L*)
+	  func_file_conv "${1#-L}"
+	  linker_opts="$linker_opts -LIBPATH:$file"
+	  ;;
+	-Wl,*)
+	  arg=${1#-Wl,}
+	  save_ifs="$IFS"; IFS=','
+	  for flag in $arg; do
+	    IFS="$save_ifs"
+	    linker_opts="$linker_opts $flag"
+	  done
+	  IFS="$save_ifs"
+	  ;;
+	-Xlinker)
+	  eat=1
+	  linker_opts="$linker_opts $2"
+	  ;;
+	*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+      esac
+    fi
+    shift
+  done
+  if test -n "$linker_opts"; then
+    linker_opts="-link$linker_opts"
+  fi
+  exec "$@" $linker_opts
+  exit 1
+}
+
 case $1 in
   '')
      echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
@@ -53,6 +168,10 @@ EOF
     echo "compile $scriptversion"
     exit $?
     ;;
+  cl | *[/\\]cl | cl\ * | *[/\\]cl\ * \
+  | cl.exe | *[/\\]cl.exe | cl.exe\ * | *[/\\]cl.exe\ * )
+    func_cl_wrapper "$@"      # Doesn't return...
+    ;;
 esac
 
 ofile=
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2771a66..98e5587 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -177,6 +177,9 @@ commen10.test \
 commen11.test \
 compile.test \
 compile2.test \
+compile3.test \
+compile4.test \
+compile5.test \
 compile_f90_c_cxx.test \
 compile_f_c_cxx.test \
 cond.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index db53cfb..103b961 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -388,6 +388,9 @@ commen10.test \
 commen11.test \
 compile.test \
 compile2.test \
+compile3.test \
+compile4.test \
+compile5.test \
 compile_f90_c_cxx.test \
 compile_f_c_cxx.test \
 cond.test \
diff --git a/tests/compile3.test b/tests/compile3.test
new file mode 100755
index 0000000..5bccb37
--- /dev/null
+++ b/tests/compile3.test
@@ -0,0 +1,45 @@
+#! /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' wraps the Microsoft C/C++ compiler (cl) 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
+
+# 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`
+test x"$opts" = x"foo.c -Fefoo bar.lib -Ibaz -link -LIBPATH:gazonk foobar -foo bar"
+
+# Check if compile handles "-o foo.obj"
+opts=`./compile ./cl -c foo.c -o foo.obj -Ibaz`
+test x"$opts" = x"-c foo.c -Fofoo.obj -Ibaz"
+
+# Check if compile handles "-o foo.o"
+opts=`./compile ./cl -c foo.c -o foo.o -Ibaz`
+test x"$opts" = x"-c foo.c -Fofoo.o -Ibaz"
+
+:
diff --git a/tests/compile4.test b/tests/compile4.test
new file mode 100755
index 0000000..d4c736d
--- /dev/null
+++ b/tests/compile4.test
@@ -0,0 +1,81 @@
+#! /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' wraps the Microsoft C/C++ compiler (cl) correctly
+# with respect to absolute paths.
+
+required='cl'
+. ./defs || Exit 1
+
+set -e
+
+mkdir sub
+
+cat >sub/foo.c <<'EOF'
+int
+foo ()
+{
+  return 0;
+}
+EOF
+
+cat >main.c <<'EOF'
+extern int foo ();
+int
+main ()
+{
+  return foo ();
+}
+EOF
+
+absfoodir=`pwd`/sub
+absmain=`pwd`/main.c
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_RANLIB
+AC_OUTPUT(sub/Makefile)
+END
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub
+END
+
+cat > sub/Makefile.am << 'END'
+lib_LIBRARIES = libfoo.a
+libfoo_a_SOURCES = foo.c
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE
+
+# 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
+
+./compile cl $CPPFLAGS $CFLAGS $LDFLAGS -L"$absfoodir" "$absmain" -o main -lfoo
+
+./main
+
+:
diff --git a/tests/compile5.test b/tests/compile5.test
new file mode 100755
index 0000000..3ed848d
--- /dev/null
+++ b/tests/compile5.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 the file name translation in the `compile' script works
+# 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
+
+cat >>configure.in << 'END'
+AC_CANONICAL_HOST
+AC_OUTPUT(check_host)
+END
+
+: >Makefile.am
+
+cat >check_host.in << 'END'
+#! /bin/sh
+case @host_os@ in
+  mingw*)
+    ;;
+  *)
+    exit 77
+    ;;
+esac
+case @build_os@ in
+  mingw* | cygwin*)
+    ;;
+  *)
+    winepath -w / || exit 77
+    ;;
+esac
+END
+
+chmod +x ./check_host.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+./check_host
+
+pwd=`pwd`
+
+# Check if "compile cl" transforms absolute file names to
+# host format (e.g /somewhere -> c:/msys/1.0/somewhere).
+
+res=`./compile ./cl -L"$pwd" | sed -e 's/-link -LIBPATH://'`
+
+case $res in
+  ?:[\\/]*)
+    ;;
+  *)
+    Exit 1
+    ;;
+esac
+
+:
diff --git a/tests/defs.in b/tests/defs.in
index 9bb6333..b5cc99e 100644
--- a/tests/defs.in
+++ b/tests/defs.in
@@ -105,6 +105,12 @@ do
       echo "$me: running bzip2 --help"
       ( bzip2 --help ) || exit 77
       ;;
+    cl)
+      CC=cl
+      export CC
+      echo "$me: running $CC -?"
+      ( $CC -? ) || exit 77
+      ;;
     etags)
       # Exuberant Ctags will create a TAGS file even
       # when asked for --help or --version.  (Emacs's etags

Reply via email to