diff options
author | Han <hangenuit@gmail.com> | 2011-09-14 14:39:12 +0200 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-10-04 11:29:31 -0600 |
commit | 2b248e51f6522a21260c2b752a117b7927046793 (patch) | |
tree | 09ab31e76b508f7324709ba4ce4787eab829c9bb /numpy | |
parent | 2e899dd23bc36ffad5590c8bc11de22d51a16966 (diff) | |
download | numpy-2b248e51f6522a21260c2b752a117b7927046793.tar.gz |
ENH: Generate custom MSCV runtime library for mingw32.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/distutils/mingw32ccompiler.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py index 5b352c300..c21b66478 100644 --- a/numpy/distutils/mingw32ccompiler.py +++ b/numpy/distutils/mingw32ccompiler.py @@ -90,6 +90,11 @@ class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler): build_import_library() + # Check for custom msvc runtime library on Windows. Build if it doesn't exist. + if build_msvcr_library(): + # add preprocessor statement for using customized msvcr lib + self.define_macro('NPY_MINGW_USE_CUSTOM_MSVCR', '1') + # **changes: eric jones 4/11/01 # 2. increased optimization and turned off all warnings # 3. also added --driver-name g++ @@ -290,6 +295,47 @@ def generate_def(dll, dfile): d.write('%s\n' % s[1]) d.close() +def find_msvcr_dll(msvcr_dll_name): + for path in [sys.prefix] + os.environ['PATH'].split(';'): + filepath = os.path.join(path, msvcr_dll_name) + if os.path.exists(filepath): + return os.path.abspath(filepath) + return None + +def build_msvcr_library(debug=False): + if os.name != 'nt': + return False + + if debug: + log.warn('Cannot build msvcr-dbg library: not yet implemented') + return False + + msvcr_name = msvc_runtime_library() + msvcr_dll_name = msvcr_name + '.dll' + dll_file = find_msvcr_dll(msvcr_dll_name) + if not dll_file: + log.warn('Cannot build msvcr library: "%s" not found' % msvcr_dll_name) + return False + + out_name = "lib%s.a" % msvcr_name + out_file = os.path.join(sys.prefix, 'libs', out_name) + if os.path.isfile(out_file): + log.debug('Skip building msvcr library: "%s" exists' % (out_file)) + return True + + def_name = "lib%s.def" % msvcr_name + def_file = os.path.join(sys.prefix, 'libs', def_name) + + log.info('Building msvcr library: "%s" (from %s)' \ + % (out_file, dll_file)) + + generate_def(dll_file, def_file) + + cmd = ['dlltool', '-d', def_file, '-l', out_file] + retcode = subprocess.call(cmd) + + return (not retcode) + def build_import_library(): if os.name != 'nt': return |