Chris@87: """ Chris@87: Support code for building Python extensions on Windows. Chris@87: Chris@87: # NT stuff Chris@87: # 1. Make sure libpython.a exists for gcc. If not, build it. Chris@87: # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) Chris@87: # 3. Force windows to use g77 Chris@87: Chris@87: """ Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import os Chris@87: import sys Chris@87: import subprocess Chris@87: import re Chris@87: Chris@87: # Overwrite certain distutils.ccompiler functions: Chris@87: import numpy.distutils.ccompiler Chris@87: Chris@87: if sys.version_info[0] < 3: Chris@87: from . import log Chris@87: else: Chris@87: from numpy.distutils import log Chris@87: # NT stuff Chris@87: # 1. Make sure libpython.a exists for gcc. If not, build it. Chris@87: # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) Chris@87: # --> this is done in numpy/distutils/ccompiler.py Chris@87: # 3. Force windows to use g77 Chris@87: Chris@87: import distutils.cygwinccompiler Chris@87: from distutils.version import StrictVersion Chris@87: from numpy.distutils.ccompiler import gen_preprocess_options, gen_lib_options Chris@87: from distutils.errors import DistutilsExecError, CompileError, UnknownFileError Chris@87: Chris@87: from distutils.unixccompiler import UnixCCompiler Chris@87: from distutils.msvccompiler import get_build_version as get_build_msvc_version Chris@87: from numpy.distutils.misc_util import msvc_runtime_library, get_build_architecture Chris@87: Chris@87: # Useful to generate table of symbols from a dll Chris@87: _START = re.compile(r'\[Ordinal/Name Pointer\] Table') Chris@87: _TABLE = re.compile(r'^\s+\[([\s*[0-9]*)\] ([a-zA-Z0-9_]*)') Chris@87: Chris@87: # the same as cygwin plus some additional parameters Chris@87: class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler): Chris@87: """ A modified MingW32 compiler compatible with an MSVC built Python. Chris@87: Chris@87: """ Chris@87: Chris@87: compiler_type = 'mingw32' Chris@87: Chris@87: def __init__ (self, Chris@87: verbose=0, Chris@87: dry_run=0, Chris@87: force=0): Chris@87: Chris@87: distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, Chris@87: verbose, dry_run, force) Chris@87: Chris@87: # we need to support 3.2 which doesn't match the standard Chris@87: # get_versions methods regex Chris@87: if self.gcc_version is None: Chris@87: import re Chris@87: p = subprocess.Popen(['gcc', '-dumpversion'], shell=True, Chris@87: stdout=subprocess.PIPE) Chris@87: out_string = p.stdout.read() Chris@87: p.stdout.close() Chris@87: result = re.search('(\d+\.\d+)', out_string) Chris@87: if result: Chris@87: self.gcc_version = StrictVersion(result.group(1)) Chris@87: Chris@87: # A real mingw32 doesn't need to specify a different entry point, Chris@87: # but cygwin 2.91.57 in no-cygwin-mode needs it. Chris@87: if self.gcc_version <= "2.91.57": Chris@87: entry_point = '--entry _DllMain@12' Chris@87: else: Chris@87: entry_point = '' Chris@87: Chris@87: if self.linker_dll == 'dllwrap': Chris@87: # Commented out '--driver-name g++' part that fixes weird Chris@87: # g++.exe: g++: No such file or directory Chris@87: # error (mingw 1.0 in Enthon24 tree, gcc-3.4.5). Chris@87: # If the --driver-name part is required for some environment Chris@87: # then make the inclusion of this part specific to that environment. Chris@87: self.linker = 'dllwrap' # --driver-name g++' Chris@87: elif self.linker_dll == 'gcc': Chris@87: self.linker = 'g++' Chris@87: Chris@87: # **changes: eric jones 4/11/01 Chris@87: # 1. Check for import library on Windows. Build if it doesn't exist. Chris@87: Chris@87: build_import_library() Chris@87: Chris@87: # Check for custom msvc runtime library on Windows. Build if it doesn't exist. Chris@87: msvcr_success = build_msvcr_library() Chris@87: msvcr_dbg_success = build_msvcr_library(debug=True) Chris@87: if msvcr_success or msvcr_dbg_success: Chris@87: # add preprocessor statement for using customized msvcr lib Chris@87: self.define_macro('NPY_MINGW_USE_CUSTOM_MSVCR') Chris@87: Chris@87: # Define the MSVC version as hint for MinGW Chris@87: msvcr_version = '0x%03i0' % int(msvc_runtime_library().lstrip('msvcr')) Chris@87: self.define_macro('__MSVCRT_VERSION__', msvcr_version) Chris@87: Chris@87: # **changes: eric jones 4/11/01 Chris@87: # 2. increased optimization and turned off all warnings Chris@87: # 3. also added --driver-name g++ Chris@87: #self.set_executables(compiler='gcc -mno-cygwin -O2 -w', Chris@87: # compiler_so='gcc -mno-cygwin -mdll -O2 -w', Chris@87: # linker_exe='gcc -mno-cygwin', Chris@87: # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' Chris@87: # % (self.linker, entry_point)) Chris@87: Chris@87: # MS_WIN64 should be defined when building for amd64 on windows, but Chris@87: # python headers define it only for MS compilers, which has all kind of Chris@87: # bad consequences, like using Py_ModuleInit4 instead of Chris@87: # Py_ModuleInit4_64, etc... So we add it here Chris@87: if get_build_architecture() == 'AMD64': Chris@87: if self.gcc_version < "4.0": Chris@87: self.set_executables( Chris@87: compiler='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall', Chris@87: compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes', Chris@87: linker_exe='gcc -g -mno-cygwin', Chris@87: linker_so='gcc -g -mno-cygwin -shared') Chris@87: else: Chris@87: # gcc-4 series releases do not support -mno-cygwin option Chris@87: self.set_executables( Chris@87: compiler='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall', Chris@87: compiler_so='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypes', Chris@87: linker_exe='gcc -g', Chris@87: linker_so='gcc -g -shared') Chris@87: else: Chris@87: if self.gcc_version <= "3.0.0": Chris@87: self.set_executables(compiler='gcc -mno-cygwin -O2 -w', Chris@87: compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes', Chris@87: linker_exe='g++ -mno-cygwin', Chris@87: linker_so='%s -mno-cygwin -mdll -static %s' Chris@87: % (self.linker, entry_point)) Chris@87: elif self.gcc_version < "4.0": Chris@87: self.set_executables(compiler='gcc -mno-cygwin -O2 -Wall', Chris@87: compiler_so='gcc -mno-cygwin -O2 -Wall -Wstrict-prototypes', Chris@87: linker_exe='g++ -mno-cygwin', Chris@87: linker_so='g++ -mno-cygwin -shared') Chris@87: else: Chris@87: # gcc-4 series releases do not support -mno-cygwin option Chris@87: self.set_executables(compiler='gcc -O2 -Wall', Chris@87: compiler_so='gcc -O2 -Wall -Wstrict-prototypes', Chris@87: linker_exe='g++ ', Chris@87: linker_so='g++ -shared') Chris@87: # added for python2.3 support Chris@87: # we can't pass it through set_executables because pre 2.2 would fail Chris@87: self.compiler_cxx = ['g++'] Chris@87: Chris@87: # Maybe we should also append -mthreads, but then the finished Chris@87: # dlls need another dll (mingwm10.dll see Mingw32 docs) Chris@87: # (-mthreads: Support thread-safe exception handling on `Mingw32') Chris@87: Chris@87: # no additional libraries needed Chris@87: #self.dll_libraries=[] Chris@87: return Chris@87: Chris@87: # __init__ () Chris@87: Chris@87: def link(self, Chris@87: target_desc, Chris@87: objects, Chris@87: output_filename, Chris@87: output_dir, Chris@87: libraries, Chris@87: library_dirs, Chris@87: runtime_library_dirs, Chris@87: export_symbols = None, Chris@87: debug=0, Chris@87: extra_preargs=None, Chris@87: extra_postargs=None, Chris@87: build_temp=None, Chris@87: target_lang=None): Chris@87: # Include the appropiate MSVC runtime library if Python was built Chris@87: # with MSVC >= 7.0 (MinGW standard is msvcrt) Chris@87: runtime_library = msvc_runtime_library() Chris@87: if runtime_library: Chris@87: if not libraries: Chris@87: libraries = [] Chris@87: libraries.append(runtime_library) Chris@87: args = (self, Chris@87: target_desc, Chris@87: objects, Chris@87: output_filename, Chris@87: output_dir, Chris@87: libraries, Chris@87: library_dirs, Chris@87: runtime_library_dirs, Chris@87: None, #export_symbols, we do this in our def-file Chris@87: debug, Chris@87: extra_preargs, Chris@87: extra_postargs, Chris@87: build_temp, Chris@87: target_lang) Chris@87: if self.gcc_version < "3.0.0": Chris@87: func = distutils.cygwinccompiler.CygwinCCompiler.link Chris@87: else: Chris@87: func = UnixCCompiler.link Chris@87: func(*args[:func.__code__.co_argcount]) Chris@87: return Chris@87: Chris@87: def object_filenames (self, Chris@87: source_filenames, Chris@87: strip_dir=0, Chris@87: output_dir=''): Chris@87: if output_dir is None: output_dir = '' Chris@87: obj_names = [] Chris@87: for src_name in source_filenames: Chris@87: # use normcase to make sure '.rc' is really '.rc' and not '.RC' Chris@87: (base, ext) = os.path.splitext (os.path.normcase(src_name)) Chris@87: Chris@87: # added these lines to strip off windows drive letters Chris@87: # without it, .o files are placed next to .c files Chris@87: # instead of the build directory Chris@87: drv, base = os.path.splitdrive(base) Chris@87: if drv: Chris@87: base = base[1:] Chris@87: Chris@87: if ext not in (self.src_extensions + ['.rc', '.res']): Chris@87: raise UnknownFileError( Chris@87: "unknown file type '%s' (from '%s')" % \ Chris@87: (ext, src_name)) Chris@87: if strip_dir: Chris@87: base = os.path.basename (base) Chris@87: if ext == '.res' or ext == '.rc': Chris@87: # these need to be compiled to object files Chris@87: obj_names.append (os.path.join (output_dir, Chris@87: base + ext + self.obj_extension)) Chris@87: else: Chris@87: obj_names.append (os.path.join (output_dir, Chris@87: base + self.obj_extension)) Chris@87: return obj_names Chris@87: Chris@87: # object_filenames () Chris@87: Chris@87: Chris@87: def find_python_dll(): Chris@87: maj, min, micro = [int(i) for i in sys.version_info[:3]] Chris@87: dllname = 'python%d%d.dll' % (maj, min) Chris@87: print("Looking for %s" % dllname) Chris@87: Chris@87: # We can't do much here: Chris@87: # - find it in python main dir Chris@87: # - in system32, Chris@87: # - ortherwise (Sxs), I don't know how to get it. Chris@87: lib_dirs = [] Chris@87: lib_dirs.append(sys.prefix) Chris@87: lib_dirs.append(os.path.join(sys.prefix, 'lib')) Chris@87: try: Chris@87: lib_dirs.append(os.path.join(os.environ['SYSTEMROOT'], 'system32')) Chris@87: except KeyError: Chris@87: pass Chris@87: Chris@87: for d in lib_dirs: Chris@87: dll = os.path.join(d, dllname) Chris@87: if os.path.exists(dll): Chris@87: return dll Chris@87: Chris@87: raise ValueError("%s not found in %s" % (dllname, lib_dirs)) Chris@87: Chris@87: def dump_table(dll): Chris@87: st = subprocess.Popen(["objdump.exe", "-p", dll], stdout=subprocess.PIPE) Chris@87: return st.stdout.readlines() Chris@87: Chris@87: def generate_def(dll, dfile): Chris@87: """Given a dll file location, get all its exported symbols and dump them Chris@87: into the given def file. Chris@87: Chris@87: The .def file will be overwritten""" Chris@87: dump = dump_table(dll) Chris@87: for i in range(len(dump)): Chris@87: if _START.match(dump[i].decode()): Chris@87: break Chris@87: else: Chris@87: raise ValueError("Symbol table not found") Chris@87: Chris@87: syms = [] Chris@87: for j in range(i+1, len(dump)): Chris@87: m = _TABLE.match(dump[j].decode()) Chris@87: if m: Chris@87: syms.append((int(m.group(1).strip()), m.group(2))) Chris@87: else: Chris@87: break Chris@87: Chris@87: if len(syms) == 0: Chris@87: log.warn('No symbols found in %s' % dll) Chris@87: Chris@87: d = open(dfile, 'w') Chris@87: d.write('LIBRARY %s\n' % os.path.basename(dll)) Chris@87: d.write(';CODE PRELOAD MOVEABLE DISCARDABLE\n') Chris@87: d.write(';DATA PRELOAD SINGLE\n') Chris@87: d.write('\nEXPORTS\n') Chris@87: for s in syms: Chris@87: #d.write('@%d %s\n' % (s[0], s[1])) Chris@87: d.write('%s\n' % s[1]) Chris@87: d.close() Chris@87: Chris@87: def find_dll(dll_name): Chris@87: Chris@87: arch = {'AMD64' : 'amd64', Chris@87: 'Intel' : 'x86'}[get_build_architecture()] Chris@87: Chris@87: def _find_dll_in_winsxs(dll_name): Chris@87: # Walk through the WinSxS directory to find the dll. Chris@87: winsxs_path = os.path.join(os.environ['WINDIR'], 'winsxs') Chris@87: if not os.path.exists(winsxs_path): Chris@87: return None Chris@87: for root, dirs, files in os.walk(winsxs_path): Chris@87: if dll_name in files and arch in root: Chris@87: return os.path.join(root, dll_name) Chris@87: return None Chris@87: Chris@87: def _find_dll_in_path(dll_name): Chris@87: # First, look in the Python directory, then scan PATH for Chris@87: # the given dll name. Chris@87: for path in [sys.prefix] + os.environ['PATH'].split(';'): Chris@87: filepath = os.path.join(path, dll_name) Chris@87: if os.path.exists(filepath): Chris@87: return os.path.abspath(filepath) Chris@87: Chris@87: return _find_dll_in_winsxs(dll_name) or _find_dll_in_path(dll_name) Chris@87: Chris@87: def build_msvcr_library(debug=False): Chris@87: if os.name != 'nt': Chris@87: return False Chris@87: Chris@87: msvcr_name = msvc_runtime_library() Chris@87: Chris@87: # Skip using a custom library for versions < MSVC 8.0 Chris@87: if int(msvcr_name.lstrip('msvcr')) < 80: Chris@87: log.debug('Skip building msvcr library: custom functionality not present') Chris@87: return False Chris@87: Chris@87: if debug: Chris@87: msvcr_name += 'd' Chris@87: Chris@87: # Skip if custom library already exists Chris@87: out_name = "lib%s.a" % msvcr_name Chris@87: out_file = os.path.join(sys.prefix, 'libs', out_name) Chris@87: if os.path.isfile(out_file): Chris@87: log.debug('Skip building msvcr library: "%s" exists' % (out_file)) Chris@87: return True Chris@87: Chris@87: # Find the msvcr dll Chris@87: msvcr_dll_name = msvcr_name + '.dll' Chris@87: dll_file = find_dll(msvcr_dll_name) Chris@87: if not dll_file: Chris@87: log.warn('Cannot build msvcr library: "%s" not found' % msvcr_dll_name) Chris@87: return False Chris@87: Chris@87: def_name = "lib%s.def" % msvcr_name Chris@87: def_file = os.path.join(sys.prefix, 'libs', def_name) Chris@87: Chris@87: log.info('Building msvcr library: "%s" (from %s)' \ Chris@87: % (out_file, dll_file)) Chris@87: Chris@87: # Generate a symbol definition file from the msvcr dll Chris@87: generate_def(dll_file, def_file) Chris@87: Chris@87: # Create a custom mingw library for the given symbol definitions Chris@87: cmd = ['dlltool', '-d', def_file, '-l', out_file] Chris@87: retcode = subprocess.call(cmd) Chris@87: Chris@87: # Clean up symbol definitions Chris@87: os.remove(def_file) Chris@87: Chris@87: return (not retcode) Chris@87: Chris@87: def build_import_library(): Chris@87: if os.name != 'nt': Chris@87: return Chris@87: Chris@87: arch = get_build_architecture() Chris@87: if arch == 'AMD64': Chris@87: return _build_import_library_amd64() Chris@87: elif arch == 'Intel': Chris@87: return _build_import_library_x86() Chris@87: else: Chris@87: raise ValueError("Unhandled arch %s" % arch) Chris@87: Chris@87: def _build_import_library_amd64(): Chris@87: dll_file = find_python_dll() Chris@87: Chris@87: out_name = "libpython%d%d.a" % tuple(sys.version_info[:2]) Chris@87: out_file = os.path.join(sys.prefix, 'libs', out_name) Chris@87: if os.path.isfile(out_file): Chris@87: log.debug('Skip building import library: "%s" exists' % (out_file)) Chris@87: return Chris@87: Chris@87: def_name = "python%d%d.def" % tuple(sys.version_info[:2]) Chris@87: def_file = os.path.join(sys.prefix, 'libs', def_name) Chris@87: Chris@87: log.info('Building import library (arch=AMD64): "%s" (from %s)' \ Chris@87: % (out_file, dll_file)) Chris@87: Chris@87: generate_def(dll_file, def_file) Chris@87: Chris@87: cmd = ['dlltool', '-d', def_file, '-l', out_file] Chris@87: subprocess.Popen(cmd) Chris@87: Chris@87: def _build_import_library_x86(): Chris@87: """ Build the import libraries for Mingw32-gcc on Windows Chris@87: """ Chris@87: lib_name = "python%d%d.lib" % tuple(sys.version_info[:2]) Chris@87: lib_file = os.path.join(sys.prefix, 'libs', lib_name) Chris@87: out_name = "libpython%d%d.a" % tuple(sys.version_info[:2]) Chris@87: out_file = os.path.join(sys.prefix, 'libs', out_name) Chris@87: if not os.path.isfile(lib_file): Chris@87: log.warn('Cannot build import library: "%s" not found' % (lib_file)) Chris@87: return Chris@87: if os.path.isfile(out_file): Chris@87: log.debug('Skip building import library: "%s" exists' % (out_file)) Chris@87: return Chris@87: log.info('Building import library (ARCH=x86): "%s"' % (out_file)) Chris@87: Chris@87: from numpy.distutils import lib2def Chris@87: Chris@87: def_name = "python%d%d.def" % tuple(sys.version_info[:2]) Chris@87: def_file = os.path.join(sys.prefix, 'libs', def_name) Chris@87: nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file) Chris@87: nm_output = lib2def.getnm(nm_cmd) Chris@87: dlist, flist = lib2def.parse_nm(nm_output) Chris@87: lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w')) Chris@87: Chris@87: dll_name = "python%d%d.dll" % tuple(sys.version_info[:2]) Chris@87: args = (dll_name, def_file, out_file) Chris@87: cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args Chris@87: status = os.system(cmd) Chris@87: # for now, fail silently Chris@87: if status: Chris@87: log.warn('Failed to build import library for gcc. Linking will fail.') Chris@87: #if not success: Chris@87: # msg = "Couldn't find import library, and failed to build it." Chris@87: # raise DistutilsPlatformError(msg) Chris@87: return Chris@87: Chris@87: #===================================== Chris@87: # Dealing with Visual Studio MANIFESTS Chris@87: #===================================== Chris@87: Chris@87: # Functions to deal with visual studio manifests. Manifest are a mechanism to Chris@87: # enforce strong DLL versioning on windows, and has nothing to do with Chris@87: # distutils MANIFEST. manifests are XML files with version info, and used by Chris@87: # the OS loader; they are necessary when linking against a DLL not in the Chris@87: # system path; in particular, official python 2.6 binary is built against the Chris@87: # MS runtime 9 (the one from VS 2008), which is not available on most windows Chris@87: # systems; python 2.6 installer does install it in the Win SxS (Side by side) Chris@87: # directory, but this requires the manifest for this to work. This is a big Chris@87: # mess, thanks MS for a wonderful system. Chris@87: Chris@87: # XXX: ideally, we should use exactly the same version as used by python. I Chris@87: # submitted a patch to get this version, but it was only included for python Chris@87: # 2.6.1 and above. So for versions below, we use a "best guess". Chris@87: _MSVCRVER_TO_FULLVER = {} Chris@87: if sys.platform == 'win32': Chris@87: try: Chris@87: import msvcrt Chris@87: # I took one version in my SxS directory: no idea if it is the good Chris@87: # one, and we can't retrieve it from python Chris@87: _MSVCRVER_TO_FULLVER['80'] = "8.0.50727.42" Chris@87: _MSVCRVER_TO_FULLVER['90'] = "9.0.21022.8" Chris@87: # Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0 on Windows XP: Chris@87: _MSVCRVER_TO_FULLVER['100'] = "10.0.30319.460" Chris@87: if hasattr(msvcrt, "CRT_ASSEMBLY_VERSION"): Chris@87: major, minor, rest = msvcrt.CRT_ASSEMBLY_VERSION.split(".", 2) Chris@87: _MSVCRVER_TO_FULLVER[major + minor] = msvcrt.CRT_ASSEMBLY_VERSION Chris@87: del major, minor, rest Chris@87: except ImportError: Chris@87: # If we are here, means python was not built with MSVC. Not sure what to do Chris@87: # in that case: manifest building will fail, but it should not be used in Chris@87: # that case anyway Chris@87: log.warn('Cannot import msvcrt: using manifest will not be possible') Chris@87: Chris@87: def msvc_manifest_xml(maj, min): Chris@87: """Given a major and minor version of the MSVCR, returns the Chris@87: corresponding XML file.""" Chris@87: try: Chris@87: fullver = _MSVCRVER_TO_FULLVER[str(maj * 10 + min)] Chris@87: except KeyError: Chris@87: raise ValueError("Version %d,%d of MSVCRT not supported yet" \ Chris@87: % (maj, min)) Chris@87: # Don't be fooled, it looks like an XML, but it is not. In particular, it Chris@87: # should not have any space before starting, and its size should be Chris@87: # divisible by 4, most likely for alignement constraints when the xml is Chris@87: # embedded in the binary... Chris@87: # This template was copied directly from the python 2.6 binary (using Chris@87: # strings.exe from mingw on python.exe). Chris@87: template = """\ Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: Chris@87: """ Chris@87: Chris@87: return template % {'fullver': fullver, 'maj': maj, 'min': min} Chris@87: Chris@87: def manifest_rc(name, type='dll'): Chris@87: """Return the rc file used to generate the res file which will be embedded Chris@87: as manifest for given manifest file name, of given type ('dll' or Chris@87: 'exe'). Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: name : str Chris@87: name of the manifest file to embed Chris@87: type : str {'dll', 'exe'} Chris@87: type of the binary which will embed the manifest Chris@87: Chris@87: """ Chris@87: if type == 'dll': Chris@87: rctype = 2 Chris@87: elif type == 'exe': Chris@87: rctype = 1 Chris@87: else: Chris@87: raise ValueError("Type %s not supported" % type) Chris@87: Chris@87: return """\ Chris@87: #include "winuser.h" Chris@87: %d RT_MANIFEST %s""" % (rctype, name) Chris@87: Chris@87: def check_embedded_msvcr_match_linked(msver): Chris@87: """msver is the ms runtime version used for the MANIFEST.""" Chris@87: # check msvcr major version are the same for linking and Chris@87: # embedding Chris@87: msvcv = msvc_runtime_library() Chris@87: if msvcv: Chris@87: assert msvcv.startswith("msvcr"), msvcv Chris@87: # Dealing with something like "mscvr90" or "mscvr100", the last Chris@87: # last digit is the minor release, want int("9") or int("10"): Chris@87: maj = int(msvcv[5:-1]) Chris@87: if not maj == int(msver): Chris@87: raise ValueError( Chris@87: "Discrepancy between linked msvcr " \ Chris@87: "(%d) and the one about to be embedded " \ Chris@87: "(%d)" % (int(msver), maj)) Chris@87: Chris@87: def configtest_name(config): Chris@87: base = os.path.basename(config._gen_temp_sourcefile("yo", [], "c")) Chris@87: return os.path.splitext(base)[0] Chris@87: Chris@87: def manifest_name(config): Chris@87: # Get configest name (including suffix) Chris@87: root = configtest_name(config) Chris@87: exext = config.compiler.exe_extension Chris@87: return root + exext + ".manifest" Chris@87: Chris@87: def rc_name(config): Chris@87: # Get configest name (including suffix) Chris@87: root = configtest_name(config) Chris@87: return root + ".rc" Chris@87: Chris@87: def generate_manifest(config): Chris@87: msver = get_build_msvc_version() Chris@87: if msver is not None: Chris@87: if msver >= 8: Chris@87: check_embedded_msvcr_match_linked(msver) Chris@87: ma = int(msver) Chris@87: mi = int((msver - ma) * 10) Chris@87: # Write the manifest file Chris@87: manxml = msvc_manifest_xml(ma, mi) Chris@87: man = open(manifest_name(config), "w") Chris@87: config.temp_files.append(manifest_name(config)) Chris@87: man.write(manxml) Chris@87: man.close() Chris@87: # # Write the rc file Chris@87: # manrc = manifest_rc(manifest_name(self), "exe") Chris@87: # rc = open(rc_name(self), "w") Chris@87: # self.temp_files.append(manrc) Chris@87: # rc.write(manrc) Chris@87: # rc.close()