123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- """
- unixccompiler - can handle very long argument lists for ar.
- """
- import os
- import sys
- import subprocess
- from distutils.errors import CompileError, DistutilsExecError, LibError
- from distutils.unixccompiler import UnixCCompiler
- from numpy.distutils.ccompiler import replace_method
- from numpy.distutils.misc_util import _commandline_dep_string
- from numpy.distutils import log
- def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
- """Compile a single source files with a Unix-style compiler."""
-
- ccomp = self.compiler_so
- if ccomp[0] == 'aCC':
-
- if '-Ae' in ccomp:
- ccomp.remove('-Ae')
- if '-Aa' in ccomp:
- ccomp.remove('-Aa')
-
- ccomp += ['-AA']
- self.compiler_so = ccomp
-
- if 'OPT' in os.environ:
-
- from sysconfig import get_config_vars
- opt = " ".join(os.environ['OPT'].split())
- gcv_opt = " ".join(get_config_vars('OPT')[0].split())
- ccomp_s = " ".join(self.compiler_so)
- if opt not in ccomp_s:
- ccomp_s = ccomp_s.replace(gcv_opt, opt)
- self.compiler_so = ccomp_s.split()
- llink_s = " ".join(self.linker_so)
- if opt not in llink_s:
- self.linker_so = llink_s.split() + opt.split()
- display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src)
-
-
- if getattr(self, '_auto_depends', False):
- deps = ['-MMD', '-MF', obj + '.d']
- else:
- deps = []
- try:
- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps +
- extra_postargs, display = display)
- except DistutilsExecError as e:
- msg = str(e)
- raise CompileError(msg)
-
- if deps:
-
-
-
- if sys.platform == 'zos':
- subprocess.check_output(['chtag', '-tc', 'IBM1047', obj + '.d'])
- with open(obj + '.d', 'a') as f:
- f.write(_commandline_dep_string(cc_args, extra_postargs, pp_opts))
- replace_method(UnixCCompiler, '_compile', UnixCCompiler__compile)
- def UnixCCompiler_create_static_lib(self, objects, output_libname,
- output_dir=None, debug=0, target_lang=None):
- """
- Build a static library in a separate sub-process.
- Parameters
- ----------
- objects : list or tuple of str
- List of paths to object files used to build the static library.
- output_libname : str
- The library name as an absolute or relative (if `output_dir` is used)
- path.
- output_dir : str, optional
- The path to the output directory. Default is None, in which case
- the ``output_dir`` attribute of the UnixCCompiler instance.
- debug : bool, optional
- This parameter is not used.
- target_lang : str, optional
- This parameter is not used.
- Returns
- -------
- None
- """
- objects, output_dir = self._fix_object_args(objects, output_dir)
- output_filename = \
- self.library_filename(output_libname, output_dir=output_dir)
- if self._need_link(objects, output_filename):
- try:
-
-
-
- os.unlink(output_filename)
- except (IOError, OSError):
- pass
- self.mkpath(os.path.dirname(output_filename))
- tmp_objects = objects + self.objects
- while tmp_objects:
- objects = tmp_objects[:50]
- tmp_objects = tmp_objects[50:]
- display = '%s: adding %d object files to %s' % (
- os.path.basename(self.archiver[0]),
- len(objects), output_filename)
- self.spawn(self.archiver + [output_filename] + objects,
- display = display)
-
-
-
-
-
- if self.ranlib:
- display = '%s:@ %s' % (os.path.basename(self.ranlib[0]),
- output_filename)
- try:
- self.spawn(self.ranlib + [output_filename],
- display = display)
- except DistutilsExecError as e:
- msg = str(e)
- raise LibError(msg)
- else:
- log.debug("skipping %s (up-to-date)", output_filename)
- return
- replace_method(UnixCCompiler, 'create_static_lib',
- UnixCCompiler_create_static_lib)
|