Greg Ward | bfc79d6 | 2000-06-28 01:29:09 +0000 | [diff] [blame] | 1 | """distutils.msvccompiler |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 2 | |
| 3 | Contains MSVCCompiler, an implementation of the abstract CCompiler class |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 4 | for the Microsoft Visual Studio.""" |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 5 | |
| 6 | |
| 7 | # created 1999/08/19, Perry Stoll |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 8 | # hacked by Robin Becker and Thomas Heller to do a better job of |
| 9 | # finding DevStudio (through the registry) |
| 10 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 11 | __revision__ = "$Id$" |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 12 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 13 | import sys, os, string |
| 14 | from types import * |
Greg Ward | 3add77f | 2000-05-30 02:02:49 +0000 | [diff] [blame] | 15 | from distutils.errors import \ |
| 16 | DistutilsExecError, DistutilsPlatformError, \ |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 17 | CompileError, LibError, LinkError |
Greg Ward | 3add77f | 2000-05-30 02:02:49 +0000 | [diff] [blame] | 18 | from distutils.ccompiler import \ |
| 19 | CCompiler, gen_preprocess_options, gen_lib_options |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 20 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 21 | _can_read_reg = 0 |
| 22 | try: |
Greg Ward | 83c3870 | 2000-06-29 23:04:59 +0000 | [diff] [blame^] | 23 | try: |
| 24 | import _winreg |
| 25 | except ImportError: |
| 26 | import winreg # for pre-2000/06/29 CVS Python |
| 27 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 28 | _can_read_reg = 1 |
Greg Ward | cd079c4 | 2000-06-29 22:59:10 +0000 | [diff] [blame] | 29 | hkey_mod = _winreg |
Greg Ward | 19ce166 | 2000-03-31 19:04:25 +0000 | [diff] [blame] | 30 | |
Greg Ward | cd079c4 | 2000-06-29 22:59:10 +0000 | [diff] [blame] | 31 | RegOpenKeyEx = _winreg.OpenKeyEx |
| 32 | RegEnumKey = _winreg.EnumKey |
| 33 | RegEnumValue = _winreg.EnumValue |
| 34 | RegError = _winreg.error |
Greg Ward | 19ce166 | 2000-03-31 19:04:25 +0000 | [diff] [blame] | 35 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 36 | except ImportError: |
| 37 | try: |
| 38 | import win32api |
| 39 | import win32con |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 40 | _can_read_reg = 1 |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 41 | hkey_mod = win32con |
Greg Ward | 19ce166 | 2000-03-31 19:04:25 +0000 | [diff] [blame] | 42 | |
| 43 | RegOpenKeyEx = win32api.RegOpenKeyEx |
| 44 | RegEnumKey = win32api.RegEnumKey |
| 45 | RegEnumValue = win32api.RegEnumValue |
| 46 | RegError = win32api.error |
| 47 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 48 | except ImportError: |
| 49 | pass |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 50 | |
| 51 | if _can_read_reg: |
| 52 | HKEY_CLASSES_ROOT = hkey_mod.HKEY_CLASSES_ROOT |
| 53 | HKEY_LOCAL_MACHINE = hkey_mod.HKEY_LOCAL_MACHINE |
| 54 | HKEY_CURRENT_USER = hkey_mod.HKEY_CURRENT_USER |
| 55 | HKEY_USERS = hkey_mod.HKEY_USERS |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 56 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 57 | |
| 58 | |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 59 | def get_devstudio_versions (): |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 60 | """Get list of devstudio versions from the Windows registry. Return a |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 61 | list of strings containing version numbers; the list will be |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 62 | empty if we were unable to access the registry (eg. couldn't import |
| 63 | a registry-access module) or the appropriate registry keys weren't |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 64 | found.""" |
| 65 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 66 | if not _can_read_reg: |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 67 | return [] |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 68 | |
| 69 | K = 'Software\\Microsoft\\Devstudio' |
| 70 | L = [] |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 71 | for base in (HKEY_CLASSES_ROOT, |
| 72 | HKEY_LOCAL_MACHINE, |
| 73 | HKEY_CURRENT_USER, |
| 74 | HKEY_USERS): |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 75 | try: |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 76 | k = RegOpenKeyEx(base,K) |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 77 | i = 0 |
| 78 | while 1: |
| 79 | try: |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 80 | p = RegEnumKey(k,i) |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 81 | if p[0] in '123456789' and p not in L: |
| 82 | L.append(p) |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 83 | except RegError: |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 84 | break |
| 85 | i = i + 1 |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 86 | except RegError: |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 87 | pass |
| 88 | L.sort() |
| 89 | L.reverse() |
| 90 | return L |
| 91 | |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 92 | # get_devstudio_versions () |
| 93 | |
| 94 | |
| 95 | def get_msvc_paths (path, version='6.0', platform='x86'): |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 96 | """Get a list of devstudio directories (include, lib or path). Return |
| 97 | a list of strings; will be empty list if unable to access the |
| 98 | registry or appropriate registry keys not found.""" |
| 99 | |
Greg Ward | 7642f5c | 2000-03-31 16:47:40 +0000 | [diff] [blame] | 100 | if not _can_read_reg: |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 101 | return [] |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 102 | |
| 103 | L = [] |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 104 | if path=='lib': |
| 105 | path= 'Library' |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 106 | path = string.upper(path + ' Dirs') |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 107 | K = ('Software\\Microsoft\\Devstudio\\%s\\' + |
| 108 | 'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \ |
| 109 | (version,platform) |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 110 | for base in (HKEY_CLASSES_ROOT, |
| 111 | HKEY_LOCAL_MACHINE, |
| 112 | HKEY_CURRENT_USER, |
| 113 | HKEY_USERS): |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 114 | try: |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 115 | k = RegOpenKeyEx(base,K) |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 116 | i = 0 |
| 117 | while 1: |
| 118 | try: |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 119 | (p,v,t) = RegEnumValue(k,i) |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 120 | if string.upper(p) == path: |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 121 | V = string.split(v,';') |
| 122 | for v in V: |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 123 | if v == '' or v in L: continue |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 124 | L.append(v) |
| 125 | break |
| 126 | i = i + 1 |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 127 | except RegError: |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 128 | break |
Greg Ward | 1027e3f | 2000-03-31 16:53:42 +0000 | [diff] [blame] | 129 | except RegError: |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 130 | pass |
| 131 | return L |
| 132 | |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 133 | # get_msvc_paths() |
| 134 | |
| 135 | |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 136 | def find_exe (exe, version_number): |
| 137 | """Try to find an MSVC executable program 'exe' (from version |
| 138 | 'version_number' of MSVC) in several places: first, one of the MSVC |
| 139 | program search paths from the registry; next, the directories in the |
| 140 | PATH environment variable. If any of those work, return an absolute |
| 141 | path that is known to exist. If none of them work, just return the |
| 142 | original program name, 'exe'.""" |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 143 | |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 144 | for p in get_msvc_paths ('path', version_number): |
| 145 | fn = os.path.join (os.path.abspath(p), exe) |
| 146 | if os.path.isfile(fn): |
| 147 | return fn |
| 148 | |
| 149 | # didn't find it; try existing path |
| 150 | for p in string.split (os.environ['Path'],';'): |
| 151 | fn = os.path.join(os.path.abspath(p),exe) |
| 152 | if os.path.isfile(fn): |
| 153 | return fn |
| 154 | |
| 155 | return exe # last desperate hope |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 156 | |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 157 | |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 158 | def set_path_env_var (name, version_number): |
| 159 | """Set environment variable 'name' to an MSVC path type value obtained |
| 160 | from 'get_msvc_paths()'. This is equivalent to a SET command prior |
| 161 | to execution of spawned commands.""" |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 162 | |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 163 | p = get_msvc_paths (name, version_number) |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 164 | if p: |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 165 | os.environ[name] = string.join (p,';') |
Greg Ward | 62e3393 | 2000-02-10 02:52:42 +0000 | [diff] [blame] | 166 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 167 | |
Greg Ward | 3d50b90 | 1999-09-08 02:36:01 +0000 | [diff] [blame] | 168 | class MSVCCompiler (CCompiler) : |
| 169 | """Concrete class that implements an interface to Microsoft Visual C++, |
| 170 | as defined by the CCompiler abstract class.""" |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 171 | |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 172 | compiler_type = 'msvc' |
| 173 | |
Greg Ward | 992c8f9 | 2000-06-25 02:31:16 +0000 | [diff] [blame] | 174 | # Just set this so CCompiler's constructor doesn't barf. We currently |
| 175 | # don't use the 'set_executables()' bureaucracy provided by CCompiler, |
| 176 | # as it really isn't necessary for this sort of single-compiler class. |
| 177 | # Would be nice to have a consistent interface with UnixCCompiler, |
| 178 | # though, so it's worth thinking about. |
| 179 | executables = {} |
| 180 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 181 | # Private class data (need to distinguish C from C++ source for compiler) |
| 182 | _c_extensions = ['.c'] |
| 183 | _cpp_extensions = ['.cc','.cpp'] |
| 184 | |
| 185 | # Needed for the filename generation methods provided by the |
| 186 | # base class, CCompiler. |
| 187 | src_extensions = _c_extensions + _cpp_extensions |
| 188 | obj_extension = '.obj' |
| 189 | static_lib_extension = '.lib' |
| 190 | shared_lib_extension = '.dll' |
| 191 | static_lib_format = shared_lib_format = '%s%s' |
| 192 | exe_extension = '.exe' |
| 193 | |
| 194 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 195 | def __init__ (self, |
| 196 | verbose=0, |
Greg Ward | c74138d | 1999-10-03 20:47:52 +0000 | [diff] [blame] | 197 | dry_run=0, |
| 198 | force=0): |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 199 | |
Greg Ward | c74138d | 1999-10-03 20:47:52 +0000 | [diff] [blame] | 200 | CCompiler.__init__ (self, verbose, dry_run, force) |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 201 | versions = get_devstudio_versions () |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 202 | |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 203 | if versions: |
| 204 | version = versions[0] # highest version |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 205 | |
Greg Ward | 41b4dd6 | 2000-03-29 04:13:00 +0000 | [diff] [blame] | 206 | self.cc = find_exe("cl.exe", version) |
| 207 | self.link = find_exe("link.exe", version) |
| 208 | self.lib = find_exe("lib.exe", version) |
Greg Ward | 5de8cee | 2000-02-11 02:52:39 +0000 | [diff] [blame] | 209 | set_path_env_var ('lib', version) |
| 210 | set_path_env_var ('include', version) |
| 211 | path=get_msvc_paths('path', version) |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 212 | try: |
| 213 | for p in string.split(os.environ['path'],';'): |
| 214 | path.append(p) |
| 215 | except KeyError: |
| 216 | pass |
| 217 | os.environ['path'] = string.join(path,';') |
| 218 | else: |
| 219 | # devstudio not found in the registry |
| 220 | self.cc = "cl.exe" |
| 221 | self.link = "link.exe" |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 222 | self.lib = "lib.exe" |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 223 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 224 | self.preprocess_options = None |
Greg Ward | 6998809 | 2000-02-11 02:47:15 +0000 | [diff] [blame] | 225 | self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3' ] |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 226 | self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/Z7', '/D_DEBUG'] |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 227 | |
Greg Ward | 1b9c6f7 | 2000-02-08 02:39:44 +0000 | [diff] [blame] | 228 | self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO'] |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 229 | self.ldflags_shared_debug = [ |
| 230 | '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG' |
| 231 | ] |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 232 | self.ldflags_static = [ '/nologo'] |
| 233 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 234 | |
| 235 | # -- Worker methods ------------------------------------------------ |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 236 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 237 | def compile (self, |
| 238 | sources, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 239 | output_dir=None, |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 240 | macros=None, |
Greg Ward | 0bdd90a | 1999-12-12 17:19:58 +0000 | [diff] [blame] | 241 | include_dirs=None, |
Greg Ward | 386b844 | 2000-02-09 02:18:39 +0000 | [diff] [blame] | 242 | debug=0, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 243 | extra_preargs=None, |
| 244 | extra_postargs=None): |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 245 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 246 | (output_dir, macros, include_dirs) = \ |
| 247 | self._fix_compile_args (output_dir, macros, include_dirs) |
| 248 | (objects, skip_sources) = self._prep_compile (sources, output_dir) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 249 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 250 | if extra_postargs is None: |
| 251 | extra_postargs = [] |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 252 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 253 | pp_opts = gen_preprocess_options (macros, include_dirs) |
| 254 | compile_opts = extra_preargs or [] |
| 255 | compile_opts.append ('/c') |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 256 | if debug: |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 257 | compile_opts.extend (self.compile_options_debug) |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 258 | else: |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 259 | compile_opts.extend (self.compile_options) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 260 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 261 | for i in range (len (sources)): |
| 262 | src = sources[i] ; obj = objects[i] |
| 263 | ext = (os.path.splitext (src))[1] |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 264 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 265 | if skip_sources[src]: |
| 266 | self.announce ("skipping %s (%s up-to-date)" % (src, obj)) |
| 267 | else: |
| 268 | if ext in self._c_extensions: |
| 269 | input_opt = "/Tc" + src |
| 270 | elif ext in self._cpp_extensions: |
| 271 | input_opt = "/Tp" + src |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 272 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 273 | output_opt = "/Fo" + obj |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 274 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 275 | self.mkpath (os.path.dirname (obj)) |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 276 | try: |
| 277 | self.spawn ([self.cc] + compile_opts + pp_opts + |
| 278 | [input_opt, output_opt] + |
| 279 | extra_postargs) |
| 280 | except DistutilsExecError, msg: |
| 281 | raise CompileError, msg |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 282 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 283 | return objects |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 284 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 285 | # compile () |
Greg Ward | 3d50b90 | 1999-09-08 02:36:01 +0000 | [diff] [blame] | 286 | |
| 287 | |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 288 | def create_static_lib (self, |
| 289 | objects, |
| 290 | output_libname, |
| 291 | output_dir=None, |
| 292 | debug=0, |
| 293 | extra_preargs=None, |
| 294 | extra_postargs=None): |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 295 | |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 296 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 297 | output_filename = \ |
| 298 | self.library_filename (output_libname, output_dir=output_dir) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 299 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 300 | if self._need_link (objects, output_filename): |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 301 | lib_args = objects + ['/OUT:' + output_filename] |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 302 | if debug: |
| 303 | pass # XXX what goes here? |
| 304 | if extra_preargs: |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 305 | lib_args[:0] = extra_preargs |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 306 | if extra_postargs: |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 307 | lib_args.extend (extra_postargs) |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 308 | try: |
Greg Ward | 992c8f9 | 2000-06-25 02:31:16 +0000 | [diff] [blame] | 309 | self.spawn ([self.lib] + lib_args) |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 310 | except DistutilsExecError, msg: |
| 311 | raise LibError, msg |
| 312 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 313 | else: |
| 314 | self.announce ("skipping %s (up-to-date)" % output_filename) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 315 | |
Greg Ward | 09fc542 | 2000-03-10 01:49:26 +0000 | [diff] [blame] | 316 | # create_static_lib () |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 317 | |
| 318 | |
| 319 | def link_shared_lib (self, |
| 320 | objects, |
| 321 | output_libname, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 322 | output_dir=None, |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 323 | libraries=None, |
| 324 | library_dirs=None, |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 325 | runtime_library_dirs=None, |
Greg Ward | 5299b6a | 2000-05-20 13:23:21 +0000 | [diff] [blame] | 326 | export_symbols=None, |
Greg Ward | 386b844 | 2000-02-09 02:18:39 +0000 | [diff] [blame] | 327 | debug=0, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 328 | extra_preargs=None, |
Greg Ward | bfc79d6 | 2000-06-28 01:29:09 +0000 | [diff] [blame] | 329 | extra_postargs=None, |
| 330 | build_temp=None): |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 331 | |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 332 | self.link_shared_object (objects, |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 333 | self.shared_library_name(output_libname), |
| 334 | output_dir=output_dir, |
| 335 | libraries=libraries, |
| 336 | library_dirs=library_dirs, |
Greg Ward | 5299b6a | 2000-05-20 13:23:21 +0000 | [diff] [blame] | 337 | runtime_library_dirs=runtime_library_dirs, |
| 338 | export_symbols=export_symbols, |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 339 | debug=debug, |
| 340 | extra_preargs=extra_preargs, |
Greg Ward | bfc79d6 | 2000-06-28 01:29:09 +0000 | [diff] [blame] | 341 | extra_postargs=extra_postargs, |
| 342 | build_temp=build_temp) |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 343 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 344 | |
| 345 | def link_shared_object (self, |
| 346 | objects, |
| 347 | output_filename, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 348 | output_dir=None, |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 349 | libraries=None, |
| 350 | library_dirs=None, |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 351 | runtime_library_dirs=None, |
Greg Ward | 5299b6a | 2000-05-20 13:23:21 +0000 | [diff] [blame] | 352 | export_symbols=None, |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 353 | debug=0, |
Greg Ward | df178f9 | 1999-09-29 12:29:10 +0000 | [diff] [blame] | 354 | extra_preargs=None, |
Greg Ward | bfc79d6 | 2000-06-28 01:29:09 +0000 | [diff] [blame] | 355 | extra_postargs=None, |
| 356 | build_temp=None): |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 357 | |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 358 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 359 | (libraries, library_dirs, runtime_library_dirs) = \ |
| 360 | self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) |
| 361 | |
Greg Ward | f70c603 | 2000-04-19 02:16:49 +0000 | [diff] [blame] | 362 | if runtime_library_dirs: |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 363 | self.warn ("I don't know what to do with 'runtime_library_dirs': " |
| 364 | + str (runtime_library_dirs)) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 365 | |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 366 | lib_opts = gen_lib_options (self, |
Greg Ward | 2f557a2 | 2000-03-26 21:42:28 +0000 | [diff] [blame] | 367 | library_dirs, runtime_library_dirs, |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 368 | libraries) |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 369 | if output_dir is not None: |
| 370 | output_filename = os.path.join (output_dir, output_filename) |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 371 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 372 | if self._need_link (objects, output_filename): |
| 373 | |
| 374 | if debug: |
| 375 | ldflags = self.ldflags_shared_debug |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 376 | else: |
| 377 | ldflags = self.ldflags_shared |
| 378 | |
Greg Ward | 5299b6a | 2000-05-20 13:23:21 +0000 | [diff] [blame] | 379 | export_opts = [] |
| 380 | for sym in (export_symbols or []): |
| 381 | export_opts.append("/EXPORT:" + sym) |
| 382 | |
| 383 | ld_args = (ldflags + lib_opts + export_opts + |
| 384 | objects + ['/OUT:' + output_filename]) |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 385 | |
| 386 | if extra_preargs: |
| 387 | ld_args[:0] = extra_preargs |
| 388 | if extra_postargs: |
| 389 | ld_args.extend (extra_postargs) |
| 390 | |
Greg Ward | 02a1a2b | 2000-04-15 22:15:07 +0000 | [diff] [blame] | 391 | print "link_shared_object():" |
| 392 | print " output_filename =", output_filename |
| 393 | print " mkpath'ing:", os.path.dirname (output_filename) |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 394 | self.mkpath (os.path.dirname (output_filename)) |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 395 | try: |
| 396 | self.spawn ([self.link] + ld_args) |
| 397 | except DistutilsExecError, msg: |
| 398 | raise LinkError, msg |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 399 | |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 400 | else: |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 401 | self.announce ("skipping %s (up-to-date)" % output_filename) |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 402 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 403 | # link_shared_object () |
Greg Ward | f70c603 | 2000-04-19 02:16:49 +0000 | [diff] [blame] | 404 | |
| 405 | |
| 406 | def link_executable (self, |
| 407 | objects, |
| 408 | output_progname, |
| 409 | output_dir=None, |
| 410 | libraries=None, |
| 411 | library_dirs=None, |
| 412 | runtime_library_dirs=None, |
| 413 | debug=0, |
| 414 | extra_preargs=None, |
| 415 | extra_postargs=None): |
| 416 | |
| 417 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 418 | (libraries, library_dirs, runtime_library_dirs) = \ |
| 419 | self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) |
| 420 | |
| 421 | if runtime_library_dirs: |
| 422 | self.warn ("I don't know what to do with 'runtime_library_dirs': " |
| 423 | + str (runtime_library_dirs)) |
| 424 | |
| 425 | lib_opts = gen_lib_options (self, |
| 426 | library_dirs, runtime_library_dirs, |
| 427 | libraries) |
| 428 | output_filename = output_progname + self.exe_extension |
| 429 | if output_dir is not None: |
| 430 | output_filename = os.path.join (output_dir, output_filename) |
| 431 | |
| 432 | if self._need_link (objects, output_filename): |
| 433 | |
| 434 | if debug: |
| 435 | ldflags = self.ldflags_shared_debug[1:] |
| 436 | else: |
| 437 | ldflags = self.ldflags_shared[1:] |
| 438 | |
| 439 | ld_args = ldflags + lib_opts + \ |
| 440 | objects + ['/OUT:' + output_filename] |
| 441 | |
| 442 | if extra_preargs: |
| 443 | ld_args[:0] = extra_preargs |
| 444 | if extra_postargs: |
| 445 | ld_args.extend (extra_postargs) |
| 446 | |
| 447 | self.mkpath (os.path.dirname (output_filename)) |
Greg Ward | d151711 | 2000-05-30 01:56:44 +0000 | [diff] [blame] | 448 | try: |
| 449 | self.spawn ([self.link] + ld_args) |
| 450 | except DistutilsExecError, msg: |
| 451 | raise LinkError, msg |
Greg Ward | f70c603 | 2000-04-19 02:16:49 +0000 | [diff] [blame] | 452 | else: |
| 453 | self.announce ("skipping %s (up-to-date)" % output_filename) |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 454 | |
Greg Ward | 4ba9b2e | 2000-02-10 02:15:52 +0000 | [diff] [blame] | 455 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 456 | # -- Miscellaneous methods ----------------------------------------- |
| 457 | # These are all used by the 'gen_lib_options() function, in |
| 458 | # ccompiler.py. |
Greg Ward | c74138d | 1999-10-03 20:47:52 +0000 | [diff] [blame] | 459 | |
| 460 | def library_dir_option (self, dir): |
| 461 | return "/LIBPATH:" + dir |
| 462 | |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 463 | def runtime_library_dir_option (self, dir): |
| 464 | raise DistutilsPlatformError, \ |
| 465 | "don't know how to set runtime library search path for MSVC++" |
| 466 | |
Greg Ward | c74138d | 1999-10-03 20:47:52 +0000 | [diff] [blame] | 467 | def library_option (self, lib): |
| 468 | return self.library_filename (lib) |
| 469 | |
| 470 | |
| 471 | def find_library_file (self, dirs, lib): |
| 472 | |
| 473 | for dir in dirs: |
| 474 | libfile = os.path.join (dir, self.library_filename (lib)) |
| 475 | if os.path.exists (libfile): |
| 476 | return libfile |
| 477 | |
| 478 | else: |
| 479 | # Oops, didn't find it in *any* of 'dirs' |
| 480 | return None |
| 481 | |
| 482 | # find_library_file () |
| 483 | |
Greg Ward | dbd1276 | 1999-08-29 18:15:07 +0000 | [diff] [blame] | 484 | # class MSVCCompiler |