--- SConstruct.orig	2009-05-23 05:47:29.000000000 +0200
+++ SConstruct	2010-01-08 06:47:48.000000000 +0100
@@ -25,6 +25,8 @@
 options.Add('CC', 'The C-Compiler used to compile C-Files')
 options.Add('CXX', 'The C++-Compiler used to compile C++-Files')
 options.Add('CPPDEFINES', 'C++-Compiler macros')
+options.Add('CCFLAGS', 'C compiler flags', Split(''))
+options.Add('LINKFLAGS', 'C linker flags', Split(''))
 options.Add(BoolOption('release', 'Build for public release (random numbers are nondeterminisitc, etc.).  This will force debug=0.', 0))
 options.Add(BoolOption('debug', 'Generate debug code', 0))
 options.Add(BoolOption('multithreaded', 'Generate multithreaded code', 1))
@@ -119,6 +122,9 @@
 
 options.Update(env)
 
+env['CCFLAGS'] = Split(env['CCFLAGS'])
+env['LINKFLAGS'] = Split(env['LINKFLAGS'])
+
 if env.has_key('use_distcc') and env['use_distcc']:
     if 'distcc' not in env['CC']:
         env['CC'] = 'distcc %s' % env['CC']
@@ -197,6 +204,15 @@
         else:
             print 'Configuring unknown system (assuming the system is POSIX-like) ...'
 
+        # pthreads
+        if str(Platform()) == 'posix':
+            if env['multithreaded']:
+                if conf.CheckCHeader('pthread.h') and conf.CheckLib('pthread', 'pthread_create', autoadd = 0):
+                    env.AppendUnique(CCFLAGS = ['-pthread'])
+                    env.AppendUnique(LINKFLAGS = ['-pthread'])
+                else:
+                    Exit(1)
+
         # Python
         import distutils.sysconfig
         if str(Platform()) == 'win32':
@@ -216,6 +232,8 @@
             matches = regex.findall(distutils.sysconfig.get_config_var('LDLIBRARY'))
             if len(matches):
                 python_libname = matches[0]
+	    elif os.environ.has_key('PYTHON_LIB'):
+	        python_libname = os.environ['PYTHON_LIB']
             else:
                 print 'Unable to determine the name of the Python runtime library.  Terminating....'
                 Exit(1)
@@ -268,15 +286,6 @@
                     BoostLibWin32Name('python', env)
                     ])
 
-            # pthreads
-            if str(Platform()) == 'posix':
-                if env['multithreaded']:
-                    if conf.CheckCHeader('pthread.h') and conf.CheckLib('pthread', 'pthread_create', autoadd = 0):
-                        env.AppendUnique(CCFLAGS = '-pthread')
-                        env.AppendUnique(LINKFLAGS = '-pthread')
-                    else:
-                        Exit(1)
-
             # GL and GLU
             if str(Platform()) == 'win32':
                 env.AppendUnique(LIBS = [
