Merge pull request #107 from rvandermeulen/msvcc Various compatibility fixes and improvements to msvcc.sh.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/msvcc.sh b/msvcc.sh
index dcdbeab..7440deb 100755
--- a/msvcc.sh
+++ b/msvcc.sh
@@ -42,6 +42,7 @@
# format and translated into something sensible for cl or ml.
#
+args_orig=$@
args="-nologo -W3"
md=-MD
cl="cl"
@@ -72,14 +73,35 @@ do
shift 1
;;
-O*)
- # If we're optimizing, make sure we explicitly turn on some optimizations
- # that are implicitly disabled by debug symbols (-Zi).
- args="$args $1 -OPT:REF -OPT:ICF -INCREMENTAL:NO"
+ # Runtime error checks (enabled by setting -RTC1 in the -DFFI_DEBUG
+ # case below) are not compatible with optimization flags and will
+ # cause the build to fail. Therefore, drop the optimization flag if
+ # -DFFI_DEBUG is also set.
+ case $args_orig in
+ *-DFFI_DEBUG*)
+ args="$args"
+ ;;
+ *)
+ # The ax_cc_maxopt.m4 macro from the upstream autoconf-archive
+ # project doesn't support MSVC and therefore ends up trying to
+ # use -O3. Use the equivalent "max optimization" flag for MSVC
+ # instead of erroring out.
+ case $1 in
+ -O3)
+ args="$args -O2"
+ ;;
+ *)
+ args="$args $1"
+ ;;
+ esac
+ opt="true"
+ ;;
+ esac
shift 1
;;
-g)
# Enable debug symbol generation.
- args="$args -Zi -DEBUG"
+ args="$args -Zi"
shift 1
;;
-DFFI_DEBUG)
@@ -126,6 +148,10 @@ do
# to do here.
shift 1
;;
+ -pedantic)
+ # libffi tests -pedantic with -Wall, so drop it also.
+ shift 1
+ ;;
-Werror)
args="$args -WX"
shift 1
@@ -170,6 +196,13 @@ do
esac
done
+# If -Zi is specified, certain optimizations are implicitly disabled
+# by MSVC. Add back those optimizations if this is an optimized build.
+# NOTE: These arguments must come after all others.
+if [ -n "$opt" ]; then
+ args="$args -link -OPT:REF -OPT:ICF -INCREMENTAL:NO"
+fi
+
if [ -n "$assembly" ]; then
if [ -z "$outdir" ]; then
outdir="."
@@ -189,7 +222,10 @@ if [ -n "$assembly" ]; then
else
args="$md $args"
echo "$cl $args"
- eval "\"$cl\" $args"
+ # Return an error code of 1 if an invalid command line parameter is passed
+ # instead of just ignoring it.
+ eval "(\"$cl\" $args 2>&1 1>&3 | \
+ awk '{print \$0} /D9002/ {error=1} END{exit error}' >&2) 3>&1"
result=$?
fi