[Python-checkins] r42518 - python/trunk/Lib/distutils/msvccompiler.py

martin.v.loewis python-checkins at python.org
Mon Feb 20 13:26:59 CET 2006


Author: martin.v.loewis
Date: Mon Feb 20 13:26:58 2006
New Revision: 42518

Modified:
   python/trunk/Lib/distutils/msvccompiler.py
Log:
Detect Win64 builds.

Modified: python/trunk/Lib/distutils/msvccompiler.py
==============================================================================
--- python/trunk/Lib/distutils/msvccompiler.py	(original)
+++ python/trunk/Lib/distutils/msvccompiler.py	Mon Feb 20 13:26:58 2006
@@ -172,6 +172,20 @@
     # else we don't know what version of the compiler this is
     return None
 
+def get_build_architecture():
+    """Return the processor architecture.
+
+    Possible results are "Intel", "Itanium", or "AMD64".
+    """
+
+    prefix = " bit ("
+    i = string.find(sys.version, prefix)
+    if i == -1:
+        return "Intel"
+    j = string.find(sys.version, ")", i)
+    return sys.version[i+len(prefix):j]
+    
+
 
 class MSVCCompiler (CCompiler) :
     """Concrete class that implements an interface to Microsoft Visual C++,
@@ -206,11 +220,19 @@
     def __init__ (self, verbose=0, dry_run=0, force=0):
         CCompiler.__init__ (self, verbose, dry_run, force)
         self.__version = get_build_version()
-        if self.__version >= 7:
-            self.__root = r"Software\Microsoft\VisualStudio"
-            self.__macros = MacroExpander(self.__version)
+        self.__arch = get_build_architecture()
+        if self.__arch == "Intel":
+            # x86
+            if self.__version >= 7:
+                self.__root = r"Software\Microsoft\VisualStudio"
+                self.__macros = MacroExpander(self.__version)
+            else:
+                self.__root = r"Software\Microsoft\Devstudio"
+            self.__product = "Visual Studio version %s" % self.__version
         else:
-            self.__root = r"Software\Microsoft\Devstudio"
+            # Win64. Assume this was built with the platform SDK
+            self.__product = "Microsoft SDK compiler %s" % (self.__version + 6)
+            
         self.initialized = False
 
     def initialize(self):
@@ -228,9 +250,9 @@
 
             if len (self.__paths) == 0:
                 raise DistutilsPlatformError, \
-                      ("Python was built with version %s of Visual Studio, "
+                      ("Python was built with %s, "
                        "and extensions need to be built with the same "
-                       "version of the compiler, but it isn't installed." % self.__version)
+                       "version of the compiler, but it isn't installed." % self.__product)
 
             self.cc = self.find_exe("cl.exe")
             self.linker = self.find_exe("link.exe")
@@ -249,10 +271,17 @@
         os.environ['path'] = string.join(self.__paths, ';')
 
         self.preprocess_options = None
-        self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' ,
-                                 '/DNDEBUG']
-        self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
-                                      '/Z7', '/D_DEBUG']
+        if self.__arch == "Intel":
+            self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' ,
+                                     '/DNDEBUG']
+            self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
+                                          '/Z7', '/D_DEBUG']
+        else:
+            # Win64
+            self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
+                                     '/DNDEBUG']
+            self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
+                                          '/Z7', '/D_DEBUG']            
 
         self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
         if self.__version >= 7:


More information about the Python-checkins mailing list