1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
import re
import os
import sys
import new
from distutils.ccompiler import *
from distutils import ccompiler
from distutils.sysconfig import customize_compiler
from distutils.version import LooseVersion
import log
from exec_command import exec_command
from misc_util import compiler_to_string
# Using customized CCompiler.spawn.
def CCompiler_spawn(self, cmd, display=None):
if display is None:
display = cmd
if type(display) is type([]): display = ' '.join(display)
log.info(display)
s,o = exec_command(cmd)
print s
print o
if s:
if type(cmd) is type([]):
cmd = ' '.join(cmd)
raise DistutilsExecError,\
'Command "%s" failed with exit status %d' % (cmd, s)
CCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)
def CCompiler_compile(self, sources, output_dir=None, macros=None,
include_dirs=None, debug=0, extra_preargs=None,
extra_postargs=None, depends=None):
if not sources:
return []
from fcompiler import FCompiler
if isinstance(self, FCompiler):
display = []
for fc in ['f77','f90','fix']:
fcomp = getattr(self,'compiler_'+fc)
if fcomp is None:
continue
display.append("%s(%s) options: '%s'" % (os.path.basename(fcomp[0]),
fc,
' '.join(fcomp[1:])))
display = '\n'.join(display)
else:
ccomp = self.compiler_so
display = "%s options: '%s'" % (os.path.basename(ccomp[0]),
' '.join(ccomp[1:]))
log.info(display)
macros, objects, extra_postargs, pp_opts, build = \
self._setup_compile(output_dir, macros, include_dirs, sources,
depends, extra_postargs)
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
display = "compile options: '%s'" % (' '.join(cc_args))
if extra_postargs:
display += "\nextra options: '%s'" % (' '.join(extra_postargs))
log.info(display)
# build any sources in same order as they were originally specified
# especially important for fortran .f90 files using modules
if isinstance(self, FCompiler):
from distutils.sysconfig import python_build
objects = self.object_filenames(sources,
strip_dir=python_build,
output_dir=output_dir)
objects_to_build = build.keys()
for obj in objects:
if obj in objects_to_build:
src, ext = build[obj]
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
else:
for obj, (src, ext) in build.items():
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
# Return *all* object filenames, not just the ones we just built.
return objects
CCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)
def CCompiler_customize_cmd(self, cmd):
""" Customize compiler using distutils command.
"""
log.info('customize %s using %s' % (self.__class__.__name__,
cmd.__class__.__name__))
if getattr(cmd,'include_dirs',None) is not None:
self.set_include_dirs(cmd.include_dirs)
if getattr(cmd,'define',None) is not None:
for (name,value) in cmd.define:
self.define_macro(name, value)
if getattr(cmd,'undef',None) is not None:
for macro in cmd.undef:
self.undefine_macro(macro)
if getattr(cmd,'libraries',None) is not None:
self.set_libraries(self.libraries + cmd.libraries)
if getattr(cmd,'library_dirs',None) is not None:
self.set_library_dirs(self.library_dirs + cmd.library_dirs)
if getattr(cmd,'rpath',None) is not None:
self.set_runtime_library_dirs(cmd.rpath)
if getattr(cmd,'link_objects',None) is not None:
self.set_link_objects(cmd.link_objects)
return
CCompiler.customize_cmd = new.instancemethod(\
CCompiler_customize_cmd,None,CCompiler)
def CCompiler_show_customization(self):
if 0:
for attrname in ['include_dirs','define','undef',
'libraries','library_dirs',
'rpath','link_objects']:
attr = getattr(self,attrname,None)
if not attr:
continue
log.info("compiler '%s' is set to %s" % (attrname,attr))
try: self.get_version()
except: pass
print '*'*80
print self.__class__
print compiler_to_string(self)
print '*'*80
CCompiler.show_customization = new.instancemethod(\
CCompiler_show_customization,None,CCompiler)
def CCompiler_customize(self, dist, need_cxx=0):
# See FCompiler.customize for suggested usage.
log.info('customize %s' % (self.__class__.__name__))
customize_compiler(self)
if need_cxx:
if self.compiler[0].find('gcc')>=0:
if sys.version[:3]>='2.3':
if not self.compiler_cxx:
self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\
+ self.compiler[1:]
else:
self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\
+ self.compiler[1:]
else:
log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)
return
CCompiler.customize = new.instancemethod(\
CCompiler_customize,None,CCompiler)
def CCompiler_get_version(self, force=0, ok_status=[0]):
""" Compiler version. Returns None if compiler is not available. """
if not force and hasattr(self,'version'):
return self.version
if not (hasattr(self,'version_cmd') and
hasattr(self,'version_pattern')):
log.warn('%s does not provide version_cmd and version_pattern attributes' \
% (self.__class__))
return
cmd = ' '.join(self.version_cmd)
status, output = exec_command(cmd,use_tee=0)
version = None
if status in ok_status:
m = re.match(self.version_pattern,output)
if m:
version = m.group('version')
assert version,`version`
version = LooseVersion(version)
self.version = version
return version
CCompiler.get_version = new.instancemethod(\
CCompiler_get_version,None,CCompiler)
if sys.platform == 'win32':
compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',
"Mingw32 port of GNU C Compiler for Win32"\
"(for MSC built Python)")
if os.environ.get('OSTYPE','')=='msys' or \
os.environ.get('MSYSTEM','')=='MINGW32':
# On windows platforms, we want to default to mingw32 (gcc)
# because msvc can't build blitz stuff.
log.info('Setting mingw32 as default compiler for nt.')
ccompiler._default_compilers = (('nt', 'mingw32'),) \
+ ccompiler._default_compilers
_distutils_new_compiler = new_compiler
def new_compiler (plat=None,
compiler=None,
verbose=0,
dry_run=0,
force=0):
# Try first C compilers from scipy_distutils.
if plat is None:
plat = os.name
try:
if compiler is None:
compiler = get_default_compiler(plat)
(module_name, class_name, long_description) = compiler_class[compiler]
except KeyError:
msg = "don't know how to compile C/C++ code on platform '%s'" % plat
if compiler is not None:
msg = msg + " with '%s' compiler" % compiler
raise DistutilsPlatformError, msg
module_name = "scipy_distutils." + module_name
try:
__import__ (module_name)
except ImportError, msg:
print msg
module_name = module_name[6:]
try:
__import__(module_name)
except ImportError:
raise DistutilsModuleError, \
"can't compile C/C++ code: unable to load module '%s'" % \
module_name
try:
module = sys.modules[module_name]
klass = vars(module)[class_name]
except KeyError:
raise DistutilsModuleError, \
("can't compile C/C++ code: unable to find class '%s' " +
"in module '%s'") % (class_name, module_name)
compiler = klass(None, dry_run, force)
log.debug('new_fcompiler returns %s' % (klass))
return compiler
ccompiler.new_compiler = new_compiler
|