win: x86 targets XP subsystem

The default in the VS2013 compiler has been switched to Vista+,
however the runtime library still supports XP if the PE header
is set properly. So, make sure the subsystem is set to 5.01 so
that gyp-built binaries can be run on XP.

R=thakis@chromium.org
BUG=chromium:297971

Review URL: https://codereview.chromium.org/68533011

git-svn-id: http://gyp.googlecode.com/svn/trunk@1784 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py
index 3ac153d..5f6363a 100644
--- a/pylib/gyp/msvs_emulation.py
+++ b/pylib/gyp/msvs_emulation.py
@@ -466,7 +466,17 @@
         else '/MAP'})
     ld('MapExports', map={'true': '/MAPINFO:EXPORTS'})
     ld('AdditionalOptions', prefix='')
-    ld('SubSystem', map={'1': 'CONSOLE', '2': 'WINDOWS'}, prefix='/SUBSYSTEM:')
+
+    xp_version = ''
+    # If we're targeting x86, make sure we're targeting XP.
+    if self._Setting(('VCLinkerTool', 'TargetMachine'),
+                     config, default='1') == '1':
+      xp_version = ',5.01'
+    ld('SubSystem',
+       map={'1': 'CONSOLE%s' % xp_version,
+            '2': 'WINDOWS%s' % xp_version},
+       prefix='/SUBSYSTEM:')
+
     ld('TerminalServerAware', map={'1': ':NO', '2': ''}, prefix='/TSAWARE')
     ld('LinkIncremental', map={'1': ':NO', '2': ''}, prefix='/INCREMENTAL')
     ld('FixedBaseAddress', map={'1': ':NO', '2': ''}, prefix='/FIXED')
diff --git a/test/win/gyptest-link-subsystem.py b/test/win/gyptest-link-subsystem.py
index 94d2a12..de3fb79 100644
--- a/test/win/gyptest-link-subsystem.py
+++ b/test/win/gyptest-link-subsystem.py
@@ -23,6 +23,14 @@
   test.build('subsystem.gyp', 'test_windows_ok', chdir=CHDIR)
   test.build('subsystem.gyp', 'test_windows_fail', chdir=CHDIR, status=1)
 
+  # Make sure we are targeting XP.
+  def GetHeaders(exe):
+    return test.run_dumpbin('/headers', test.built_file_path(exe, chdir=CHDIR))
+  if '5.01 subsystem version' not in GetHeaders('test_console_ok.exe'):
+    test.fail_test()
+  if '5.01 subsystem version' not in GetHeaders('test_windows_ok.exe'):
+    test.fail_test()
+
   # TODO(scottmg): There are other subsystems (WinCE, etc.) that we don't use.
 
   test.pass_test()