diff --git a/setup.py b/setup.py
index 5ebbdcd..a51d964 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,14 @@
 #!/usr/bin/env python
+"""SWFTools build configuration.
+
+The following environment variable overrides are supported:
+
+  SWFTOOLS_DATADIR -- Path to a directory
+  SWFTOOLS_LIBRARY_DIRS -- A colon (:) separated list of directories where libraries will be searched
+  SWFTOOLS_INCLUDE_DIRS -- A colon (:) separated list of directories where headers will be searched
+  SWFTOOLS_DISABLE_SWF_MODULE -- Boolean flag to prevent the ``SWF`` module from being built
+  SWFTOOLS_DISABLE_GFX_MODULE -- Boolean flag to prevent the ``gfx`` module from being built
+"""
 
 from distutils import ccompiler
 from distutils.core import CompileError
@@ -8,6 +18,11 @@ try:
 except ImportError:
     from distutils.core import setup, Extension
 
+import os
+import sys
+import stat
+
+
 cc = ccompiler.new_compiler()
 
 # leave it to gcc to detect c/c++ files. we'll be linking against -lstdc++
@@ -15,22 +30,14 @@ cc = ccompiler.new_compiler()
 # compile *everything* as c++ just because of the few .cc files.
 cc.language_map[".cc"] = "c"
 
-import os
-import sys
-import stat
-import re
 
-DATADIR = "/usr/share/swftools/"
+DATADIR = os.environ.get('SWFTOOLS_DATADIR', '/usr/share/swftools/')
 
 def update_dirs(list1, list2):
-    for v in list2:
-        if v not in list1 and os.path.isdir(v):
-            list1.append(v)
+    list1.extend([item for item in list2 if item not in list1 and os.path.isdir(item)])
 
 def update_list(list1, list2):
-    for v in list2:
-        if v not in list1:
-            list1.append(v)
+    list1.extend([item for item in list2 if item not in list1])
 
 COMPILER_OPTIONS = ['-fPIC', '-Wparentheses', '-Wimplicit', '-Wreturn-type',
                     '-O3', '-fomit-frame-pointer', '-Winline', 
@@ -38,16 +45,16 @@ COMPILER_OPTIONS = ['-fPIC', '-Wparentheses', '-Wimplicit', '-Wreturn-type',
                     '-DSWFTOOLS_DATADIR="'+DATADIR+'"']
 INCLUDE=['lib/lame/', 'lib/pdf/xpdf', 'lib/pdf']
 
-if 'library_dirs' in os.environ:
-    update_dirs(cc.library_dirs, [path.strip() for path in os.environ.get('library_dirs').strip().split(":")])
+if 'SWFTOOLS_LIBRARY_DIRS' in os.environ:
+    update_dirs(cc.library_dirs, [path.strip() for path in os.environ.get('SWFTOOLS_LIBRARY_DIRS').strip().split(":")])
 else:
     update_dirs(cc.library_dirs, [os.path.join(sys.prefix, 'lib'), 
                                   os.path.join(sys.prefix, 'local/lib')])
     if sys.platform == "darwin":
         update_list(cc.library_dirs, ["/sw/lib", "/opt/local/lib"])
 
-if 'include_dirs' in os.environ:
-    update_dirs(cc.include_dirs, [path.strip() for path in os.environ.get('include_dirs').strip().split(":")])
+if 'SWFTOOLS_INCLUDE_DIRS' in os.environ:
+    update_dirs(cc.include_dirs, [path.strip() for path in os.environ.get('SWFTOOLS_INCLUDE_DIRS').strip().split(":")])
 else:
     update_dirs(cc.include_dirs, [os.path.join(sys.prefix, 'include'), 
                                   os.path.join(sys.prefix, 'include/freetype2'),
@@ -306,33 +313,39 @@ libgfx_sources = [
 ]
 gfxswf_sources = ["lib/devices/swf.c", "lib/readers/swf.c", "lib/readers/image.c"]
 
-swf_module = Extension(
-    name='SWF', 
-    include_dirs=cc.include_dirs+INCLUDE,
-    sources=['lib/python/SWF.c', 'lib/python/taglist.c', 'lib/python/tag.c', 'lib/python/image.c', 
-             'lib/python/tags.c', 'lib/python/tagmap.c', 'lib/python/action.c', 'lib/python/primitives.c', 
-             'lib/python/pyutils.c'] + base_sources + rfxswf_sources,
-    library_dirs=cc.library_dirs,
-    libraries=config.libraries,
-    extra_objects=['%s/lib/python%s/site-packages/PIL/_imaging.so' % (sys.prefix, sys.version[:3])],
-    extra_compile_args=COMPILER_OPTIONS,
-    )
-
-gfx_module = Extension(
-    name='gfx',
-    sources=['lib/python/gfx.c'] + base_sources + libgfx_sources + rfxswf_sources + libpdf_sources + gfxswf_sources,
-    include_dirs=cc.include_dirs+INCLUDE,
-    library_dirs=cc.library_dirs,
-    libraries=config.libraries + ["stdc++"],
-    extra_objects=[],
-    extra_compile_args=COMPILER_OPTIONS,
-    )    
+extension_modules = []
+
+if not 'SWFTOOLS_DISABLE_SWF_MODULE' in os.environ:
+    swf_module = Extension(
+        name='SWF',
+        include_dirs=cc.include_dirs+INCLUDE,
+        sources=['lib/python/SWF.c', 'lib/python/taglist.c', 'lib/python/tag.c', 'lib/python/image.c',
+                 'lib/python/tags.c', 'lib/python/tagmap.c', 'lib/python/action.c', 'lib/python/primitives.c',
+                 'lib/python/pyutils.c'] + base_sources + rfxswf_sources,
+        library_dirs=cc.library_dirs,
+        libraries=config.libraries,
+        extra_objects=['%s/lib/python%s/site-packages/PIL/_imaging.so' % (sys.prefix, sys.version[:3])],
+        extra_compile_args=COMPILER_OPTIONS,
+        )
+    extension_modules.append(swf_module)
+
+if not 'SWFTOOLS_DISABLE_GFX_MODULE' in os.environ:
+    gfx_module = Extension(
+        name='gfx',
+        sources=['lib/python/gfx.c'] + base_sources + libgfx_sources + rfxswf_sources + libpdf_sources + gfxswf_sources,
+        include_dirs=cc.include_dirs+INCLUDE,
+        library_dirs=cc.library_dirs,
+        libraries=config.libraries + ["stdc++"],
+        extra_objects=[],
+        extra_compile_args=COMPILER_OPTIONS,
+        )
+    extension_modules.append(gfx_module)
 
 setup(name='SWFTools',
-      version='0.9dev',
+      version='0.9.1',
       description='Python wrapper for SWFTools',
       author='Matthias Kramm',
       author_email='kramm@quiss.org',
       url='http://www.swftools.org/',
-      ext_modules=[swf_module, gfx_module],
+      ext_modules=extension_modules,
 )
