+# Check for SWIG
+if not env.has_key('SWIG'):
+ print 'Error: SWIG utility not found.'
+ print ' Please install (see http://www.swig.org) and retry.'
+ Exit(1)
+
+# Check for appropriate SWIG version
+swig_version = os.popen('swig -version').read().split()
+# First 3 words should be "SWIG Version x.y.z"
+if swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
+ print 'Error determining SWIG version.'
+ Exit(1)
+
+min_swig_version = '1.3.28'
+if compare_versions(swig_version[2], min_swig_version) < 0:
+ print 'Error: SWIG version', min_swig_version, 'or newer required.'
+ print ' Installed version:', swig_version[2]
+ Exit(1)
+
+# Set up SWIG flags & scanner
+env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
+
+import SCons.Scanner
+
+swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
+
+swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
+ swig_inc_re)
+
+env.Append(SCANNERS = swig_scanner)
+
+# Platform-specific configuration. Note again that we assume that all
+# builds under a given build root run on the same host platform.
+conf = Configure(env,
+ conf_dir = os.path.join(build_root, '.scons_config'),
+ log_file = os.path.join(build_root, 'scons_config.log'))
+
+# Find Python include and library directories for embedding the
+# interpreter. For consistency, we will use the same Python
+# installation used to run scons (and thus this script). If you want
+# to link in an alternate version, see above for instructions on how
+# to invoke scons with a different copy of the Python interpreter.
+
+# Get brief Python version name (e.g., "python2.4") for locating
+# include & library files
+py_version_name = 'python' + sys.version[:3]
+
+# include path, e.g. /usr/local/include/python2.4
+py_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name)
+env.Append(CPPPATH = py_header_path)
+# verify that it works
+if not conf.CheckHeader('Python.h', '<>'):
+ print "Error: can't find Python.h header in", py_header_path
+ Exit(1)
+
+# add library path too if it's not in the default place
+py_lib_path = None
+if sys.exec_prefix != '/usr':
+ py_lib_path = os.path.join(sys.exec_prefix, 'lib')
+elif sys.platform == 'cygwin':
+ # cygwin puts the .dll in /bin for some reason
+ py_lib_path = '/bin'
+if py_lib_path:
+ env.Append(LIBPATH = py_lib_path)
+ print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
+if not conf.CheckLib(py_version_name):
+ print "Error: can't find Python library", py_version_name
+ Exit(1)
+
+# Check for zlib. If the check passes, libz will be automatically
+# added to the LIBS environment variable.
+if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'):
+ print 'Error: did not find needed zlib compression library '\
+ 'and/or zlib.h header file.'
+ print ' Please install zlib and try again.'
+ Exit(1)