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