summaryrefslogtreecommitdiff
path: root/msvcc.sh
diff options
context:
space:
mode:
authorRyan VanderMeulen <ryanvm@gmail.com>2014-03-18 12:09:45 -0400
committerRyan VanderMeulen <ryanvm@gmail.com>2014-03-18 12:09:45 -0400
commitc3dd0a1a0245fc174361a70876e88ae24285f861 (patch)
treeb0b4f25ec08b061522e3416a9a7415ba70efc193 /msvcc.sh
parentc697472fccfbb5b87b007c053cda9ef014b346b9 (diff)
downloadlibffi-c3dd0a1a0245fc174361a70876e88ae24285f861.tar.gz
Various compatibility fixes and improvements to msvcc.sh.
* Don't try to mix incompatible optimization flags in debug builds. * Workaround ax_cc_maxopt.m4 not supporting MSVC and change -O3 to -O2. * Fix MSVC warning by properly passing linker flags to compiler. * Make msvcc.sh return 1 if invalid command line options are used rather than silently eating them. * Add more comments.
Diffstat (limited to 'msvcc.sh')
-rwxr-xr-xmsvcc.sh46
1 files changed, 41 insertions, 5 deletions
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