# created 1999/07/05, Thomas Heller __revision__ = "$Id$" from distutils.errors import * from distutils.util import newer_pairwise, newer_group import string, os from distutils.ccompiler import CCompiler def find_exe (exe): for p in string.split (os.environ['Path'],';'): fn = os.path.join(os.path.abspath(p),exe) if os.path.isfile(fn): return fn # for vers in ("1.3", "1.2", "1.1"): fn = os.path.join(r"c:\swig%s" % vers ,exe) if os.path.isfile (fn): return fn return exe class Swig (CCompiler): src_extensions = ['.i'] obj_extension = '.cpp' ## obj_extension = '.c' def __init__ (self, verbose=0, dry_run=0, force=0): CCompiler.__init__ (self, verbose, dry_run, force) self.exe = find_exe ("swig.exe") def compile (self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) (objects, skip_sources) = self._prep_compile (sources, output_dir) print "SWIG!", include_dirs print "SWIG!", self.include_dirs for i in range (len (sources)): src = sources[i] ; obj = objects[i] if src == obj: # nothing to do continue ext = (os.path.splitext (src))[1] if skip_sources[src]: self.announce ("skipping %s (%s up-to-date)" % (src, obj)) else: self.announce ("swigging %s to %s" % (src, obj)) self.mkpath (os.path.dirname (obj)) try: self.spawn ([self.exe] + [ "-python", "-dnone", "-c++", "-ISWIG", "-o", obj] + [src]) except DistutilsExecError, msg: raise CompileError, msg return objects def object_filenames (self, source_filenames, strip_dir=0, output_dir=''): if output_dir is None: output_dir = '' obj_names = [] for src_name in source_filenames: (base, ext) = os.path.splitext (src_name) if ext not in self.src_extensions: obj_names.append (src_name) continue if strip_dir: base = os.path.basename (base) obj_names.append (os.path.join (output_dir, base + self.obj_extension)) return obj_names # object_filenames ()