summaryrefslogtreecommitdiff
path: root/numpy/distutils/command/build_clib.py
diff options
context:
space:
mode:
authorxoviat <xoviat@users.noreply.github.com>2017-07-22 15:30:07 -0500
committerPauli Virtanen <pav@iki.fi>2017-09-02 16:56:22 +0300
commitf3c8a0ab23966cae9992dae74da96807a44bc0d8 (patch)
tree8d00247115affdcb9d8f5b1b8c88586946b9143b /numpy/distutils/command/build_clib.py
parent11593aa176d491beb0cc5ffcc393956a5435a2bf (diff)
downloadnumpy-f3c8a0ab23966cae9992dae74da96807a44bc0d8.tar.gz
distutils: gnu: patch fcompile
This allows mingw's gfortran to work with MSVC. DLLs are autogenerated using heuristics that should work with most cases. In addition, a libopenblas DLL is compiled from the static lib for use with MSVC. All generated DLLs have randomized names so that no clashes will occur.
Diffstat (limited to 'numpy/distutils/command/build_clib.py')
-rw-r--r--numpy/distutils/command/build_clib.py78
1 files changed, 46 insertions, 32 deletions
diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py
index 1c868cf6c..594c3f67f 100644
--- a/numpy/distutils/command/build_clib.py
+++ b/numpy/distutils/command/build_clib.py
@@ -7,21 +7,22 @@ from glob import glob
import shutil
from distutils.command.build_clib import build_clib as old_build_clib
from distutils.errors import DistutilsSetupError, DistutilsError, \
- DistutilsFileError
+ DistutilsFileError
from numpy.distutils import log
from distutils.dep_util import newer_group
from numpy.distutils.misc_util import filter_sources, has_f_sources,\
- has_cxx_sources, all_strings, get_lib_source_files, is_sequence, \
- get_numpy_include_dirs
+ has_cxx_sources, all_strings, get_lib_source_files, is_sequence, \
+ get_numpy_include_dirs, get_library_names
# Fix Python distutils bug sf #1718574:
_l = old_build_clib.user_options
for _i in range(len(_l)):
if _l[_i][0] in ['build-clib', 'build-temp']:
- _l[_i] = (_l[_i][0]+'=',)+_l[_i][1:]
+ _l[_i] = (_l[_i][0] + '=',) + _l[_i][1:]
#
+
class build_clib(old_build_clib):
description = "build C/C++/F libraries used by Python extensions"
@@ -32,7 +33,7 @@ class build_clib(old_build_clib):
('inplace', 'i', 'Build in-place'),
('parallel=', 'j',
"number of parallel jobs"),
- ]
+ ]
boolean_options = old_build_clib.boolean_options + ['inplace']
@@ -75,7 +76,8 @@ class build_clib(old_build_clib):
for (lib_name, build_info) in self.libraries:
l = build_info.get('language', None)
- if l and l not in languages: languages.append(l)
+ if l and l not in languages:
+ languages.append(l)
from distutils.ccompiler import new_compiler
self.compiler = new_compiler(compiler=self.compiler,
@@ -94,11 +96,11 @@ class build_clib(old_build_clib):
if self.have_f_sources():
from numpy.distutils.fcompiler import new_fcompiler
self._f_compiler = new_fcompiler(compiler=self.fcompiler,
- verbose=self.verbose,
- dry_run=self.dry_run,
- force=self.force,
- requiref90='f90' in languages,
- c_compiler=self.compiler)
+ verbose=self.verbose,
+ dry_run=self.dry_run,
+ force=self.force,
+ requiref90='f90' in languages,
+ c_compiler=self.compiler)
if self._f_compiler is not None:
self._f_compiler.customize(self.distribution)
@@ -114,10 +116,10 @@ class build_clib(old_build_clib):
self.build_libraries(self.libraries)
if self.inplace:
- for l in self.distribution.installed_libraries:
+ for l in self.distribution.installed_libraries:
libname = self.compiler.library_filename(l.name)
source = os.path.join(self.build_clib, libname)
- target = os.path.join(l.target_dir, libname)
+ target = os.path.join(l.target_dir, libname)
self.mkpath(l.target_dir)
shutil.copy(source, target)
@@ -129,6 +131,11 @@ class build_clib(old_build_clib):
return filenames
def build_libraries(self, libraries):
+ library_names = get_library_names()
+ library_order = {v: k for k, v in enumerate(library_names)}
+ libraries = sorted(
+ libraries, key=lambda library: library_order[library[0]])
+
for (lib_name, build_info) in libraries:
self.build_a_library(build_info, lib_name, libraries)
@@ -140,21 +147,25 @@ class build_clib(old_build_clib):
sources = build_info.get('sources')
if sources is None or not is_sequence(sources):
raise DistutilsSetupError(("in 'libraries' option (library '%s'), " +
- "'sources' must be present and must be " +
- "a list of source filenames") % lib_name)
+ "'sources' must be present and must be " +
+ "a list of source filenames") % lib_name)
sources = list(sources)
c_sources, cxx_sources, f_sources, fmodule_sources \
- = filter_sources(sources)
+ = filter_sources(sources)
requiref90 = not not fmodule_sources or \
- build_info.get('language', 'c')=='f90'
+ build_info.get('language', 'c') == 'f90'
# save source type information so that build_ext can use it.
source_languages = []
- if c_sources: source_languages.append('c')
- if cxx_sources: source_languages.append('c++')
- if requiref90: source_languages.append('f90')
- elif f_sources: source_languages.append('f77')
+ if c_sources:
+ source_languages.append('c')
+ if cxx_sources:
+ source_languages.append('c++')
+ if requiref90:
+ source_languages.append('f90')
+ elif f_sources:
+ source_languages.append('f77')
build_info['source_languages'] = source_languages
lib_file = compiler.library_filename(lib_name,
@@ -168,8 +179,8 @@ class build_clib(old_build_clib):
config_fc = build_info.get('config_fc', {})
if fcompiler is not None and config_fc:
- log.info('using additional config_fc from setup script '\
- 'for fortran compiler: %s' \
+ log.info('using additional config_fc from setup script '
+ 'for fortran compiler: %s'
% (config_fc,))
from numpy.distutils.fcompiler import new_fcompiler
fcompiler = new_fcompiler(compiler=fcompiler.compiler_type,
@@ -186,12 +197,14 @@ class build_clib(old_build_clib):
# check availability of Fortran compilers
if (f_sources or fmodule_sources) and fcompiler is None:
- raise DistutilsError("library %s has Fortran sources"\
- " but no Fortran compiler found" % (lib_name))
+ raise DistutilsError("library %s has Fortran sources"
+ " but no Fortran compiler found" % (lib_name))
if fcompiler is not None:
- fcompiler.extra_f77_compile_args = build_info.get('extra_f77_compile_args') or []
- fcompiler.extra_f90_compile_args = build_info.get('extra_f90_compile_args') or []
+ fcompiler.extra_f77_compile_args = build_info.get(
+ 'extra_f77_compile_args') or []
+ fcompiler.extra_f90_compile_args = build_info.get(
+ 'extra_f90_compile_args') or []
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
@@ -203,9 +216,10 @@ class build_clib(old_build_clib):
# where compiled F90 module files are:
module_dirs = build_info.get('module_dirs') or []
module_build_dir = os.path.dirname(lib_file)
- if requiref90: self.mkpath(module_build_dir)
+ if requiref90:
+ self.mkpath(module_build_dir)
- if compiler.compiler_type=='msvc':
+ if compiler.compiler_type == 'msvc':
# this hack works around the msvc compiler attributes
# problem, msvc uses its own convention :(
c_sources += cxx_sources
@@ -239,7 +253,7 @@ class build_clib(old_build_clib):
if requiref90:
if fcompiler.module_dir_switch is None:
existing_modules = glob('*.mod')
- extra_postargs += fcompiler.module_options(\
+ extra_postargs += fcompiler.module_options(
module_dirs, module_build_dir)
if fmodule_sources:
@@ -257,14 +271,14 @@ class build_clib(old_build_clib):
if f in existing_modules:
continue
t = os.path.join(module_build_dir, f)
- if os.path.abspath(f)==os.path.abspath(t):
+ if os.path.abspath(f) == os.path.abspath(t):
continue
if os.path.isfile(t):
os.remove(t)
try:
self.move_file(f, module_build_dir)
except DistutilsFileError:
- log.warn('failed to move %r to %r' \
+ log.warn('failed to move %r to %r'
% (f, module_build_dir))
if f_sources: