--- Portfile.orig	2013-11-11 16:30:13.000000000 +0800
+++ Portfile	2014-01-09 14:21:53.000000000 +0800
@@ -20,33 +20,55 @@
                     sha256  f44c52a0f8065d41d44772a7484f93bc5e7da21a8f4a9ad3f38a36b827eeff0b
 
 depends_lib         path:lib/pkgconfig/glib-2.0.pc:glib2 \
-                    port:libxml2 \
-                    port:swig-python
+                    port:libxml2
 
 patchfiles          patch-iterator.diff
 
-configure.args-append   -DENABLE_CYTHON=OFF
+configure.args-append   -DENABLE_CYTHON=OFF -DENABLE_SWIG=OFF
 
 use_parallel_build  no
 
-variant python26 conflicts python27 description {Use Python 2.6} {
-    depends_lib-append  port:python26
+variant python26 conflicts python27 python32 python33 description {Install Python 2.6 bindings} {
+    depends_lib-append  port:python26 port:swig-python
+    configure.args-replace -DENABLE_SWIG=OFF -DENABLE_SWIG=ON
     configure.args-append -DPYTHON_EXECUTABLE=${prefix}/bin/python2.6 \
-                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.6/include/python2.6 \
+                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.6/Headers \
                           -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/2.6/Python
 }
-variant python27 conflicts python26 description {Use Python 2.7} {
-    depends_lib-append  port:python27
+variant python27 conflicts python26 python32 python33 description {Install Python 2.7 bindings} {
+    depends_lib-append  port:python27 port:swig-python
+    configure.args-replace -DENABLE_SWIG=OFF -DENABLE_SWIG=ON
     configure.args-append -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \
-                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/include/python2.7 \
+                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/Headers \
                           -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/2.7/Python
 }
-if {![variant_isset python26]} {
-    default_variants    +python27
+variant python32 conflicts python26 python27 python33 description {Install Python 3.2 bindings} {
+    depends_lib-append  port:python32 port:swig-python
+    configure.args-replace -DENABLE_SWIG=OFF -DENABLE_SWIG=ON
+    configure.args-append -DPYTHON_EXECUTABLE=${prefix}/bin/python3.2 \
+                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/3.2/Headers \
+                          -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/3.2/Python
+    pre-configure {
+        reinplace "s|CMAKE_SWIG_FLAGS|CMAKE_SWIG_FLAGS -py3|" \
+            ${worksrcpath}/swig/CMakeLists.txt
+            
+        reinplace "s|print distutils\.sysconfig\.get_python_lib\(plat_specific=1\)|print (distutils.sysconfig.get_python_lib(plat_specific=1))|" \
+            ${worksrcpath}/swig/CMakeLists.txt
+    }
 }
-if {![variant_isset python26] && ![variant_isset python27]} {
-    depends_lib-delete port:swig-python
-    configure.args-append -DENABLE_SWIG=OFF
+variant python33 conflicts python26 python27 python32 description {Install Python 3.3 bindings} {
+    depends_lib-append  port:python32 port:swig-python
+    configure.args-replace -DENABLE_SWIG=OFF -DENABLE_SWIG=ON
+    configure.args-append -DPYTHON_EXECUTABLE=${prefix}/bin/python3.3 \
+                          -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/3.3/Headers \
+                          -DPYTHON_LIBRARY=${frameworks_dir}/Python.framework/Versions/3.3/Python
+    pre-configure {
+        reinplace "s|CMAKE_SWIG_FLAGS|CMAKE_SWIG_FLAGS -py3|" \
+            ${worksrcpath}/swig/CMakeLists.txt
+            
+        reinplace "s|print distutils\.sysconfig\.get_python_lib\(plat_specific=1\)|print (distutils.sysconfig.get_python_lib(plat_specific=1))|" \
+            ${worksrcpath}/swig/CMakeLists.txt
+    }
 }
 
 livecheck.type      regex
