[cig-commits] commit: Adding the new configuration scheme.

Mercurial hg at geodynamics.org
Mon Nov 24 11:22:50 PST 2008


changeset:   40:6ca3cf494638
user:        LukeHodkinson
date:        Fri Mar 07 00:08:53 2008 +0000
files:       SConstruct StgSCons config/SConfig/Package.py config/SConfig/SConscript config/SConfig/__init__.py config/SConfig/packages/BlasLapack.py config/SConfig/packages/HDF5.py config/SConfig/packages/MPI.py config/SConfig/packages/OSMesa.py config/SConfig/packages/OpenGL.py config/SConfig/packages/PETSc.py config/SConfig/packages/PICellerator.py config/SConfig/packages/SDL.py config/SConfig/packages/SVNRevision.py config/SConfig/packages/StGermain.py config/SConfig/packages/StgDomain.py config/SConfig/packages/StgFEM.py config/SConfig/packages/__init__.py config/SConfig/packages/cmath.py config/SConfig/packages/dl.py config/SConfig/packages/libFAME.py config/SConfig/packages/libJPEG.py config/SConfig/packages/libPNG.py config/SConfig/packages/libTIFF.py config/SConfig/packages/libXML2.py config/SConfig/packages/libavcodec.py config/packages/__init__.py config/packages/stgMagma.py
description:
Adding the new configuration scheme.


diff -r 3368109c9103 -r 6ca3cf494638 SConstruct
--- a/SConstruct	Fri Mar 07 00:05:38 2008 +0000
+++ b/SConstruct	Fri Mar 07 00:08:53 2008 +0000
@@ -1,71 +1,61 @@ import os
-import os
+import os, sys, platform
 
-# Check versions of some things.
-EnsurePythonVersion(2, 5)
-EnsureSConsVersion(0, 96,93)
+# Source the configuration scripts.
+sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), 'config')))
+SConscript('config/SConfig/SConscript')
 
-#
-# Create our substitution environment.
-#
+# Create our base construction environment.
+if platform.platform().find('ia64') != -1:
+    # Hack needed for APAC, damn it all!
+    env = Environment(ENV=os.environ, tools=['gcc', 'gnulink'])
+else:
+    env = Environment(ENV=os.environ)
 
-env = Environment(ENV=os.environ)
+# Configuring or building? Or helping?
+if 'config' in COMMAND_LINE_TARGETS or 'help' in COMMAND_LINE_TARGETS:
+    import packages
+    opts = Options() # Create our options database.
 
-# Include our SCons utils (hopefully they'll add stuff to do 
-# these things we need).
-SConscript('SConsUtils', exports='env')
+    # Setup all the packages we want configured.
+    env.Package(packages.stgUnderworld, opts)
 
-# Are we configuring or building?
-if ('config' in COMMAND_LINE_TARGETS or 'help' in COMMAND_LINE_TARGETS) \
-        and not env.GetOption('clean'):
-    SConscript('SConfigure', exports='env')
-    env.Alias('config', '.')
-    env.Alias('help', '.')
+    # Displaying help?
+    if 'help' in COMMAND_LINE_TARGETS:
+        env.Alias('help', '.')
+        print opts.GenerateHelpText(env)
+
+    # Or configuring?
+    else:
+        env.configure_packages(opts)
 
 else:
-    # Setup all our StGermain specific utilities.
-    SConscript('StgSCons', exports='env')
+    # Prepare our construction environment.
+    env.load_config('config.cfg') # Load configuration.
+    SConscript('StgSCons', exports='env') # Setup our StG specific utils.
+    if env['staticLibraries']: # Static libs or shared?
+        env.library_builder = env.StaticLibrary
+    else:
+        env.library_builder = env.SharedLibrary
+    env.Default(env['buildPath']) # Needed for different build paths.
+    if platform.system() == 'Darwin': # Need to modify building shared libraries when on Mac OS X.
+        env.AppendUnique(SHLINKFLAGS=['-flat_namespace',
+                                      '-single_module',
+                                      '-undefined', 'suppress'])
+        import SCons.Util # And fix RPATHs.
+        env['LINKFLAGS'] = SCons.Util.CLVar('')
+        env['RPATHPREFIX'] = ''
+        env['RPATHSUFFIX'] = ''
+        env['_RPATH'] = ''
 
-    # Load the configuration.
-    env.load_cfg('config.state')
-
-    # Add any variables that get used throughout the whole build.
-    if env['debug']:
-        env.Append(CCFLAGS='-g')
-    env.Prepend(CPPPATH=['#build/include'])
-    env.Prepend(LIBPATH=['#build/lib'])
-
-    # Setup any additional build targets.
-    env.Alias('install', env['prefix'])
-
-    #
-    # Call target SConscripts.
-    #
-
-    env.BuildDir('build', '.', duplicate=0)
-
-    env.clear_all()
-    SConscript('build/StGermain/SConscript', exports='env')
-    env.Prepend(LIBS=['StGermain'])
-
-    env.clear_all()
-    SConscript('build/StgDomain/SConscript', exports='env')
-    env.Prepend(LIBS=['StgDomain'])
-
-    env.clear_all()
-    SConscript('build/StgFEM/SConscript', exports='env')
-    env.Prepend(LIBS=['StgFEM'])
-
-    env.clear_all()
-    SConscript('build/PICellerator/SConscript', exports='env')
-    env.Prepend(LIBS=['PICellerator'])
-
-    env.clear_all()
-    SConscript('build/Underworld/SConscript', exports='env')
-    env.Prepend(LIBS=['Underworld'])
-
-    env.clear_all()
-    SConscript('build/Magma/SConscript', exports='env')
-    env.Prepend(LIBS=['Magma'])
-
-    env.clear_all()
-    SConscript('build/gLucifer/SConscript', exports='env')
+    # Specify targets.
+    SConscript('StGermain/SConscript', exports='env')
+    env.Prepend(LIBS='StGermain')
+    SConscript('StgDomain/SConscript', exports='env')
+    env.Prepend(LIBS='StgDomain')
+    SConscript('StgFEM/SConscript', exports='env')
+    env.Prepend(LIBS='StgFEM')
+    SConscript('PICellerator/SConscript', exports='env')
+    env.Prepend(LIBS='PICellerator')
+    SConscript('Underworld/SConscript', exports='env')
+    if env['with_glucifer']:
+        SConscript('gLucifer/SConscript', exports='env')
diff -r 3368109c9103 -r 6ca3cf494638 StgSCons
--- a/StgSCons	Fri Mar 07 00:05:38 2008 +0000
+++ b/StgSCons	Fri Mar 07 00:08:53 2008 +0000
@@ -1,13 +1,106 @@ import os
-import os
+import os, glob as pyglob, platform, pickle
 from SCons.Script.SConscript import SConsEnvironment
 
 #
+# Setup some basic path utilities.
+#
+
+# Globbing for hierarchical SCons scripts.
+def glob(env, ptrn):
+    if not os.path.isabs(ptrn):
+        old = os.getcwd()
+        os.chdir(Dir('.').srcnode().abspath)
+        res = pyglob.glob(ptrn)
+        os.chdir(old)
+    else:
+        res = pyglob.glob(ptrn)
+    return res
+
+# Normalise an SCons path to the project root.
+def norm_path(env, path):
+    cur_dir = env.Dir('.').srcnode().path
+    if path[0] != '#':
+        path = os.path.join(cur_dir, path)
+    else:
+        path = path[1:]
+    return path
+
+# Copy a file immediately.
+def copy_file(env, dst, src):
+    if env.GetOption('clean'):
+        return
+    dst = env.norm_path(dst)
+    old = os.getcwd()
+    os.chdir(env.GetLaunchDir())
+    f = File(os.path.abspath(dst))
+    f.binfo = f.gen_binfo() # Hack to make work with later versions.
+    if not f.is_up_to_date():
+        src = env.norm_path(src)
+        dst_dir = os.path.dirname(dst)
+        if not os.path.exists(dst_dir):
+            Execute(Mkdir(dst_dir))
+        Execute(Copy(dst, src))
+        os.chdir(old)
+
+# Add to the SCons main class.
+SConsEnvironment.glob = glob
+SConsEnvironment.norm_path = norm_path
+SConsEnvironment.copy_file = copy_file
+
+#
+# Setup the hierarchical build stuff.
+#
+
+def hbuild(env, builder, hpath, store=True, *args, **kw):
+    nodes = builder(*args, **kw)
+    if store:
+        if builder not in env.hbuilders:
+            env.hbuilders.append(builder)
+        ind = env.hbuilders.index(builder)
+        if ind not in env.hnodes:
+            env.hnodes[ind] = {}
+        place = env.hnodes[ind]
+        if '.' not in place:
+            place['.'] = []
+        place['.'].append(nodes)
+        for h in hpath.split(os.path.sep):
+            if h not in place:
+                place[h] = {}
+            place = place[h]
+            if '.' not in place:
+                place['.'] = []
+            place['.'].append(nodes)
+    return nodes
+
+def get_hnodes(env, builder, hpath=None):
+    ind = env.hbuilders.index(builder)
+    place = env.hnodes[ind]
+    if hpath:
+        for h in hpath.split(os.path.sep):
+            place = place[h]
+    return place['.']
+
+def hclear(env):
+    env.hnodes = {}
+    env.hbuilders = []
+
+SConsEnvironment.hbuild = hbuild
+SConsEnvironment.get_hnodes = get_hnodes
+SConsEnvironment.hclear = hclear
+
+#
 # Helper functions.
 #
 
+def to_list(var):
+    if isinstance(var, list):
+        return var
+    else:
+        return [var]
+
 def copy_includes(env, files, dst, inc_nodes, force=False):
-    files = files if isinstance(files, list) else [files]
-    dst = os.path.join('#build', dst)
+    files = to_list(files)
+    dst = os.path.join(env['buildPath'], dst)
     for i in files:
         node = env.Install(dst, i)
         inc_nodes.append(node)
@@ -19,6 +112,9 @@ def copy_includes(env, files, dst, inc_n
 # Builder helpers.
 #
 
+def get_target_name(env, src, suffix='.c'):
+    return os.path.join(env['buildPath'], env.project_name, src[:-len(suffix)])
+
 def build_defines(env, files, dst):
     copy_includes(env, files, os.path.join('include', dst), 
                   env.def_nodes, True)
@@ -32,52 +128,58 @@ def build_xmls(env, files, dst, force_co
                   env.hdr_nodes, force_copy)
 
 def build_objects(env, files, hpath, store=True):
-    files = files if isinstance(files, list) else [files]
+    files = to_list(files)
     nodes = []
-    name = env.proj + ''.join(hpath.split(os.path.sep))
+    name = env.project_name + ''.join(hpath.split(os.path.sep))
     mod = [('CURR_MODULE_NAME', env['ESCAPE']('"' + name + '"'))]
     for src in files:
+        tgt = get_target_name(env, src)
         cur_node = env.hbuild(env.SharedObject, hpath, store,
-                              source=src,
+                              target=tgt, source=src,
                               CPPDEFINES=env['CPPDEFINES'] + mod)
         nodes.append(cur_node)
     return nodes
 
 def build_metadata(env, files, hpath):
-    files = files if isinstance(files, list) else [files]
+    files = to_list(files)
     nodes = []
     for m in files:
-        src = env.Meta(m)
-        cur_node = env.hbuild(env.SharedObject, hpath, source=src)
+        tgt = get_target_name(env, m, '.meta')
+        src = env.Meta(target=tgt, source=m)
+        tgt = src[0].path[:-2]
+        cur_node = env.hbuild(env.SharedObject, hpath,
+                              target=tgt, source=src)
         nodes.append(cur_node)
     return nodes
 
 def build_library(env, objs, name, libs=[], force_name=False):
-    objs = objs if isinstance(objs, list) else [objs]
-    dst = os.path.join('#build', 'lib', name)
+    objs = to_list(objs)
+    dst = os.path.join(env['buildPath'], 'lib', name)
     if force_name:
-        cur_node = env.SharedLibrary(
+        cur_node = env.library_builder(
             dst, objs,
             SHLIBPREFIX='',
             LIBPREFIXES=[env['LIBPREFIXES']] + [''],
 	    LIBS=libs + env.get('LIBS', []))
     else:
-        cur_node = env.SharedLibrary(dst, objs, LIBS=libs + env.get('LIBS', []))
-    env.lib_nodes.append(cur_node)
+        cur_node = env.library_builder(dst, objs, LIBS=libs + env.get('LIBS', []))
+    env.lib_nodes.insert(0, cur_node)
 
 def build_tests(env, files, name, sup_objs=[], libs=None):
     if not libs:
         libs = env.lib_nodes
-    files = files if isinstance(files, list) else [files]
-    sup_objs = [sup_objs] if isinstance(sup_objs, str) else sup_objs
+    files = to_list(files)
+    sup_objs = to_list(sup_objs)
     nodes = env.test_nodes
     mod = [('CURR_MODULE_NAME', env['ESCAPE']('"' + name + '"'))]
-    l = libs if isinstance(libs, list) else [libs]
+    l = to_list(libs)
     for src in files:
-        dst = os.path.join('#build', 'tests',
+        tgt = get_target_name(env, src)
+        obj_node = env.SharedObject(tgt, src,
+                                    CPPDEFINES=env.get('CPPDEFINES') + mod)
+        dst = os.path.join(env['buildPath'], 'tests',
                            os.path.splitext(os.path.basename(src))[0])
-        cur_node = env.Program(dst, [src] + sup_objs,
-                               CPPDEFINES=env['CPPDEFINES'] + mod,
+        cur_node = env.Program(dst, obj_node + sup_objs,
                                LIBS=l + env.get('LIBS', []))
         nodes.append(cur_node)
 
@@ -85,11 +187,11 @@ def build_directory(env, dir, extra_objs
                     test_libs=None, build_lib=True):
     if not test_libs:
         test_libs = env.lib_nodes
-    test_libs = [test_libs] if isinstance(test_libs, str) else test_libs
-    extra_objs = [extra_objs] if isinstance(extra_objs, str) else extra_objs
+    test_libs = to_list(test_libs)
+    extra_objs = to_list(extra_objs)
     srcDir = os.path.join(dir, 'src')
     tstDir = os.path.join(dir, 'tests')
-    hdrDir = os.path.join(env.proj, dir)
+    hdrDir = os.path.join(env.project_name, dir)
     mod = ''.join(hdrDir.split(os.path.sep))
 
     env.build_defines(env.glob(os.path.join(srcDir, '*.def')), hdrDir)
@@ -111,14 +213,14 @@ def build_plugin(env, dir, hpath, prefix
 def build_plugin(env, dir, hpath, prefix=True):
     name = hpath.split(os.path.sep)
     if prefix:
-        name = [env.proj] + name
+        name = [env.project_name] + name
     name = '_'.join(name) + 'module'
-    hdr_dir = os.path.join(env.proj, hpath.split(os.path.sep)[-1])
+    hdr_dir = os.path.join(env.project_name, hpath.split(os.path.sep)[-1])
 
     env.build_headers(env.glob(os.path.join(dir, '*.h')), hdr_dir)
     objs = env.build_objects(env.glob(os.path.join(dir, '*.c')),
                          hpath, False)
-    env.build_library(objs, name, [env.proj], True)
+    env.build_library(objs, name, [env.project_name], True)
 
 def clear_all(env):
     env.hclear()
@@ -162,8 +264,32 @@ def create_meta(target, source, env):
             output_file.write(l[start+19:end])
             output_file.write("\n")
             break
-    template_file=file("meta-template.c")
-    output_file.write(template_file.read())
+    output_file.write('''
+#define Stg_Component_Stringify( str ) #str
+
+/* Note: Two macros are used to resolve the the extra macro level */
+#define Stg_Component_Metadata_Create( name ) Stg_Component_Metadata_Create_Macro( name )
+#define Stg_Component_Metadata_Create_Macro( name ) \
+	const char* name ##_Meta = XML_METADATA; \
+	const char* name ##_Name = #name; \
+	const char* name ##_Version = VERSION; \
+	const char* name ##_Type_GetMetadata() { /* hack...won't be needed when hierarchy rollout is done */\
+		return name ##_Meta; \
+	} \
+	const char* name ##_GetMetadata() { \
+		return name ##_Meta; \
+	} \
+	const char* name ##_GetName() { \
+		return name ##_Name; \
+	} \
+	const char* name ##_GetVersion() { \
+		return name ##_Version; \
+	}
+
+#if defined(COMPONENT_NAME) && defined(VERSION) && defined(XML_METADATA)
+	Stg_Component_Metadata_Create( COMPONENT_NAME )
+#endif
+''')
 
 def gen_meta_suffix(env, sources):
     return "-meta.c"
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/Package.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/Package.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,597 @@
+import os, platform, glob
+import SCons.Script
+import SConfig
+
+class Package(object):
+    def __init__(self, env, options=None, required=True):
+        # Construct this package's name.
+        self.name = self.__module__.split('.')[-1]
+        self.option_name = self.name.lower()
+        self.environ_name = self.name.upper()
+        self.command_options = {}
+        self.environ_options = {}
+
+        # Setup some system specific information.
+        self.system = platform.system()
+        if platform.architecture()[0].find('64') != -1:
+            self.bits = 64
+        else:
+            self.bits = 32
+
+        # Setup the options immediately, that way we can access them
+        # in sub-classes.
+        self.opts = options
+        self.setup_options()
+        if self.opts:
+            self.opts.Update(env)
+
+        # Is this package essential?
+        self.required          = required
+
+        # Language options.
+        self.language          = 'C' # 'C' | 'CXX' | 'F77'
+        self.have_define       = ''
+
+        # Search options.
+        self.base_dirs         = [] #['']
+        self.base_patterns     = [] #['']
+        self.sub_dirs          = [] #[[[''], ['']]]
+        self.header_sub_dir    = ''
+
+        # Header options.
+        self.headers            = [[]] #[['']]
+
+        # Library options.
+        self.libraries         = [] #[['']]
+        self.require_shared    = False
+        self.use_rpath         = True
+        self.symbols           = [([], '')] #[([''], '')]
+        self.symbol_setup      = ''
+        self.symbol_teardown   = ''
+        self.symbol_prototypes = [] #['']
+        self.symbol_calls      = [] #['']
+
+        # Framework options.
+        self.frameworks        = [] #[['']]
+
+        # Version checking options.
+        self.version           = [] #[['', 0]]
+
+        # A list of checks to perform for this package.
+        self.checks            = [self.find_package]
+
+        # Once configured, these values will be set.
+        self.configured = False
+        self.result = [0, '', '']
+        self.cpp_defines = []
+        self.base_dir = ''
+        self.hdr_dirs = []
+        self.hdrs = []
+        self.lib_dirs = []
+        self.libs = []
+        self.have_shared = None
+        self.fworks = []
+        self.state = {}
+
+        # Private stuff.
+        self.env = env
+        self.deps = []
+
+        self.setup_search_defaults()
+
+    def setup_search_defaults(self):
+        # Set common defaults of Darwin and Linux.
+        if self.system in ['Darwin', 'Linux']:
+            self.base_dirs = ['/usr', '/usr/local']
+            self.sub_dirs = [[['include'], ['lib']]]
+            if self.bits == 64:
+                self.sub_dirs = [[['include'], ['lib64']],
+                                 [['include'], [os.path.join('lib', '64')]]] + self.sub_dirs
+
+        # Set Darwin specific defaults.
+        if self.system == 'Darwin':
+            self.base_dirs += ['/sw']
+
+        # Set Window specific defaults.
+        if self.system == 'Windows':
+            pass # TODO
+
+    def setup_options(self):
+        if not self.opts:
+            return
+        self.command_options = [self.option_name + 'Dir',
+                                self.option_name + 'IncDir',
+                                self.option_name + 'LibDir',
+                                self.option_name + 'Lib',
+                                self.option_name + 'Framework']
+        self.environ_options = {self.option_name + 'Dir': self.environ_name + '_DIR',
+                                self.option_name + 'IncDir': self.environ_name + '_INC_DIR',
+                                self.option_name + 'LibDir': self.environ_name + '_LIB_DIR',
+                                self.option_name + 'Lib': self.environ_name + '_LIB',
+                                self.option_name + 'Framework': self.environ_name + '_FRAMEWORK'}
+        self.opts.AddOptions(
+            SCons.Script.PathOption(self.option_name + 'Dir',
+                                    '%s installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            SCons.Script.PathOption(self.option_name + 'IncDir',
+                                    '%s header installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            SCons.Script.PathOption(self.option_name + 'LibDir',
+                                    '%s library installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            (self.option_name + 'Lib',
+             '%s libraries' % self.name,
+             None, None),
+            (self.option_name + 'Framework',
+             '%s framework' % self.name,
+             None, None))
+
+    def get_headers_error_message(self, console):
+        return ''
+
+    def get_run_error_message(self, console):
+        return ''
+
+    def configure(self, configure_context):
+        """Perform the configuration of this package. Override this method to perform
+        custom configuration checks."""
+        # If we've already configured this package, just return.
+        if self.configured:
+            return
+
+        # Setup our configure context and environment.
+        self.ctx = configure_context
+        self.configured = True
+
+        # If we have shared libraries enabled, we must ensure the dynamic loader
+        # package is included.
+        if self.require_shared:
+            self.pkg_dl = self.require(SConfig.packages.dl)
+
+        # Process dependencies first.
+        self.process_dependencies()
+
+        # Process options.
+        self.process_options()
+
+        # Perfrom actual configuration.
+        for check in self.checks:
+            result = check()
+            if not result[0]:
+                break
+
+        # Required?
+        if self.required and not result[0]:
+            self.ctx.Display('\nThe required package ' + self.name + ' could not be found.\n')
+            self.ctx.Display('The printouts above should provide some information on what went wrong,\n')
+            self.ctx.Display('To see further details, please read the \'config.log\' file.\n')
+            if len(self.command_options):
+                self.ctx.Display('You can directly specify search parameters for this package via\n')
+                self.ctx.Display('the following command line options:\n\n')
+                for opt in self.command_options:
+                    self.ctx.Display('  ' + opt + '\n')
+                self.ctx.Display('\nRun \'scons help\' for more details on these options.\n\n')
+            self.env.Exit()
+
+        # If we succeeded, store the resulting environment.
+        if result[0]:
+            if self.have_define:
+                self.cpp_defines += [self.have_define]
+            self.build_state()
+            self.push_state(self.state)
+
+        return result
+
+    def require(self, package_module):
+        pkg = self.env.Package(package_module, self.opts)
+        self.deps += [pkg]
+        return pkg
+
+    def process_dependencies(self):
+        """Ensure all dependencies have been configured before this package."""
+        for pkg in self.deps:
+            pkg.configure(self.ctx)
+
+    def process_options(self):
+        """Do any initial option processing, including importing any values from
+        the environment and validating that all options are consistent."""
+        cmd_opts = False
+        for opt in self.command_options:
+            if opt in self.opts.args:
+                cmd_opts = True
+                break
+        if cmd_opts:
+            return
+        for cmd, env in self.environ_options.iteritems():
+            if cmd not in self.opts.args and env in self.env['ENV']:
+                self.env[cmd] = self.env['ENV'][env]
+
+    def find_package(self):
+        # Search for package locations.
+        self.ctx.Message('Checking for package %s ... ' % self.name)
+        self.ctx.Display('\n   Searching locations:\n')
+        for loc in self.generate_locations():
+            result = self.check_location(loc)
+            self.ctx.Display('      %s\n' % str(loc))
+
+            # If we succeeded, back out here.
+            if result[0]:
+                break
+
+            # Display an error message.
+            if result[2]:
+                self.ctx.Display('         %s\n' % result[2])
+
+        # Display results.
+        self.ctx.Display('   ')
+        self.ctx.Result(result[0])
+
+        return result
+
+    def check_location(self, location):
+        """Check if the currently selected location is a valid installation of the
+        required package. At this stage we know that the paths given in the location
+        actually exist."""
+        # Validate the headers, first.
+        result = self.validate_location(location)
+        if not result[0]:
+            return result
+
+        # Construct our path state.
+        path_state = self.build_header_state(location)
+        old = self.push_state(path_state)
+
+        # Check for the headers.
+        result = self.check_headers(location)
+        if not result[0]:
+            self.pop_state(old)
+            return result
+
+        # Scan each set of libraries in turn.
+        libs = []
+        for libs in self.libraries:
+            result = self.check_libs(location, libs)
+            if result[0]:
+                break
+
+        # Store last known configuration.
+        self.store_result(result, location, libs)
+
+        # Roll-back on state.
+        self.pop_state(old)
+        return result
+
+    def check_headers(self, location):
+        """Determine if the required headers are available with the current construction
+        environment settings."""
+        for hdrs in self.headers:
+            src = self.get_header_source(hdrs)
+            result = self.run_scons_cmd(self.ctx.TryCompile, src, '.c')
+            if result[0]:
+                self.hdrs = list(hdrs)
+                break
+        if not result[0]:
+            msg = self.get_headers_error_message(result[1])
+            if not msg:
+                msg = 'Failed to locate headers.'
+        else:
+            msg = ''
+        return [result[0], '', msg]
+
+    def check_libs(self, location, libs):
+        """Check if the currently selected location is a valid installation of the
+        required package. At this stage we know that the paths given in the location
+        actually exist and we need to confirm that the libraries in 'libs' exist."""
+        # Validate the libraries.
+        result = self.validate_libraries(location, libs)
+        if not result[0]:
+            return result
+
+        # Construct the library state.
+        lib_state = self.build_lib_state(location, libs)
+        old = self.push_state(lib_state)
+
+        # Check that we can link against the libraries by trying to link against
+        # a particular set of symbols.
+        result = self.check_symbols()
+        if not result[0]:
+            if not result[2]:
+                result[2] = 'Failed to link against library(s).'
+            self.pop_state(old)
+            return result
+
+        # Check if we have shared libraries.
+        if self.require_shared:
+            result = self.check_shared(location, libs)
+            if not result[0] and not result[2]:
+                result[2] = 'No shared library(s) available.'
+
+        # Roll-back on our state.
+        self.pop_state(old)
+        return result
+
+    def check_symbols(self):
+        """We have our paths and libraries setup, now we need to see if we can find
+        one of the set of required symbols in the libraries."""
+        for syms in self.symbols:
+            result = self.run_source(self.get_check_symbols_source(syms[0]))
+            if result[0]:
+                if syms[1]:
+                    self.cpp_defines += [syms[1]] # Add the CPP defines.
+                break
+        return result
+
+    def check_shared(self, location, libs):
+        """Confirm that there are shared versions of this package's libraries available."""
+        if not self.pkg_dl.result[0]:
+            return [0, '', 'No dynamic loader found (libdl).']
+
+        # Build a binary to try and dynamically open the library.
+        result = [1, '', '']
+        for l in libs:
+            src = self.get_header_source()
+            src += '#include<dlfcn.h>\n'
+            src += """
+int main(int argc, char* argv[]) {
+  void* lib;
+  lib = dlopen("%s", RTLD_LAZY);
+  return lib ? 0 : 1;
+}
+""" % self.env.subst('${SHLIBPREFIX}' + l + '${SHLIBSUFFIX}')
+            result = self.run_source(src)
+            if not result[0]:
+                break
+        return result
+
+    def run_source(self, source):
+        """At this point we know all our construction environment has been set up,
+        so we should be able to build and run the application."""
+        result = self.run_scons_cmd(self.ctx.TryRun, source, '.c')
+        msg = self.get_run_error_message(result[1])
+        return [result[0][0], result[0][1], msg]
+
+    def validate_location(self, location):
+        """Confirm that the location is okay, possibly modifying it in place if
+        there are additional locations to search."""
+        return [1, '', '']
+
+    def validate_libraries(self, location, libs):
+        """Confirm that the specified libraries are okay, possibly modifying in
+        place the list of libraries."""
+        return [1, '', '']
+
+    def generate_locations(self):
+        """Generate a set of potential package locations. Locations are of the form
+        ['base_dir', ['header_dirs'], ['lib_dirs'], ['frameworks']]."""
+        # If we've been given options directly specifying the location of this
+        # package we need to use those in place of searching for locations.
+        base_dir = self.env.get(self.option_name + 'Dir', '')
+        inc_dir = self.env.get(self.option_name + 'IncDir', '')
+        lib_dir = self.env.get(self.option_name + 'LibDir', '')
+        fwork = self.env.get(self.option_name + 'Framework', '')
+        if inc_dir or lib_dir:
+            if not (inc_dir and lib_dir):
+                print '   Error: must specify both of'
+                print '      ' + self.option_name + 'IncDir'
+                print '      ' + self.option_name + 'LibDir'
+                env.Exit()
+            yield ['', [inc_dir], [lib_dir], [fwork]]
+            return
+        have_loc = base_dir or inc_dir or lib_dir
+
+        # Produce an empty location to see if the package exists in a default
+        # location.
+        if not have_loc:
+            yield ['', [], [], []]
+
+        # Combine all possible base directories.
+        if not base_dir:
+            base_dirs = list(self.base_dirs)
+            for dir in self.base_dirs:
+                for ptrn in self.base_patterns:
+                    base_dirs += glob.glob(os.path.join(dir, ptrn))
+        else:
+            base_dirs = [base_dir]
+
+        # Add an empty set to the beginning of the frameworks.
+        if not fwork:
+            frameworks = [[]] + self.frameworks
+        else:
+            frameworks = [fwork]
+
+        for fw in frameworks:
+            # If we have some frameworks, try them alone first.
+            if not have_loc and fw:
+                yield ['', [], [], list(fw)]
+
+            # Traverse the list of base directories, using them only if they exist.
+            for dir in base_dirs:
+                if os.path.exists(dir) and os.path.isdir(dir):
+                    for hdr, lib in self.combine_sub_dirs(dir):
+                        yield [dir, list(hdr), list(lib), list(fw)]
+                        for sub in self.combine_header_sub_dir(dir, hdr):
+                            yield [dir, list(sub), list(lib), list(fw)]
+
+    def combine_sub_dirs(self, base_dir):
+        """Take a base directory and combine it with the set of header and library
+        subdirectories. Yields (['header_dirs'], ['lib_dirs'])."""
+        for hdr, lib in self.sub_dirs:
+            loc_okay = True
+            hdr_dirs = []
+            lib_dirs = []
+
+            # Combine header subdirectories.
+            for h in hdr:
+                dir = self.join_sub_dir(base_dir, h)
+                if not (os.path.exists(dir) and os.path.isdir(dir)):
+                    loc_okay = False
+                    break
+                hdr_dirs += [h]
+            if not loc_okay:
+                continue
+
+            # Combine library subdirectories.
+            for l in lib:
+                dir = self.join_sub_dir(base_dir, l)
+                if not (os.path.exists(dir) and os.path.isdir(dir)):
+                    loc_okay = False
+                    break
+                lib_dirs += [l]
+            if not loc_okay:
+                continue
+
+            yield (hdr_dirs, lib_dirs)
+
+    def combine_header_sub_dir(self, base_dir, hdr_dirs):
+        if not self.header_sub_dir or not hdr_dirs:
+            return
+        cand = [os.path.join(h, self.header_sub_dir) for h in hdr_dirs if h]
+        for d in cand:
+            path = os.path.join(base_dir, d)
+            if not (os.path.exists(path) and os.path.isdir(path)):
+                return
+        yield cand
+
+    def join_sub_dir(self, base_dir, sub_dir):
+        if os.path.isabs(sub_dir):
+            return sub_dir
+        return os.path.join(base_dir, sub_dir)
+
+    def build_header_state(self, location):
+        """Build a construction state for including headers."""
+        state = {}
+        if location[1]:
+            state['CPPPATH'] = [self.join_sub_dir(location[0], l) for l in location[1]]
+        if location[3]:
+            state['FRAMEWORKS'] = location[3]
+        return state
+
+    def build_lib_state(self, location, libs):
+        """Take the current location and libraries and convert them into an SCons
+        construction environment state dictionary."""
+        state = {}
+        if location[2]:
+            state['LIBPATH'] = [self.join_sub_dir(location[0], l) for l in location[2]]
+            if self.use_rpath:
+                state['RPATH'] = [os.path.abspath(p) for p in state['LIBPATH']]
+        if location[3]:
+            state['FRAMEWORKS'] = location[3]
+        if libs:
+            state['LIBS'] = libs
+        return state
+
+    def build_state(self):
+        self.state = {}
+        if self.cpp_defines:
+            self.state['CPPDEFINES'] = self.cpp_defines
+        if self.hdr_dirs:
+            self.state['CPPPATH'] = [self.join_sub_dir(self.base_dir, d) \
+                                         for d in self.hdr_dirs]
+        if self.fworks:
+            self.state['FRAMEWORKS'] = self.fworks
+        if self.lib_dirs:
+            self.state['LIBPATH'] = [self.join_sub_dir(self.base_dir, d) \
+                                         for d in self.lib_dirs]
+            if self.use_rpath:
+                self.state['RPATH'] = [os.path.abspath(p) for p in self.state['LIBPATH']]
+        if self.libs:
+            self.state['LIBS'] = self.libs
+
+    def store_result(self, result, location, libs):
+        self.result = result
+        self.base_dir = location[0]
+        self.hdr_dirs = location[1]
+        self.lib_dirs = location[2]
+        self.libs = libs
+        if self.require_shared:
+            self.have_shared = True
+        else:
+            self.have_shared = None
+        self.fworks = location[3]
+
+    def push_state(self, state, append=False):
+        old = {}
+        copy = dict(state)
+        for k, v in copy.iteritems():
+            if not isinstance(v, list):
+                copy[k] = [v]
+            else:
+                copy[k] = v
+            old[k] = self.env.get(k, None)
+        if append:
+            self.env.AppendUnique(**copy)
+        else:
+            self.env.PrependUnique(**copy)
+        return old
+
+    def pop_state(self, old):
+        self.env.Replace(**old)
+
+    def get_all_headers(self, headers):
+        if not self.result[0]:
+            return
+        headers += [h for h in self.hdrs if h not in headers]
+        for d in self.deps:
+            d.get_all_headers(headers)
+
+    def get_header_source(self, headers=None):
+        src = '#include<stdlib.h>\n#include<stdio.h>\n#include<string.h>\n'
+        if headers is None:
+            hdrs = list(self.hdrs)
+        else:
+            hdrs = list(headers)
+        for d in self.deps:
+            d.get_all_headers(hdrs)
+        for h in hdrs:
+            src += '#include<' + h + '>\n'
+        return src
+
+    def get_check_symbols_source(self, symbols):
+        src = self.get_header_source()
+        for sym, proto in zip(symbols, self.symbol_prototypes):
+            src += (proto % sym) + '\n'
+        src += 'int main(int argc, char* argv[]) {\n'
+        if self.symbol_setup:
+            src += self.symbol_setup + '\n'
+        for sym, call in zip(symbols, self.symbol_calls):
+            src += (call % sym) + '\n'
+        if self.symbol_teardown:
+            src += self.symbol_teardown + '\n'
+        src += 'return 0;\n}\n'
+        return src
+
+    def run_scons_cmd(self, cmd, *args, **kw):
+        # Capture the log.
+        old_log = self.ctx.sconf.logstream
+        self.ctx.sconf.logstream = open('sconfig.log', 'w')
+
+        # Execute the command.
+        res = cmd(*args, **kw)
+
+        # Make sure the file is closed.
+        try:
+            self.ctx.sconf.logstream.close()
+        finally:
+            pass
+
+        # Replace the old log.
+        self.ctx.sconf.logstream = old_log
+
+        # Return results.
+        log_file = open('sconfig.log', 'r')
+        log = log_file.read()
+        log_file.close()
+        os.remove('sconfig.log')
+        old_log.write(log)
+        return (res, log)
+
+    def __str__(self):
+        str =  'Package name:  %s\n' % self.name
+        str += 'Found:         %s\n' % self.result[0]
+        str += 'Base path:     %s\n' % self.base_dir
+        str += 'Header paths:  %s\n' % self.hdr_dirs
+        str += 'Library paths: %s\n' % self.lib_dirs
+        str += 'Libraries:     %s\n' % self.libs
+        str += 'Have shared:   %s\n' % self.have_shared
+        str += 'Frameworks:    %s\n' % self.fworks
+        return str
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/SConscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/SConscript	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,68 @@
+import os
+from SCons.Script.SConscript import SConsEnvironment
+
+#
+# Setup the Package system.
+#
+
+def Package(env, pkg_module, options=None):
+    # Setup the SCons environment to hold packages if not already
+    # done.
+    if not hasattr(env, 'packages'):
+        env.packages = {}
+        env.package_list = []
+
+    if not pkg_module in env.packages:
+        # Add an instance of this package.
+        env.packages[pkg_module] = pkg_module(env, options)
+        env.package_list += [env.packages[pkg_module]]
+
+    return env.packages[pkg_module]
+
+def CheckPackages(ctx, pkg_list):
+    for pkg in pkg_list:
+        pkg.configure(ctx)
+
+def save_config(env, filename, vars):
+    d = {}
+    for a in vars:
+        if a in env._dict:
+            d[a] = env[a]
+    f = file(filename, 'w')
+    import pickle
+    pickle.dump(d, f)
+    f.close()
+
+def load_config(env, filename):
+    if not os.path.exists(filename):
+        print "\nError: project hasn't been configured!\n"
+        print '************************************************'
+        print "* Run 'scons config' to configure the project. *"
+        print '************************************************\n'
+        env.Exit()
+    f = file(filename, 'r')
+    import pickle
+    d = pickle.load(f)
+    f.close()
+    for k, v in d.iteritems():
+        env[k] = v
+
+def configure_packages(env, options=None, output='config.cfg'):
+    sconf = Configure(env, custom_tests={'CheckPackages': CheckPackages})
+
+    # Call the packages checker.
+    sconf.CheckPackages(env.package_list)
+
+    # Dump results to our output file.
+    vars = ['CFLAGS', 'CCFLAGS',
+            'CPPPATH', 'CPPDEFINES',
+            'LIBPATH', 'LIBS', 'RPATH',
+            'FRAMEWORKS']
+    if options:
+        vars += options.keys()
+    env.save_config(output, vars)
+
+SConsEnvironment.Package = Package
+SConsEnvironment.configure_packages = configure_packages
+SConsEnvironment.save_config = save_config
+SConsEnvironment.load_config = load_config
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/__init__.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,2 @@
+from Package import Package
+import packages
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/BlasLapack.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/BlasLapack.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,51 @@
+import os
+import SConfig
+
+class BlasLapack(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.cmath = self.require(SConfig.packages.cmath)
+        self.libraries = [['blas', 'lapack'],
+                          ['cblas', 'clapack'],
+                          ['mkl', 'mkl_lapack']]
+        self.frameworks = [['Accelerate']]
+        self.symbols = [(['dgeev'], 'FORTRAN_NORMAL'),
+                        (['dgeev_'], 'FORTRAN_SINGLE_TRAILINGBAR'),
+                        (['dgeev__'], 'FORTRAN_DOUBLE_TRAILINGBAR'),
+                        (['DGEEV'], 'FORTRAN_UPPERCASE')]
+        self.symbol_setup = '''char jobVecLeft='N';
+char jobVecRight='N';
+int dim=1;
+double* arrayA=NULL;
+double* outputReal=NULL;
+double* outputImag=NULL;
+double* leftEigenVec=NULL;
+double* rightEigenVec=NULL;
+int leadDimVL=1;
+int leadDimVR=1;
+double* workSpace=NULL;
+int dimWorkSpace;
+int INFO=0;
+
+dimWorkSpace=10*dim;
+arrayA=malloc(dim*dim*sizeof(double));
+memset(arrayA, 0, dim*dim*sizeof(double));
+outputReal=malloc(dim*sizeof(double));
+outputImag=malloc(dim*sizeof(double));
+memset(outputReal, 0, dim*sizeof(double));
+memset(outputImag, 0, dim*sizeof(double));
+workSpace=malloc(dimWorkSpace*sizeof(double));
+leftEigenVec=malloc(leadDimVL*dim*sizeof(double));
+rightEigenVec=malloc(leadDimVR*dim*sizeof(double));
+memset(leftEigenVec, 0, leadDimVL*dim*sizeof(double));
+memset(rightEigenVec, 0, leadDimVR*dim*sizeof(double));
+'''
+        self.symbol_teardown = '''free(arrayA);
+free(outputReal);
+free(outputImag);
+free(workSpace);
+free(leftEigenVec);
+free(rightEigenVec);
+'''
+        self.symbol_prototypes = ['void %s(char*,char*,int*,double*,int*,double*,double*,double*,int*,double*,int*,double*,int*,int*);']
+        self.symbol_calls = ['%s(&jobVecLeft, &jobVecRight, &dim, arrayA, &dim, outputReal, outputImag, leftEigenVec, &leadDimVL, rightEigenVec, &leadDimVR, workSpace, &dimWorkSpace, &INFO );']
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/HDF5.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/HDF5.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class HDF5(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['hdf5.h']]
+        self.libraries = [['hdf5']]
+        self.have_define = 'HAVE_HDF5'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/MPI.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/MPI.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,24 @@
+import os
+import SConfig
+
+class MPI(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.base_patterns = ['mpich*', 'MPICH*']
+        self.header_sub_dir = 'mpi'
+        self.headers = [['mpi.h']]
+        self.libraries = [['mpich'],
+                          ['mpich', 'pmpich'],
+                          ['mpich', 'rt'],
+                          ['mpich', 'pmpich', 'rt'],
+                          ['mpi']]
+        self.require_shared = True
+        self.use_rpath = True
+
+    def validate_location(self, location):
+        for lib_dir in location[2]:
+            shared_dir = os.path.join(lib_dir, 'shared')
+            path = os.path.join(location[0], shared_dir)
+            if os.path.exists(path):
+                location[2] += [shared_dir]
+        return [1, '', '']
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/OSMesa.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/OSMesa.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,8 @@
+import os
+import SConfig
+
+class OSMesa(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.libraries = [['GL', 'GLU']]
+        self.have_define = 'HAVE_MESA'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/OpenGL.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/OpenGL.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,12 @@
+import os
+import SConfig
+
+class OpenGL(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.header_sub_dir = 'GL'
+        self.headers = [['gl.h', 'glu.h'],
+                        ['OpenGL/gl.h', 'OpenGL/glu.h']] # For framework.
+        self.libraries = [['GL', 'GLU']]
+        self.frameworks = [['OpenGL']]
+        self.have_define = 'HAVE_GL'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/PETSc.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/PETSc.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,65 @@
+import os
+import SConfig
+
+class PETSc(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.require(SConfig.packages.MPI)
+        self.base_patterns = ['petsc*', 'PETSC*', 'PETSc*']
+        self.header_sub_dir = 'petsc'
+        self.headers = [['petsc.h',
+                         'petscvec.h', 'petscmat.h',
+                         'petscksp.h', 'petscsnes.h']]
+        self.libraries = [['petscsnes', 'petscksp',
+                           'petscmat', 'petscvec',
+                           'petscdm', 'petsc',]]
+        self.require_shared = True
+        self.use_rpath = True
+        self.have_define = 'HAVE_PETSC'
+
+        # Other stuff.
+        self.arch = ''
+
+    def validate_location(self, location):
+        # Must have a base directory.
+        if not location[0]:
+            return (1, '', '')
+
+        # Get the architecture.
+        arch = self.get_petsc_arch(location[0])
+        if not arch:
+            return (0, '', 'Could not read architecture from petscconf.')
+        self.arch = arch
+
+        # Add the bmake/arch include directory.
+        hdr_dir = os.path.join('bmake', arch)
+        if not os.path.exists(os.path.join(location[0], hdr_dir)):
+            return [0, '', 'No bmake/<arch> directory.']
+        if hdr_dir not in location[1]:
+            location[1] += [hdr_dir]
+
+        # Add the lib/arch library directory.
+        if 'lib' in location[2]:
+            location[2].remove('lib')
+        lib_dir = os.path.join('lib', arch)
+        if not os.path.exists(os.path.join(location[0], lib_dir)):
+            return [0, '', 'No lib/<arch> directory.']
+        if lib_dir not in location[2]:
+            location[2] += [lib_dir]
+
+        return [1, '', '']
+
+    def get_headers_error_message(self, console):
+        if console.find('MPI_') != -1:
+            return 'Incompatible implementation of MPI.'
+        return ''
+
+    def get_petsc_arch(self, base_dir):
+        petscconf = os.path.join(base_dir, 'bmake',
+                                 'petscconf')
+        if not os.path.exists(petscconf):
+            return None
+        f = file(petscconf, 'r')
+        arch = f.readline().split('=')[1][:-1]
+        f.close()
+        return arch
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/PICellerator.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/PICellerator.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,28 @@
+import os
+import SConfig
+
+class PICellerator(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.require(SConfig.packages.StGermain)
+        self.require(SConfig.packages.StgDomain)
+        self.require(SConfig.packages.StgFEM)
+        self.base_patterns = ['PICellerator*']
+        self.headers = [[os.path.join('PICellerator', 'PICellerator.h')]]
+        self.libraries = [['PICellerator']]
+        self.symbols = [(['PICellerator_Init', 'PICellerator_Finalise'], '')]
+        self.symbol_setup = '''MPI_Init(&argc, &argv);
+StGermain_Init(&argc, &argv);
+StgDomain_Init(&argc, &argv);
+StgFEM_Init(&argc, &argv);'''
+        self.symbol_teardown = '''StgFEM_Finalise();
+StgDomain_Finalise();
+StGermain_Finalise();
+MPI_Finalize();'''
+        self.symbol_calls = ['%s(&argc, &argv);', '%s();']
+        self.require_shared = True
+        self.use_rpath = True
+
+    def get_run_error_message(self, console):
+        if len(console):
+            return 'Incompatible libraries, check \'config.log\'.'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/SDL.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/SDL.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,12 @@
+import os
+import SConfig
+
+class SDL(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.header_sub_dir = 'SDL'
+        self.headers = [['SDL.h'],
+                        ['SDL/SDL.h']] # For framework.
+        self.libraries = [['SDL']]
+        self.frameworks = [['SDL', 'Cocoa']]
+        self.have_define = 'HAVE_SDL'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/SVNRevision.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/SVNRevision.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,25 @@
+import os
+import SConfig
+
+class SVNRevision(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.checks = [self.extract_revision]
+        self.define_name = 'VERSION'
+        self.checkout_path = os.getcwd()
+
+    def extract_revision(self):
+        print 'Extracting subversion revision number ... ',
+        svn_path = os.path.join(self.checkout_path, '.svn', 'entries')
+        if not os.path.exists(svn_path):
+            print '\n   Could not find .svn directory.'
+            return [0, '', '']
+        f = file(svn_path, 'r')
+        f.readline()
+        f.readline()
+        f.readline()
+        ver = self.env['ESCAPE']('"' + str(int(f.readline())) + '"')
+        f.close()
+        self.cpp_defines += [(self.define_name, ver)]
+        print 'okay'
+        return [1, '', '']
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/StGermain.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StGermain.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,22 @@
+import os
+import SConfig
+
+class StGermain(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.require(SConfig.packages.cmath)
+        self.require(SConfig.packages.libXML2)
+        self.require(SConfig.packages.MPI)
+        self.base_patterns = ['StGermain*']
+        self.headers = [[os.path.join('StGermain', 'StGermain.h')]]
+        self.libraries = [['StGermain']]
+        self.symbols = [(['StGermain_Init', 'StGermain_Finalise'], '')]
+        self.symbol_setup = 'MPI_Init(&argc, &argv);'
+        self.symbol_teardown = 'MPI_Finalize();'
+        self.symbol_calls = ['%s(&argc, &argv);', '%s();']
+        self.require_shared = True
+        self.use_rpath = True
+
+    def get_run_error_message(self, console):
+        if len(console):
+            return 'Incompatible libraries, check \'config.log\'.'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/StgDomain.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StgDomain.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,24 @@
+import os
+import SConfig
+
+class StgDomain(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.require(SConfig.packages.StGermain)
+        self.base_patterns = ['StgDomain*']
+        self.headers = [[os.path.join('StgDomain', 'StgDomain.h')]]
+        self.libraries = [['StgDomain']]
+        self.symbols = [(['StgDomain_Init', 'StgDomain_Finalise'], '')]
+        self.symbol_setup = '''MPI_Init(&argc, &argv);
+StGermain_Init(&argc, &argv);
+'''
+        self.symbol_teardown = '''StGermain_Finalise();
+MPI_Finalize();
+'''
+        self.symbol_calls = ['%s(&argc, &argv);', '%s();']
+        self.require_shared = True
+        self.use_rpath = True
+
+    def get_run_error_message(self, console):
+        if len(console):
+            return 'Incompatible libraries, check \'config.log\'.'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/StgFEM.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StgFEM.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,25 @@
+import os
+import SConfig
+
+class StgFEM(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.require(SConfig.packages.StGermain)
+        self.require(SConfig.packages.StgDomain)
+        self.base_patterns = ['StgFEM*']
+        self.headers = [[os.path.join('StgFEM', 'StgFEM.h')]]
+        self.libraries = [['StgFEM']]
+        self.symbols = [(['StgFEM_Init', 'StgFEM_Finalise'], '')]
+        self.symbol_setup = '''MPI_Init(&argc, &argv);
+StGermain_Init(&argc, &argv);
+StgDomain_Init(&argc, &argv);'''
+        self.symbol_teardown = '''StgDomain_Finalise();
+StGermain_Finalise();
+MPI_Finalize();'''
+        self.symbol_calls = ['%s(&argc, &argv);', '%s();']
+        self.require_shared = True
+        self.use_rpath = True
+
+    def get_run_error_message(self, console):
+        if len(console):
+            return 'Incompatible libraries, check \'config.log\'.'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/__init__.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,20 @@
+from libXML2 import libXML2
+from MPI import MPI
+from PETSc import PETSc
+from cmath import cmath
+from SVNRevision import SVNRevision
+from BlasLapack import BlasLapack
+from StGermain import StGermain
+from StgDomain import StgDomain
+from StgFEM import StgFEM
+from PICellerator import PICellerator
+from dl import dl
+from OpenGL import OpenGL
+from OSMesa import OSMesa
+from SDL import SDL
+from libPNG import libPNG
+from libJPEG import libJPEG
+from libTIFF import libTIFF
+from libFAME import libFAME
+from libavcodec import libavcodec
+from HDF5 import HDF5
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/cmath.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/cmath.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,7 @@
+import os
+import SConfig
+
+class cmath(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.libraries = [['m']]
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/dl.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/dl.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,8 @@
+import os
+import SConfig
+
+class dl(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['dlfcn.h']]
+        self.libraries = [['dl']]
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libFAME.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libFAME.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class libFAME(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['fame.h']]
+        self.libraries = [['fame']]
+        self.have_define = 'HAVE_FAME'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libJPEG.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libJPEG.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class libJPEG(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['jpeglib']]
+        self.libraries = [['jpeg']]
+        self.have_define = 'HAVE_JPEG'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libPNG.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libPNG.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class libPNG(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['png.h']]
+        self.libraries = [['png']]
+        self.have_define = 'HAVE_PNG'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libTIFF.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libTIFF.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class libTIFF(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.headers = [['tiff.h']]
+        self.libraries = [['tiff']]
+        self.have_define = 'HAVE_TIFF'
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libXML2.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libXML2.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,9 @@
+import os
+import SConfig
+
+class libXML2(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.header_sub_dir = 'libxml2'
+        self.headers = [[os.path.join('libxml', 'parser.h')]]
+        self.libraries = [['xml2']]
diff -r 3368109c9103 -r 6ca3cf494638 config/SConfig/packages/libavcodec.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libavcodec.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,10 @@
+import os
+import SConfig
+
+class libavcodec(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.header_sub_dir = 'ffmpeg'
+        self.headers = [['avcodec.h']]
+        self.libraries = [['avcodec']]
+        self.have_define = 'HAVE_AVCODEC'
diff -r 3368109c9103 -r 6ca3cf494638 config/packages/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/packages/__init__.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,1 @@
+from stgMagma import stgMagma
diff -r 3368109c9103 -r 6ca3cf494638 config/packages/stgMagma.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/packages/stgMagma.py	Fri Mar 07 00:08:53 2008 +0000
@@ -0,0 +1,63 @@
+import os, platform
+import SConfig
+import SCons.Script
+
+class stgMagma(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.checks = [self.setup_environment]
+        self.require(SConfig.packages.cmath)
+        self.require(SConfig.packages.libXML2)
+        self.require(SConfig.packages.MPI)
+        self.require(SConfig.packages.SVNRevision)
+        self.require(SConfig.packages.BlasLapack)
+        self.require(SConfig.packages.PETSc)
+        self.require(SConfig.packages.HDF5)
+        if self.env['with_glucifer']:
+            self.require(SConfig.packages.OpenGL)
+            mesa = self.require(SConfig.packages.OSMesa)
+            mesa.required = False
+
+    def setup_options(self):
+        SConfig.Package.setup_options(self)
+        if self.opts:
+            self.opts.AddOptions(
+                SCons.Script.BoolOption('debug',
+                                        'Enable debugging', 1),
+                SCons.Script.BoolOption('staticLibraries',
+                                        'Build static libraries only', 0),
+                SCons.Script.BoolOption('with_glucifer', 'Enable the gLucifer module', 1),
+                ('buildPath', 'Temporary build path', 'build'))
+
+    def setup_environment(self):
+        # Setup the build path.
+        if not os.path.isabs(self.env['buildPath']):
+            self.env['buildPath'] = '#' + self.env['buildPath']
+
+        # Setup LIB_DIR.
+        lib_dir = os.path.join(self.env['buildPath'], 'lib')
+        abs_lib_dir = self.env.Dir(lib_dir).abspath
+        self.env.AppendUnique(CPPDEFINES=[('LIB_DIR',
+                                           self.env['ESCAPE']('"' + abs_lib_dir + '"'))])
+        self.env.PrependUnique(LIBPATH=[lib_dir])
+
+        # Setup the RPATH.
+        self.env.PrependUnique(RPATH=[self.env.Dir(abs_lib_dir).abspath])
+
+        # Setup the module extension.
+        ext = self.env['ESCAPE']('"' + self.env['SHLIBSUFFIX'][1:] + '"')
+        self.env.Append(CPPDEFINES=[('MODULE_EXT', ext)])
+
+        # Setup the include paths.
+        inc_path = os.path.join(self.env['buildPath'], 'include')
+        self.env.AppendUnique(CPPPATH=[inc_path])
+
+        # Setup debugging.
+        if self.env['debug']:
+            self.env.MergeFlags('-g')
+
+        # Setup 64 bit builds.
+        #if platform.architecture()[0].find('64') != -1:
+        #    self.env.MergeFlags('-m64')
+
+        return [1, '', '']



More information about the CIG-COMMITS mailing list