Patch 1046644 - improved distutils support for SWIG.
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 04cd742..07614c6 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -81,6 +81,10 @@
          "specify the compiler type"),
         ('swig-cpp', None,
          "make SWIG create C++ files (default is C)"),
+        ('swig-opts=', None,
+         "list of SWIG command line options"),
+        ('swig=', None,
+         "path to the SWIG executable"),
         ]
 
     boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
@@ -107,8 +111,9 @@
         self.debug = None
         self.force = None
         self.compiler = None
+        self.swig = None
         self.swig_cpp = None
-
+        self.swig_opts = None
 
     def finalize_options (self):
         from distutils import sysconfig
@@ -205,6 +210,11 @@
         if self.undef:
             self.undef = string.split(self.undef, ',')
 
+        if self.swig_opts is None:
+            self.swig_opts = []
+        else:
+            self.swig_opts = self.swig_opts.split(' ')
+
     # finalize_options ()
 
 
@@ -429,7 +439,7 @@
         # 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)
+        sources = self.swig_sources(sources, ext)
 
         # Next, compile the source code to object files.
 
@@ -492,7 +502,7 @@
             target_lang=language)
 
 
-    def swig_sources (self, sources):
+    def swig_sources (self, sources, extension):
 
         """Walk the list of source files in 'sources', looking for SWIG
         interface (.i) files.  Run SWIG on all that are found, and
@@ -510,6 +520,9 @@
         # the temp dir.
 
         if self.swig_cpp:
+            log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
+
+        if self.swig_cpp or ('-c++' in self.swig_opts):
             target_ext = '.cpp'
         else:
             target_ext = '.c'
@@ -526,11 +539,17 @@
         if not swig_sources:
             return new_sources
 
-        swig = self.find_swig()
+        swig = self.swig or self.find_swig()
         swig_cmd = [swig, "-python"]
+        swig_cmd.extend(self.swig_opts)
         if self.swig_cpp:
             swig_cmd.append("-c++")
 
+        # Do not override commandline arguments
+        if not self.swig_opts:
+            for o in extension.swig_opts:
+                swig_cmd.append(o)
+
         for source in swig_sources:
             target = swig_targets[source]
             log.info("swigging %s to %s", source, target)
diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index 6867534..8c82801 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -54,7 +54,7 @@
                       'define_macros', 'undef_macros',
                       'library_dirs', 'libraries', 'runtime_library_dirs',
                       'extra_objects', 'extra_compile_args', 'extra_link_args',
-                      'export_symbols', 'depends', 'language')
+                      'swig_opts', 'export_symbols', 'depends', 'language')
 
 def setup (**attrs):
     """The gateway to the Distutils: do everything your setup script needs
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index e69f3e9..440d128 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -75,6 +75,9 @@
         used on all platforms, and not generally necessary for Python
         extensions, which typically export exactly one symbol: "init" +
         extension_name.
+      swig_opts : [string]
+        any extra options to pass to SWIG if a source file has the .i
+        extension.
       depends : [string]
         list of files that the extension depends on
       language : string
@@ -95,6 +98,7 @@
                   extra_compile_args=None,
                   extra_link_args=None,
                   export_symbols=None,
+                  swig_opts = None,
                   depends=None,
                   language=None,
                   **kw                      # To catch unknown keywords
@@ -116,6 +120,7 @@
         self.extra_compile_args = extra_compile_args or []
         self.extra_link_args = extra_link_args or []
         self.export_symbols = export_symbols or []
+        self.swig_opts = swig_opts or []
         self.depends = depends or []
         self.language = language