#!/usr/bin/env python
 #----------------------------------------------------------------------
 
-import sys, os, string
+import sys, os, string, glob
 from distutils.core      import setup, Extension
 from distutils.file_util import copy_file
 from distutils.dir_util  import mkpath
 # flags and values that affect this script
 #----------------------------------------------------------------------
 
-VERSION          = "2.3.2b7+"
+VERSION          = "2.3.3pre"
 DESCRIPTION      = "Cross platform GUI toolkit for Python"
 AUTHOR           = "Robin Dunn"
 AUTHOR_EMAIL     = "Robin Dunn <robin@alldunn.com>"
 BUILD_STC = 1      # If true, build the contrib/stc extension module
 BUILD_XRC = 1      # XML based resource system
 BUILD_GIZMOS = 1   # Build a module for the gizmos contrib library
-BUILD_DLLWIDGET = 1# Build a module for the gizmos contrib library
+BUILD_DLLWIDGET = 1# Build a module for that enables unknown wx widgets
+                   # to be loaded from a DLL to be used from Python.
 
 BUILD_IEWIN = 0    # Internet Explorer wrapper (experimental)
 
 USE_SWIG = 0       # Should we actually execute SWIG, or just use the
                    # files already in the distribution?
 
+UNICODE = 0        # This will pass the 'wxUSE_UNICODE' flag to SWIG and
+                   # will ensure that the right headers are found and the
+                   # right libs are linked.
+
 IN_CVS_TREE = 0    # Set to true if building in a full wxWindows CVS
                    # tree, otherwise will assume all needed files are
                    # available in the wxPython source distribution
                            # version of wx-config or alternate flags,
                            # eg. as required by the .deb in-tree build.
 
+BUILD_BASE = "build"
+
 # Some MSW build settings
 
 FINAL = 1          # Mirrors use of same flag in wx makefiles,
                    # wxWindows must have been built with /MD, not /MDd
                    # (using FINAL=hybrid will do it.)
 
-WXDLLVER = '232'   # Version part of DLL name
+WXDLLVER = '233'   # Version part of wxWindows DLL name
 
 
 #----------------------------------------------------------------------
     if __name__ == "__main__":
         print text
 
+
 def opj(*args):
     path = apply(os.path.join, args)
     return os.path.normpath(path)
 
+
 def libFlag():
     if FINAL:
-        return ''
+        rv = ''
     elif HYBRID:
-        return 'h'
+        rv = 'h'
     else:
-        return 'd'
+        rv = 'd'
+    if UNICODE:
+        rv = 'u' + rv
+    return rv
 
 
 #----------------------------------------------------------------------
 
 for flag in ['BUILD_GLCANVAS', 'BUILD_OGL', 'BUILD_STC', 'BUILD_XRC',
              'BUILD_GIZMOS', 'BUILD_DLLWIDGET',
-             'CORE_ONLY', 'USE_SWIG', 'IN_CVS_TREE',
+             'CORE_ONLY', 'USE_SWIG', 'IN_CVS_TREE', 'UNICODE',
              'FINAL', 'HYBRID', ]:
     for x in range(len(sys.argv)):
         if string.find(sys.argv[x], flag) == 0:
 sys.argv = filter(None, sys.argv)
 
 
+
+#----------------------------------------------------------------------
+# sanity checks
+
 if CORE_ONLY:
     BUILD_GLCANVAS = 0
     BUILD_OGL = 0
     BUILD_DLLWIDGET = 0
 
 
+if UNICODE and os.name != 'nt':
+    print "UNICODE is currently only supported on Win32"
+    sys.exit()
+
+
+if UNICODE:
+    BUILD_BASE = BUILD_BASE + '.unicode'
+
+
 #----------------------------------------------------------------------
 # Setup some platform specific stuff
 #----------------------------------------------------------------------
 
 if os.name == 'nt':
     # Set compile flags and such for MSVC.  These values are derived
-    # from the wxWindows makefiles for MSVC, others will probably
-    # vary...
-    WXDIR = os.environ['WXWIN']
+    # from the wxWindows makefiles for MSVC, other compilers settings
+    # will probably vary...
+    if os.environ.has_key('WXWIN'):
+        WXDIR = os.environ['WXWIN']
+    else:
+        msg("WARNING: WXWIN not set in environment.")
+        WXDIR = '..'  # assumes in CVS tree
     WXPLAT = '__WXMSW__'
     GENDIR = 'msw'
 
             'advapi32', 'wsock32']
 
 
-    cflags = [] #['/GX-']  # workaround for internal compiler error in MSVC on some machines
+    cflags = [
+             # '/GX-'  # workaround for internal compiler error in MSVC on some machines
+             ]
     lflags = None
 
 
              #'-docstring', '-Sbefore',
              '-I./src', '-D'+WXPLAT,
              ]
+if UNICODE:
+    swig_args.append('-DwxUSE_UNICODE')
+
 swig_deps = ['src/my_typemaps.i']
 
 
                    'misc.i', 'misc2.i', 'gdi.i', 'mdi.i', 'controls.i',
                    'controls2.i', 'cmndlgs.i', 'stattool.i', 'frames.i', 'image.i',
                    'printfw.i', 'sizers.i', 'clip_dnd.i',
-                   'filesys.i', 'streams.i',
-                   ##'grid.i', 'html.i', 'htmlhelp.i', 'calendar.i', 'utils.i',
+                   'filesys.i', 'streams.i', 'utils.i'
                    ]
 
     swig_sources = run_swig(swig_files, 'src', GENDIR, PKGDIR,
     wxpExtensions.append(ext)
 
 
-    # Extension for the utils module
-    swig_sources = run_swig(['utils.i'], 'src', GENDIR, PKGDIR,
-                            USE_SWIG, swig_force, swig_args, swig_deps)
-    ext = Extension('utilsc', swig_sources,
-                    include_dirs =  includes,
-                    define_macros = defines,
-                    library_dirs = libdirs,
-                    libraries = libs,
-                    extra_compile_args = cflags,
-                    extra_link_args = lflags,
-                    )
-    wxpExtensions.append(ext)
-
-
     # Extension for the calendar module
     swig_sources = run_swig(['calendar.i'], 'src', GENDIR, PKGDIR,
                             USE_SWIG, swig_force, swig_args, swig_deps)
                                 '%s/xh_frame.cpp' % XMLLOC,
 
                                 '%s/xh_gauge.cpp' % XMLLOC,
+                                '%s/xh_gdctl.cpp' % XMLLOC,
                                 '%s/xh_html.cpp' % XMLLOC,
                                 '%s/xh_listb.cpp' % XMLLOC,
                                 '%s/xh_listc.cpp' % XMLLOC,
 
                                 '%s/xh_unkwn.cpp' % XMLLOC,
                                 '%s/xml.cpp' % XMLLOC,
-                                '%s/xmlbin.cpp' % XMLLOC,
-                                '%s/xmlbinz.cpp' % XMLLOC,
-                                '%s/xmlexpat.cpp' % XMLLOC,
-
                                 '%s/xmlres.cpp' % XMLLOC,
                                 '%s/xmlrsall.cpp' % XMLLOC,
-                                '%s/xmlwrite.cpp' % XMLLOC,
 
                              ] + swig_sources,
 
     wxpExtensions.append(ext)
 
 
+#----------------------------------------------------------------------
+# Tools and scripts
+#----------------------------------------------------------------------
+
+TOOLS = [("wxPython/tools",        glob.glob("tools/*.py")),
+         ("wxPython/tools/XRCed",  glob.glob("tools/XRCed/*.py") +
+                                   glob.glob("tools/XRCed/*.xrc") +
+                                   ["tools/XRCed/CHANGES",
+                                    "tools/XRCed/TODO",
+                                    "tools/XRCed/README"]),
+         ]
+
+
 
 
 #----------------------------------------------------------------------
               packages = [PKGDIR,
                           PKGDIR+'.lib',
                           PKGDIR+'.lib.editor',
-                          PKGDIR+'.lib.mixins'
+                          PKGDIR+'.lib.mixins',
+                          PKGDIR+'.lib.PyCrust',
                           ],
 
               ext_package = PKGDIR,
               ext_modules = wxpExtensions,
+
+              options = { 'build' : { 'build_base' : BUILD_BASE }}
+
+              ##data_files = TOOLS,
               )
 
     else:
 
               ext_package = PKGDIR,
               ext_modules = wxpExtensions,
+
               )