diff options
author | Greg Ward <gward@python.net> | 2000-06-24 00:19:35 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 2000-06-24 00:19:35 (GMT) |
commit | ffcaf2dd72ef0735d0eea125f1789d48c575f9b5 (patch) | |
tree | 0acb9bedb05ce5d4ad850c252aa6015351da22c2 /Lib/distutils | |
parent | cb18557de2a3f9b914b18f7b1d87183e3a80e663 (diff) | |
download | cpython-ffcaf2dd72ef0735d0eea125f1789d48c575f9b5.zip cpython-ffcaf2dd72ef0735d0eea125f1789d48c575f9b5.tar.gz cpython-ffcaf2dd72ef0735d0eea125f1789d48c575f9b5.tar.bz2 |
Experimental, completely untested SWIG support.
Diffstat (limited to 'Lib/distutils')
-rw-r--r-- | Lib/distutils/command/build_ext.py | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 3d6d17c..f3ff157 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -367,11 +367,12 @@ class build_ext (Command): else: self.announce ("building '%s' extension" % ext.name) - # First step: compile the source code to object files. This - # drops the object files in the current directory, regardless - # of where the source is (may be a bad thing, but that's how a - # Makefile.pre.in-based system does it, so at least there's a - # precedent!) + # First, scan the sources for SWIG definition files (.i), run + # SWIG on 'em to create .c files, and modify the sources list + # accordingly. + sources = self.swig_sources(sources) + + # Next, compile the source code to object files. # XXX not honouring 'define_macros' or 'undef_macros' -- the # CCompiler API needs to change to accomodate this, and I @@ -429,6 +430,74 @@ class build_ext (Command): # build_extensions () + def swig_sources (self, sources): + + """Walk the list of source files in 'sources', looking for SWIG + interface (.i) files. Run SWIG on all that are found, and + return a modified 'sources' list with SWIG source files replaced + by the generated C (or C++) files. + """ + + new_sources = [] + swig_sources = [] + swig_targets = {} + + # XXX this drops generated C files into the source tree, which + # is fine for developers who want to distribute the generated + # source -- but there should be an option to put SWIG output in + # the temp dir. + + for source in sources: + (base, ext) = os.path.splitext(source) + if ext in self.swig_ext(): + new_sources.append(base + ".c") # umm, what if it's C++? + swig_files.append(source) + swig_targets[source] = new_sources[-1] + else: + new_sources.append(source) + + if not swig_files: + return new_sources + + swig = self.find_swig() + swig_cmd = [swig, "-python", "-dnone", "-ISWIG"] # again, C++?!? + + for source in swig_sources: + self.announce ("swigging %s to %s" % (src, obj)) + self.spawn(swig_cmd + ["-o", swig_targets[source], source]) + + return new_sources + + # swig_sources () + + def find_swig (self): + """Return the name of the SWIG executable. On Unix, this is + just "swig" -- it should be in the PATH. Tries a bit harder on + Windows. + """ + + if os.name == "posix": + return "swig" + elif os.name == "nt": + + # Look for SWIG in its standard installation directory on + # Windows (or so I presume!). If we find it there, great; + # if not, act like Unix and assume it's in the PATH. + for vers in ("1.3", "1.2", "1.1"): + fn = os.path.join("c:\\swig%s" % vers, "swig.exe") + if os.path.isfile (fn): + return fn + else: + return "swig.exe" + + else: + raise DistutilsPlatformError, \ + ("I don't know how to find (much less run) SWIG " + "on platform '%s'") % os.name + + # find_swig () + + # -- Hooks --------------------------------------------------------- def precompile_hook (self): |