1
# Subclasses disutils.command.build_ext,
2
# replacing it with a Pyrex version that compiles pyx->c
3
# before calling the original build_ext command.
4
# July 2002, Graham Fawcett
5
# Modified by Darrell Gallion <dgallion1@yahoo.com>
6
# to allow inclusion of .c files along with .pyx files.
7
# Pyrex is (c) Greg Ewing.
9
import distutils.command.build_ext
10
#import Pyrex.Compiler.Main
11
from Pyrex.Compiler.Main import CompilationOptions, default_options, compile
12
from Pyrex.Compiler.Errors import PyrexError
13
from distutils.dep_util import newer
17
def replace_suffix(path, new_suffix):
18
return os.path.splitext(path)[0] + new_suffix
20
class build_ext (distutils.command.build_ext.build_ext):
22
description = "compile Pyrex scripts, then build C/C++ extensions (compile/link to build directory)"
24
def finalize_options (self):
25
distutils.command.build_ext.build_ext.finalize_options(self)
27
# The following hack should no longer be needed.
29
# compiling with mingw32 gets an "initializer not a constant" error
30
# doesn't appear to happen with MSVC!
31
# so if we are compiling with mingw32,
32
# switch to C++ mode, to avoid the problem
33
if self.compiler == 'mingw32':
36
def swig_sources (self, sources, extension = None):
37
if not self.extensions:
40
# collect the names of the source (.pyx) files
42
pyx_sources = [source for source in sources if source.endswith('.pyx')]
43
other_sources = [source for source in sources if not source.endswith('.pyx')]
45
#suffix = self.swig_cpp and '.cpp' or '.c'
47
for pyx in pyx_sources:
48
# should I raise an exception if it doesn't exist?
49
if os.path.exists(pyx):
51
target = replace_suffix(source, suffix)
52
if newer(source, target) or self.force:
53
self.pyrex_compile(source)
55
return [replace_suffix(src, suffix) for src in pyx_sources] + other_sources
57
def pyrex_compile(self, source):
58
options = CompilationOptions(default_options,
59
include_path = self.include_dirs)
60
result = compile(source, options)
61
if result.num_errors <> 0: