--- compile
+++ compile
@@ -133,6 +133,9 @@ func_cl_wrapper ()
   lib_path=
   shared=:
   linker_opts=
+  outfile=
+  implib=
+  linking=1
   for arg
   do
     if test -n "$eat"; then
@@ -147,11 +150,13 @@ func_cl_wrapper ()
 	      func_file_conv "$2"
 	      set x "$@" -Fo"$file"
 	      shift
+	      outfile="$file"
 	      ;;
 	    *)
 	      func_file_conv "$2"
 	      set x "$@" -Fe"$file"
 	      shift
+	      outfile="$file"
 	      ;;
 	  esac
 	  ;;
@@ -193,6 +198,7 @@ func_cl_wrapper ()
 	  for flag in $arg; do
 	    IFS="$save_ifs"
 	    linker_opts="$linker_opts $flag"
+	    case "$flag" in -IMPLIB:*) implib=${flag#-IMPLIB:} ;; esac
 	  done
 	  IFS="$save_ifs"
 	  ;;
@@ -200,6 +206,10 @@ func_cl_wrapper ()
 	  eat=1
 	  linker_opts="$linker_opts $2"
 	  ;;
+	-std=*)
+	  set x "$@" -std:"${1#-std=}"
+	  shift
+	  ;;
 	-*)
 	  set x "$@" "$1"
 	  shift
@@ -214,6 +224,11 @@ func_cl_wrapper ()
 	  set x "$@" "$file"
 	  shift
 	  ;;
+	-c)
+	  linking=0
+	  set x "$@" "$1"
+	  shift
+	  ;;
 	*)
 	  set x "$@" "$1"
 	  shift
@@ -225,8 +240,28 @@ func_cl_wrapper ()
   if test -n "$linker_opts"; then
     linker_opts="-link$linker_opts"
   fi
-  exec "$@" $linker_opts
-  exit 1
+  # remove old $implib, so we can distinguish between generated and not-generated implib below
+  if test -n "$implib" && test -f "$implib" ; then rm "$implib" ; fi
+
+  # add path to MSVC link in front on PATH if we seem to link (check isn't so accurate, but some false-positives shouldn't matter)
+  # compiler will call the link it finds in the PATH, and we don't want it to use MSYS' /bin/link
+  # we assume that MSVC link is in same directory as cl and that cl is found in PATH
+  if test "$linking" = 1 && comppath=`which cl 2>/dev/null` ; then
+    comppath=`dirname "$comppath"`
+    #echo "Adding $comppath to front of PATH"
+    PATH="$comppath:$PATH"
+  fi
+
+  #echo "compile: $@ $linker_opts"
+  "$@" $linker_opts || exit $?
+
+  # if -implib got lost or ignored, then the lib should be named ${outfile/.dll/.lib} and we rename that file
+  if test -n "$implib" && test ! -f "$implib" ; then
+    echo "compile: mv ${outfile/.dll/.lib} $implib"
+    mv "${outfile/.dll/.lib}" "$implib"
+  fi
+
+  exit 0
 }
 
 eat=
@@ -256,7 +291,8 @@ EOF
     exit $?
     ;;
   cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
-  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
+  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe | \
+  ifort | *[/\\]ifort | ifort.exe | *[/\\]ifort.exe )
     func_cl_wrapper "$@"      # Doesn't return...
     ;;
 esac
