diff --git a/dsextras.py b/dsextras.py
index 9fc79c1..10973e2 100644
--- a/dsextras.py
+++ b/dsextras.py
@@ -95,6 +95,21 @@ def pkgc_version_check(name, req_version):
         
     return 0
 
+def pkgc_get_libraries(name):
+    """returns a list of libraries as returned by pkg-config --libs-only-l"""
+    output = getoutput('pkg-config --libs-only-l %s' % name)
+    return output.replace('-l', '').split()
+
+def pkgc_get_library_dirs(name):
+    """returns a list of library dirs as returned by pkg-config --libs-only-L"""
+    output = getoutput('pkg-config --libs-only-L %s' % name)
+    return output.replace('-L', '').split()
+
+def pkgc_get_include_dirs(name):
+    """returns a list of include dirs as returned by pkg-config --cflags-only-I"""
+    output = getoutput('pkg-config --cflags-only-I %s' % name)
+    return output.replace('-I', '').split()
+
 class BuildExt(build_ext):
     def init_extra_compile_args(self):
         self.extra_compile_args = []
@@ -220,10 +235,19 @@ class PkgConfigExtension(Extension):
     can_build_ok = None
     def __init__(self, **kwargs):
         name = kwargs['pkc_name']
-        kwargs['include_dirs'] = self.get_include_dirs(name) + GLOBAL_INC
+        if 'include_dirs' in kwargs:
+            kwargs['include_dirs'] += self.get_include_dirs(name) + GLOBAL_INC
+        else:
+            kwargs['include_dirs'] = self.get_include_dirs(name) + GLOBAL_INC
         kwargs['define_macros'] = GLOBAL_MACROS
-        kwargs['libraries'] = self.get_libraries(name)
-        kwargs['library_dirs'] = self.get_library_dirs(name)
+        if 'libraries' in kwargs:
+            kwargs['libraries'] += self.get_libraries(name)
+        else:
+            kwargs['libraries'] = self.get_libraries(name)
+        if 'library_dirs' in kwargs:
+            kwargs['library_dirs'] += self.get_library_dirs(name)
+        else:
+            kwargs['library_dirs'] = self.get_library_dirs(name)
         if 'pygobject_pkc' in kwargs:
             self.pygobject_pkc = kwargs.pop('pygobject_pkc')
         if self.pygobject_pkc:
@@ -290,7 +314,7 @@ class PkgConfigExtension(Extension):
             else:
                 print "Warning: Too old version of %s" % self.pkc_name
                 print "         Need %s, but %s is installed" % \
-                      (package, orig_version)
+                      (version, orig_version)
                 self.can_build_ok = 0
                 return 0
 
diff --git a/gio/gio-types.defs b/gio/gio-types.defs
index 331e0bc..7bfdcf7 100644
--- a/gio/gio-types.defs
+++ b/gio/gio-types.defs
@@ -419,28 +419,28 @@
   )
 )
 
-(define-flags ConverterFlags
-  (in-module "gio")
-  (c-name "GConverterFlags")
-  (gtype-id "G_TYPE_CONVERTER_FLAGS")
-  (values
-    '("no-flags" "G_CONVERTER_NO_FLAGS")
-    '("input-at-end" "G_CONVERTER_INPUT_AT_END")
-    '("flush" "G_CONVERTER_FLUSH")
-  )
-)
-
-(define-enum ConverterResult
-  (in-module "gio")
-  (c-name "GConverterResult")
-  (gtype-id "G_TYPE_CONVERTER_RESULT")
-  (values
-    '("error" "G_CONVERTER_ERROR")
-    '("converted" "G_CONVERTER_CONVERTED")
-    '("finished" "G_CONVERTER_FINISHED")
-    '("flushed" "G_CONVERTER_FLUSHED")
-  )
-)
+;;(define-flags ConverterFlags
+;;  (in-module "gio")
+;;  (c-name "GConverterFlags")
+;;  (gtype-id "G_TYPE_CONVERTER_FLAGS")
+;;  (values
+;;    '("no-flags" "G_CONVERTER_NO_FLAGS")
+;;    '("input-at-end" "G_CONVERTER_INPUT_AT_END")
+;;    '("flush" "G_CONVERTER_FLUSH")
+;;  )
+;;)
+
+;;(define-enum ConverterResult
+;;  (in-module "gio")
+;;  (c-name "GConverterResult")
+;;  (gtype-id "G_TYPE_CONVERTER_RESULT")
+;;  (values
+;;    '("error" "G_CONVERTER_ERROR")
+;;    '("converted" "G_CONVERTER_CONVERTED")
+;;    '("finished" "G_CONVERTER_FINISHED")
+;;    '("flushed" "G_CONVERTER_FLUSHED")
+;;  )
+;;)
 
 (define-enum DataStreamByteOrder
   (in-module "gio")
@@ -795,13 +795,13 @@
   )
 )
 
-(define-enum ZlibCompressorFormat
-  (in-module "gio")
-  (c-name "GZlibCompressorFormat")
-  (gtype-id "G_TYPE_ZLIB_COMPRESSOR_FORMAT")
-  (values
-    '("zlib" "G_ZLIB_COMPRESSOR_FORMAT_ZLIB")
-    '("gzip" "G_ZLIB_COMPRESSOR_FORMAT_GZIP")
-    '("raw" "G_ZLIB_COMPRESSOR_FORMAT_RAW")
-  )
-)
+;;(define-enum ZlibCompressorFormat
+;;  (in-module "gio")
+;;  (c-name "GZlibCompressorFormat")
+;;  (gtype-id "G_TYPE_ZLIB_COMPRESSOR_FORMAT")
+;;  (values
+;;    '("zlib" "G_ZLIB_COMPRESSOR_FORMAT_ZLIB")
+;;    '("gzip" "G_ZLIB_COMPRESSOR_FORMAT_GZIP")
+;;    '("raw" "G_ZLIB_COMPRESSOR_FORMAT_RAW")
+;;  )
+;;)
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 171a06f..409aeef 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -50,6 +50,9 @@ init_gio(void)
     m = Py_InitModule("gio._gio", pygio_functions);
     d = PyModule_GetDict(m);
 
+    g_type_init();
+    pyglib_init();
+
     init_pygobject_check(2, 15, 2);
 
     pygio_register_classes(d);
diff --git a/glib/pygiochannel.c b/glib/pygiochannel.c
index 5b57011..4c935e8 100644
--- a/glib/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -10,6 +10,7 @@
 
 #include "pyglib.h"
 #include "pyglib-private.h"
+#include "pygsource.h"
 
 typedef struct {
     PyObject_HEAD
diff --git a/gobject/constants.py.in b/gobject/constants.py.in
index 0a1eb86..e02d8e9 100644
--- a/gobject/constants.py.in
+++ b/gobject/constants.py.in
@@ -48,3 +48,19 @@ TYPE_OBJECT = _gobject.type_from_name('GObject')
 TYPE_PYOBJECT = _gobject.type_from_name('PyObject')
 TYPE_UNICHAR = TYPE_UINT
 
+# do a little dance to maintain API compatibility
+# as these were origianally defined here, and are
+# now defined in gobjectmodule.c
+G_MINFLOAT = _gobject.G_MINFLOAT
+G_MAXFLOAT = _gobject.G_MAXFLOAT
+G_MINDOUBLE = _gobject.G_MINDOUBLE
+G_MAXDOUBLE = _gobject.G_MAXDOUBLE
+G_MINSHORT = _gobject.G_MINSHORT
+G_MAXSHORT = _gobject.G_MAXSHORT
+G_MAXUSHORT = _gobject.G_MAXUSHORT
+G_MININT = _gobject.G_MININT
+G_MAXINT = _gobject.G_MAXINT
+G_MAXUINT = _gobject.G_MAXUINT
+G_MINLONG = _gobject.G_MINLONG
+G_MAXLONG = _gobject.G_MAXLONG
+G_MAXULONG = _gobject.G_MAXULONG
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 73bfc3c..e796c66 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2522,6 +2522,22 @@ pygobject_register_api(PyObject *d)
 static void
 pygobject_register_constants(PyObject *m)
 {
+	/* PyFloat_ return a new ref, and add object takes the ref */
+	PyModule_AddObject(m, "G_MINFLOAT", PyFloat_FromDouble(G_MINFLOAT));
+	PyModule_AddObject(m, "G_MAXFLOAT", PyFloat_FromDouble(G_MAXFLOAT));
+	PyModule_AddObject(m, "G_MINDOUBLE", PyFloat_FromDouble(G_MINDOUBLE));
+	PyModule_AddObject(m, "G_MAXDOUBLE", PyFloat_FromDouble(G_MAXDOUBLE));
+
+	PyModule_AddIntConstant(m, "G_MINSHORT", G_MINSHORT);
+	PyModule_AddIntConstant(m, "G_MAXSHORT", G_MAXSHORT);
+	PyModule_AddIntConstant(m, "G_MAXUSHORT", G_MAXUSHORT);
+	PyModule_AddIntConstant(m, "G_MININT", G_MININT);
+	PyModule_AddIntConstant(m, "G_MAXINT", G_MAXINT);
+	PyModule_AddIntConstant(m, "G_MAXUINT", G_MAXUINT);
+	PyModule_AddIntConstant(m, "G_MINLONG", G_MINLONG);
+	PyModule_AddIntConstant(m, "G_MAXLONG", G_MAXLONG);
+	PyModule_AddIntConstant(m, "G_MAXULONG", G_MAXULONG);
+
     PyModule_AddIntConstant(m, "SIGNAL_RUN_FIRST", G_SIGNAL_RUN_FIRST);
     PyModule_AddIntConstant(m, "SIGNAL_RUN_LAST", G_SIGNAL_RUN_LAST);
     PyModule_AddIntConstant(m, "SIGNAL_RUN_CLEANUP", G_SIGNAL_RUN_CLEANUP);
diff --git a/setup.py b/setup.py
index b367c6a..888f657 100755
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,8 @@
 """Python Bindings for GObject."""
 
 from distutils.command.build import build
+from distutils.command.build_clib import build_clib
+from distutils.sysconfig import get_python_inc
 from distutils.core import setup
 import glob
 import os
@@ -12,7 +14,8 @@ import sys
 
 from dsextras import get_m4_define, getoutput, have_pkgconfig, \
      GLOBAL_INC, GLOBAL_MACROS, InstallLib, InstallData, BuildExt, \
-     PkgConfigExtension
+     PkgConfigExtension, TemplateExtension, \
+     pkgc_get_libraries, pkgc_get_library_dirs, pkgc_get_include_dirs
 
 if '--yes-i-know-its-not-supported' in sys.argv:
     sys.argv.remove('--yes-i-know-its-not-supported')
@@ -39,7 +42,7 @@ MICRO_VERSION = int(get_m4_define('pygobject_micro_version'))
 
 VERSION = "%d.%d.%d" % (MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION)
 
-GOBJECT_REQUIRED  = get_m4_define('glib_required_version')
+GLIB_REQUIRED  = get_m4_define('glib_required_version')
 
 PYGOBJECT_SUFFIX = '2.0'
 PYGOBJECT_SUFFIX_LONG = 'gtk-' + PYGOBJECT_SUFFIX
@@ -49,11 +52,12 @@ GLOBAL_MACROS += [('PYGOBJECT_MAJOR_VERSION', MAJOR_VERSION),
                   ('PYGOBJECT_MINOR_VERSION', MINOR_VERSION),
                   ('PYGOBJECT_MICRO_VERSION', MICRO_VERSION)]
 
-if sys.platform == 'win33':
+if sys.platform == 'win32':
     GLOBAL_MACROS.append(('VERSION', '"""%s"""' % VERSION))
 else:
     GLOBAL_MACROS.append(('VERSION', '"%s"' % VERSION))
 
+DEFS_DIR    = os.path.join('share', 'pygobject', PYGOBJECT_SUFFIX, 'defs')
 INCLUDE_DIR = os.path.join('include', 'pygtk-%s' % PYGOBJECT_SUFFIX)
 XSL_DIR = os.path.join('share', 'pygobject','xsl')
 HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygobject')
@@ -64,6 +68,7 @@ class PyGObjectInstallLib(InstallLib):
         # Install pygtk.pth, pygtk.py[c] and templates
         self.install_pth()
         self.install_pygtk()
+        self.install_pygobject_constants()
 
         # Modify the base installation dir
         install_dir = os.path.join(self.install_dir, PYGOBJECT_SUFFIX_LONG)
@@ -87,10 +92,22 @@ class PyGObjectInstallLib(InstallLib):
         self.local_outputs.append(pygtk)
         self.local_inputs.append('pygtk.py')
 
+    def install_pygobject_constants(self):
+        """generates and installs constants.py"""
+        go_dir = os.path.join(self.install_dir, PYGOBJECT_SUFFIX_LONG, "gobject")
+        self.mkpath(go_dir)
+        
+        #copy contents of constants.in to gobject/constants.py
+        constants_in = open(os.path.join("gobject","constants.py.in"), 'r').read()
+        constants = open(os.path.join(go_dir, "constants.py"), 'w')
+        constants.write(constants_in)
+        constants.close()
+
 class PyGObjectInstallData(InstallData):
     def run(self):
         self.add_template_option('VERSION', VERSION)
         self.add_template_option('FFI_LIBS', '')
+        self.add_template_option('LIBFFI_PC', '')
         self.prepare()
 
         # Install templates
@@ -110,47 +127,113 @@ class PyGObjectBuild(build):
 PyGObjectBuild.user_options.append(('enable-threading', None,
                                 'enable threading support'))
 
+# glib
+glib = PkgConfigExtension(name='glib._glib',
+                          pkc_name='glib-2.0',
+                          pkc_version=GLIB_REQUIRED,
+                          pygobject_pkc=None,
+                          include_dirs=['glib'],
+                          libraries=['pyglib'],
+                          sources=['glib/glibmodule.c',
+                                   'glib/pygiochannel.c',
+                                   'glib/pygmaincontext.c',
+                                   'glib/pygmainloop.c',
+                                   'glib/pygoptioncontext.c',
+                                   'glib/pygoptiongroup.c',
+                                   'glib/pygsource.c',
+                                   'glib/pygspawn.c',
+                                   ])
+
 # GObject
-gobject = PkgConfigExtension(name='gobject._gobject', pkc_name='gobject-2.0',
-                             pkc_version=GOBJECT_REQUIRED,
+gobject = PkgConfigExtension(name='gobject._gobject',
+                             pkc_name='gobject-2.0',
+                             pkc_version=GLIB_REQUIRED,
                              pygobject_pkc=None,
+                             include_dirs=['glib'],
+                             libraries=['pyglib'],
                              sources=['gobject/gobjectmodule.c',
                                       'gobject/pygboxed.c',
                                       'gobject/pygenum.c',
                                       'gobject/pygflags.c',
+                                      'gobject/pyginterface.c',
                                       'gobject/pygobject.c',
-                                      'gobject/pygmaincontext.c',
-                                      'gobject/pygmainloop.c',
-                                      'gobject/pygoptioncontext.c',
-                                      'gobject/pygoptiongroup.c',
                                       'gobject/pygparamspec.c',
                                       'gobject/pygpointer.c',
                                       'gobject/pygtype.c',
-                                      'gobject/pygsource.c',
-                                      'gobject/pygiochannel.c',
                                       ])
 
+# gio
+gio = TemplateExtension(name='gio',
+                        pkc_name='gio-2.0',
+                        pkc_version=GLIB_REQUIRED,
+                        output='gio._gio',
+                        defs=('gio/gio.defs', ['gio/gio-types.defs']),
+                        include_dirs=['glib'],
+                        libraries=['pyglib'],
+                        sources=['gio/giomodule.c',
+                                 'gio/gio.c',
+                                 'gio/pygio-utils.c'],
+                        register=[('gio/gio.defs', ['gio/gio-types.defs'])],
+                        override='gio/gio.override')
+
+clibs = []
 data_files = []
 ext_modules = []
-py_modules = []
-py_modules.append('dsextras')
+
+#Install dsextras and codegen so that the pygtk installer
+#can find them
+py_modules = ['dsextras']
+packages = ['codegen']
 
 if not have_pkgconfig():
     print "Error, could not find pkg-config"
     raise SystemExit
 
+if glib.can_build():
+    #It would have been nice to create another class, such as PkgConfigCLib to
+    #encapsulate this dictionary, but it is impossible. build_clib.py does
+    #a dumb check to see if its only arguments are a 2-tuple containing a
+    #string and a Dictionary type - which makes it impossible to hide behind a
+    #subclass
+    #
+    #So we are stuck with this ugly thing
+    clibs.append((
+        'pyglib',{
+            'sources':['glib/pyglib.c'],
+            'macros':GLOBAL_MACROS,
+            'include_dirs':
+                ['glib', get_python_inc()]+pkgc_get_include_dirs('glib-2.0')}))
+    #this library is not installed, so probbably should not include its header
+    #data_files.append((INCLUDE_DIR, ('glib/pyglib.h',)))
+        
+    ext_modules.append(glib)
+    py_modules += ['glib.__init__', 'glib.option']
+else:
+    print
+    print 'ERROR: Nothing to do, glib could not be found and is essential.'
+    raise SystemExit
+
 if gobject.can_build():
     ext_modules.append(gobject)
-    py_modules.append('gobject.option')
     data_files.append((INCLUDE_DIR, ('gobject/pygobject.h',)))
     data_files.append((HTML_DIR, glob.glob('docs/html/*.html')))
     data_files.append((HTML_DIR, ['docs/style.css']))
     data_files.append((XSL_DIR,  glob.glob('docs/xsl/*.xsl')))
+    py_modules += ['gobject.__init__', 'gobject.propertyhelper']
 else:
     print
     print 'ERROR: Nothing to do, gobject could not be found and is essential.'
     raise SystemExit
 
+if gio.can_build():
+    ext_modules.append(gio)
+    py_modules += ['gio.__init__']
+    data_files.append((DEFS_DIR,('gio/gio-types.defs',)))
+else:
+    print
+    print 'ERROR: Nothing to do, gio could not be found and is essential.'
+    raise SystemExit
+
 # Threading support
 if '--disable-threading' in sys.argv:
     sys.argv.remove('--disable-threading')
@@ -199,11 +282,14 @@ setup(name="pygobject",
       description = doclines[0],
       long_description = "\n".join(doclines[2:]),
       py_modules=py_modules,
+      packages=packages,
       ext_modules=ext_modules,
+      libraries=clibs,
       data_files=data_files,
       scripts = ["pygobject_postinstall.py"],
       options=options,
       cmdclass={'install_lib': PyGObjectInstallLib,
                 'install_data': PyGObjectInstallData,
+                'build_clib' : build_clib,
                 'build_ext': BuildExt,
                 'build': PyGObjectBuild})
