changeset 3112:31edb6eea0eb

[MSVC] fix cc-msvc when INCLUDE/LIB variables are empty, improve compatibility with MinGW.
author Michael Goffioul <michael.goffioul@gmail.com>
date Mon, 01 Jul 2013 13:31:11 -0400
parents 50135b4423ec
children 1fbdd34dd2ef
files src/build-msvctools/cc-msvc.cc
diffstat 1 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/build-msvctools/cc-msvc.cc	Mon Jul 01 13:31:08 2013 -0400
+++ b/src/build-msvctools/cc-msvc.cc	Mon Jul 01 13:31:11 2013 -0400
@@ -324,8 +324,11 @@
       else
         root.resize (root.size () - 4);
 
-      string include_var = getenv ("INCLUDE");
-      string lib_var = getenv ("LIB");
+      char * include_var_s = getenv ("INCLUDE");
+      char * lib_var_s = getenv ("LIB");
+
+      string include_var = (include_var_s ? include_var_s : "");
+      string lib_var = (lib_var_s ? lib_var_s : "");
 
       if (include_var.empty ())
         include_var = "INCLUDE=" + root + "\\include";
@@ -469,6 +472,11 @@
 			// do not pass those to the linker
 			clopt += (" " + arg);
 		}
+                else if (arg == "-O3")
+                {
+                        // MSVC does not support -O3, convert to -O2 instead
+			clopt += " -O2";
+                }
 		else if (starts_with(arg, "-I"))
 		{
 			string path = arg.substr(2);
@@ -557,7 +565,8 @@
 		}
 		else if (arg == "-m386" || arg == "-m486" || arg == "-mpentium" ||
 			 arg == "-mpentiumpro" || arg == "-pedantic" || starts_with(arg, "-W") ||
-			 arg == "-fPIC" || arg == "-nostdlib" || arg == "--export-all-symbols")
+			 arg == "-fPIC" || arg == "-nostdlib" || arg == "--export-all-symbols" ||
+                         starts_with(arg, "-march=") || arg == "-fomit-frame-pointer")
 		{
 			// ignore
 		}
@@ -716,7 +725,11 @@
 			linkopt += " -IMPLIB:" + implib;
 		}
 		else if (arg == "--enable-auto-import"
-			 || arg == "--enable-auto-image-base")
+			 || arg == "--enable-auto-image-base"
+			 || arg == "--whole-archive"
+			 || arg == "--no-whole-archive"
+			 || arg == "-Bsymbolic"
+			 || arg == "-s")
 		{
 			// Ignore these.
 		}
@@ -726,6 +739,28 @@
 			if (it == Xlinkopt.end ())
 				break;
 		}
+		else if (arg == "--image-base"
+			 || starts_with(arg, "--image-base="))
+		{
+			string base_addr;
+
+			if (arg == "--image-base")
+			{
+				++it;
+				if (it != Xlinkopt.end ())
+					base_addr = *it;
+				else
+				{
+					cerr << "WARNING: missing base address, ignored" << endl;
+					continue;
+				}
+			}
+			else
+				base_addr = arg.substr (13);
+
+			cllinkopt += " -BASE:" + base_addr;
+			linkopt += " -BASE:" + base_addr;
+		}
 		else
 		{
 			cllinkopt += " " + arg;