[cig-commits] commit: Updating stgMagma to be synchronised with

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


changeset:   52:20a5169ced28
user:        LukeHodkinson
date:        Thu Mar 27 23:02:56 2008 +0000
files:       config/SConfig/Package.py config/SConfig/SConscript config/SConfig/__init__.py config/SConfig/packages/BlasLapack.py config/SConfig/packages/CompilerFlags.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/SDL.py config/SConfig/packages/SVNRevision.py config/SConfig/packages/X11.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/stgMagma.py
description:
Updating stgMagma to be synchronised with
stgUnderworld.


diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/Package.py
--- a/config/SConfig/Package.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/Package.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,386 +2,290 @@ import SCons.Script
 import SCons.Script
 import SConfig
 
-class Package(object):
-    def __init__(self, env, options=None, required=False):
-        # 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.platform().find('x86_64') != -1 or \
-               platform.platform().find('ppc64') != -1 or \
-               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)
-
-        # Language options.
-        self.language          = 'C' # 'C' | 'CXX' | 'F77'
-        self.have_define       = ''
+class Package(SConfig.Node):
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Node.__init__(self, scons_env, scons_opts, required)
+
+        # This will be set in the preprocessor.
+        self.have_define         = 'HAVE_' + self.environ_name
 
         # Search options.
-        self.base_dirs         = [] #['']
-        self.base_patterns     = [] #['']
-        self.sub_dirs          = [] #[[[''], ['']]]
-        self.header_sub_dir    = ''
-
-        # Header options.
-        self.headers            = [[]] #[['']]
+        self.base_dirs           = [] #['']
+        self.base_patterns       = [] #['']
+        self.sub_dirs            = [] #[[[''], ['']]]
+        self.header_sub_dir      = ''
+        self.system_header_dirs  = []
+        self.system_library_dirs = []
+
+        # Which headers do we require?
+        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      = [] #['']
+        self.libraries           = [] #[['']]
+        self.shared_libraries    = [] # Only libraries listed here will be considered
+                                      # when checking for shared libraries.
+        self.require_shared      = False
+        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.frameworks          = [] #[['']]
+
+        # Will be set after configuration.
         self.base_dir = ''
         self.hdr_dirs = []
+        self.lib_dirs = []
         self.hdrs = []
-        self.lib_dirs = []
         self.libs = []
         self.have_shared = None
         self.fworks = []
-        self.state = {}
+        self.cpp_defines = []
 
         # Private stuff.
-        self.env = env
-        self.deps = []
-        self.required = required
-
+        self.platform = self.dependency(SConfig.Platform, True) # Need this so we can get
+                                                                # access to information about
+                                                                # the platform we're running on.
+        self.checks = [self.find_package] # The basic package location check.
+
+        # Set everything up.
         self.setup_search_defaults()
 
+    def setup_options(self):
+        SConfig.Node.setup_options(self)
+        self.opts.AddOptions(
+            SCons.Script.BoolOption('with_' + self.command_name,
+                                    'Turn on/off package %s' % self.name, 1),
+            SCons.Script.PathOption(self.command_name + '_dir',
+                                    '%s installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            SCons.Script.PathOption(self.command_name + '_inc_dir',
+                                    '%s header installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            SCons.Script.PathOption(self.command_name + '_lib_dir',
+                                    '%s library installation path' % self.name,
+                                    None, SCons.Script.PathOption.PathIsDir),
+            (self.command_name + '_lib',
+             '%s libraries' % self.name,
+             None, None),
+            (self.command_name + '_framework',
+             '%s framework' % self.name,
+             None, None))
+        self.option_map = {'with_' + self.command_name: None,
+                           self.command_name + '_dir': self.environ_name + '_DIR'}
+
     def setup_search_defaults(self):
-        # Set common defaults of Darwin and Linux.
-        if self.system in ['Darwin', 'Linux']:
+        """Setup the usual search paths for packages depending on the kind of system
+        we're on."""
+        if self.platform.system in ['Darwin', '*ix']:
             self.base_dirs = ['/usr', '/usr/local']
             self.sub_dirs = [[['include'], ['lib']]]
-            if self.bits == 64:
+            if self.platform.bits == 64:
                 self.sub_dirs = [[['include'], ['lib64']],
                                  [['include'], [os.path.join('lib', '64')]]] + self.sub_dirs
 
         # Set Darwin specific defaults.
-        if self.system == 'Darwin':
+        if self.platform.system == 'Darwin':
             self.base_dirs += ['/sw']
 
         # Set Window specific defaults.
-        if self.system == 'Windows':
+        if self.platform.system == 'Windows':
             pass # TODO
 
-    def setup_options(self):
-        if not self.opts:
+        # Combine these guys to build default system paths. We need these to ensure specific
+        # include paths are used before generic ones.
+        for base_dir in ['/usr', '/sw']:
+            for hdr_dirs, lib_dirs in self.combine_sub_dirs(base_dir):
+                hdr_dirs = [os.path.join(base_dir, h) for h in hdr_dirs]
+                self.system_header_dirs += [h for h in hdr_dirs if h not in self.system_header_dirs]
+                lib_dirs = [os.path.join(base_dir, l) for l in lib_dirs]
+                self.system_library_dirs += [l for l in lib_dirs if l not in self.system_library_dirs]
+
+    def get_check_headers_fail_reason(self, fail_logs):
+        return ''
+
+    def get_check_symbols_fail_reason(self, fail_logs):
+        return ''
+
+    def configure(self, scons_ctx):
+        if not self.required and not self.env['with_' + self.command_name]:
             return
-        self.command_options = ['with_' + self.option_name,
-                                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.BoolOption('with_' + self.option_name, 'Turn on/off %s' % self.name, 1),
-            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, or it is deselected, just return.
-        if self.configured or not (self.required or self.env['with_' + self.option_name]):
-            return
-
-        # Setup our configure context and environment.
-        self.ctx = configure_context
-        self.configured = True
-
-        # Process dependencies first.
-        result = self.process_dependencies()
-        if not result[0]:
-            self.ctx.Display('  ' + result[2])
-            self.result = result
-            return result
-
-        # Process options.
-        self.process_options()
-
-        # Perfrom actual configuration.
-        self.ctx.Message('Checking for package %s ... ' % self.name)
-        self.ctx.Display('\n')
-        for check in self.checks:
-            result = check()
-            self.result = result
-            if not self.result[0]:
+        SConfig.Node.configure(self, scons_ctx)
+
+    def setup(self):
+        SConfig.Node.setup(self)
+        if self.require_shared:
+            self.dependency(SConfig.packages.dl)
+
+    def find_package(self):
+        """Basic check routine for locating the package."""
+        result = True
+        self.ctx.Display('  Searching locations:\n')
+        for loc in self.generate_locations():
+            self.ctx.Display('    %s\n' % str(loc))
+            result = self.check_location(loc)
+            if result:
+                if self.have_define:
+                    self.cpp_defines += [self.have_define]
+                self.base_dir = loc[0]
+                self.hdr_dirs = loc[1]
+                self.lib_dirs = loc[2]
+                self.fworks = loc[3]
                 break
-
-        # Required?
-        if self.required and not self.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 self.result[0]:
-            if self.have_define:
-                self.cpp_defines += [self.have_define]
-            self.build_state()
-            self.push_state(self.state)
-
-        # Display results.
-        if not self.result[0] and self.result[2]:
-            self.ctx.Display('   ' + self.result[2])
-        self.ctx.Display('   ')
-        self.ctx.Result(self.result[0])
-
-        return self.result
-
-    def dependency(self, package_module, required=True):
-        if self.configured:
-            print 'Error: Cannot add a dependency during configuration.'
-            self.env.Exit()
-        pkg = self.env.Package(package_module, self.opts)
-        if pkg not in [d[0] for d in self.deps]:
-            self.deps += [(pkg, required)]
-        return pkg
-
-    def process_dependencies(self):
-        """Ensure all dependencies have been configured before this package."""
-        for pkg, req in self.deps:
-            pkg.configure(self.ctx)
-            if req and not pkg.result[0]:
-                return [0, '', 'Missing dependency: ' + pkg.name]
-        return [1, '', '']
-
-    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.Display('   Searching locations:\n')
-        for loc in self.generate_locations():
-            result = self.check_location(loc)
-            self.ctx.Display('      %s\n' % str(loc))
-            if result[0]: # If we succeeded, back out here.
-                break
-            if result[2]: # Display an error message.
-                self.ctx.Display('         %s\n' % result[2])
-
-        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)
+        old_state = self.enable_location_state(location)
 
         # Check for the headers.
-        result = self.check_headers(location)
-        if not result[0]:
-            self.pop_state(old)
-            return result
+        if not self.check_headers(location):
+            self.pop_state(old_state)
+            return False
 
         # Scan each set of libraries in turn.
-        libs = []
-        for libs in self.generate_libraries(location):
-            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
+        if not self.check_libraries(location):
+            self.pop_state(old_state)
+            return False
+
+        self.pop_state(old_state)
+        return True
 
     def check_headers(self, location):
         """Determine if the required headers are available with the current construction
         environment settings."""
+        fail_logs = []
         for hdrs in self.headers:
             src = self.get_header_source(hdrs)
-            result = self.run_scons_cmd(self.ctx.TryCompile, src, '.c')
+            result = self.compile_source(src)
             if result[0]:
                 self.hdrs = list(hdrs)
                 break
+            fail_logs += [result[1]]
         if not result[0]:
-            msg = self.get_headers_error_message(result[1])
+            msg = self.get_check_headers_fail_reason(fail_logs)
             if not msg:
-                msg = 'Failed to locate headers.'
-        else:
-            msg = ''
-        return [result[0], '', msg]
-
-    def check_libs(self, location, libs):
+                msg = 'Headers not found.'
+            self.ctx.Display('      ' + msg + '\n')
+        return result[0]
+
+    def check_libraries(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 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):
+        fail_reasons = []
+        no_shared = False
+        for libs in self.generate_libraries(location):
+            old_state = self.enable_library_state(location, libs)
+
+            # Check that we can link against the libraries by trying to link against
+            # a particular set of symbols.
+            result = self.check_symbols(location, libs)
+            if not result[0]:
+                fail_reasons += [result[1]]
+                self.pop_state(old_state)
+                continue
+
+            # Check if we have shared libraries.
+            if not self.require_shared or not libs:
+                self.libs = list(libs)
+                self.pop_state(old_state)
+                return True
+            elif self.check_shared(location, libs):
+                self.libs = list(libs)
+                self.pop_state(old_state)
+                return True
+            else:
+                no_shared = True
+
+        # Figure out what to report.
+        if no_shared:
+            reason = 'No shared libraries.'
+        else:
+            reason = ''
+            for reason in fail_reasons:
+                if reason:
+                    break
+            if not reason:
+                reason = 'Libraries not found.'
+        self.ctx.Display('      ' + reason + '\n')
+
+        self.pop_state(old_state)
+        return False
+
+    def check_symbols(self, location, libraries):
         """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."""
+        fail_logs = []
         for syms in self.symbols:
-            result = self.run_source(self.get_check_symbols_source(syms[0]))
+            result = self.link_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.
+            fail_logs += [result[1]]
+        if not result[0]:
+            reason = self.get_check_symbols_fail_reason(fail_logs)
+        else:
+            reason = ''
+        return [result[0], reason]
+
+    def check_shared(self, location, libraries):
+        """Confirm that there are shared versions of this package's libraries available.
+        At this point we know we can link against the libraries."""
+        # Build a binary to try and dynamically open the libraries in order.
         result = [1, '', '']
-        for l in libs:
-            src = self.get_header_source()
-            src += """
+        src = self.get_header_source()
+        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, '', '']
+  void* lib[%d];
+""" % len(libraries)
+        for l in libraries:
+            if self.shared_libraries and l not in self.shared_libraries:
+                continue
+            offs = ''
+            for p in self.generate_library_paths(location, l):
+                offs += '  '
+                if len(offs) > 2:
+                    src += '{\n'
+                src += '%slib[%d] = dlopen("%s", RTLD_NOW);\n' % (offs, libraries.index(l), p)
+                src += '%sif( !lib[%d] ) ' % (offs, libraries.index(l))
+            src += 'return 1;\n'
+            while len(offs) > 2:
+                offs = offs[:-2]
+                src += offs + '}\n'
+        src += '  return 0;\n}\n'
+        if not self.run_source(src)[0]:
+            return False
+        return True
+
+    def generate_library_paths(self, location, library):
+        lib_name = self.env.subst('${SHLIBPREFIX}' + library + '${SHLIBSUFFIX}')
+        if location[2]:
+            for d in location[2]:
+                path = os.path.join(location[0], d, lib_name)
+                yield os.path.abspath(path)
+        else:
+            yield lib_name
 
     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', '')
+        base_dir = self.env.get(self.command_name + '_dir', '')
+        inc_dir = self.env.get(self.command_name + '_inc_dir', '')
+        lib_dir = self.env.get(self.command_name + '_lib_dir', '')
+        fwork = self.env.get(self.command_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'
+                print '      ' + self.command_name + '_inc_dir'
+                print '      ' + self.command_name + '_lib_dir'
                 env.Exit()
             yield ['', [inc_dir], [lib_dir], [fwork]]
             return
@@ -419,10 +323,6 @@ int main(int argc, char* argv[]) {
                         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 generate_libraries(self, location):
-        for libs in self.libraries:
-            yield libs
 
     def combine_sub_dirs(self, base_dir):
         """Take a base directory and combine it with the set of header and library
@@ -469,93 +369,100 @@ int main(int argc, char* argv[]) {
             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 = {}
+    def generate_libraries(self, location):
+        if location[3]: # Try any frameworks by themselves first.
+            yield []
+        for libs in self.libraries:
+            yield libs
+
+    def enable_location_state(self, location):
+        """Modify our environment to include search paths for the current location."""
+        old_state = {}
         if location[1]:
-            state['CPPPATH'] = [self.join_sub_dir(location[0], l) for l in location[1]]
+            old_state['CPPPATH'] = self.env.get('CPPPATH', [])
+            self.env.PrependUnique(CPPPATH=[self.join_sub_dir(location[0], l) for l in location[1]])
+        if location[2]:
+            old_state['LIBPATH'] = self.env.get('LIBPATH', [])
+            old_state['RPATH'] = self.env.get('RPATH', [])
+            lib_paths = [self.join_sub_dir(location[0], l) for l in location[2]]
+            self.env.PrependUnique(LIBPATH=lib_paths)
+            self.env.PrependUnique(RPATH=[os.path.abspath(p) for p in lib_paths])
         if location[3]:
-            state['FRAMEWORKS'] = location[3]
-        return state
-
-    def build_lib_state(self, location, libs):
+            old_state['FRAMEWORKS'] = self.env.get('FRAMEWORKS', [])
+            self.env.PrependUnique(FRAMEWORKS=location[3])
+            if 'CPPPATH' not in old_state:
+                old_state['CPPPATH'] = self.env.get('CPPPATH', [])
+            for fw in location[3]: # Sort of a hack for Mac OS X.
+                path = '/System/Library/Frameworks/' + fw + '.framework/Headers'
+                self.env.PrependUnique(CPPPATH=[path])
+        return old_state
+
+    def enable_library_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]
+        old_state = {}
         if libs:
-            state['LIBS'] = libs
-        return state
-
-    def build_state(self):
-        self.state = {}
+            old_state['LIBS'] = self.env.get('LIBS', [])
+            self.env.PrependUnique(LIBS=libs)
+        return old_state
+
+    def enable(self, scons_env, old_state=None):
+        SConfig.Node.enable(self, scons_env, old_state)
         if self.cpp_defines:
-            self.state['CPPDEFINES'] = self.cpp_defines
+            self.backup_variable(scons_env, 'CPPDEFINES', old_state)
+            scons_env.AppendUnique(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]
+            self.backup_variable(scons_env, 'CPPPATH', old_state)
+            for d in self.hdr_dirs:
+                abs_dir = self.join_sub_dir(self.base_dir, d)
+                if abs_dir in self.system_header_dirs:
+                    scons_env.AppendUnique(CPPPATH=[abs_dir])
+                else:
+                    scons_env.PrependUnique(CPPPATH=[abs_dir])
+
         if self.fworks:
-            self.state['FRAMEWORKS'] = self.fworks
+            self.backup_variable(scons_env, 'FRAMEWORKS', old_state)
+            self.backup_variable(scons_env, 'CPPPATH', old_state)
+            scons_env.PrependUnique(FRAMEWORKS=self.fworks)
+            for fw in self.fworks: # Sort of a hack for Mac OS X.
+                path = '/System/Library/Frameworks/' + fw + '.framework/Headers'
+                self.env.PrependUnique(CPPPATH=[path])
+
         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']]
+            self.backup_variable(scons_env, 'LIBPATH', old_state)
+            self.backup_variable(scons_env, 'RPATH', old_state)
+            for d in self.lib_dirs:
+                abs_dir = self.join_sub_dir(self.base_dir, d)
+                if abs_dir in self.system_library_dirs:
+                    scons_env.AppendUnique(LIBPATH=[abs_dir])
+                    scons_env.AppendUnique(RPATH=[os.path.abspath(abs_dir)])
+                else:
+                    scons_env.PrependUnique(LIBPATH=[abs_dir])
+                    scons_env.PrependUnique(RPATH=[os.path.abspath(abs_dir)])
+
         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 v:
-                continue
-            if not isinstance(v, list):
-                copy[k] = [v]
-            else:
-                copy[k] = v
-            old[k] = self.env.get(k, [])
-        if append:
-            self.env.AppendUnique(**copy)
-        else:
-            self.env.PrependUnique(**copy)
-        return old
-
-    def pop_state(self, old):
-        self.env.Replace(**old)
+            self.backup_variable(scons_env, 'LIBS', old_state)
+            scons_env.PrependUnique(LIBS=self.libs)
 
     def get_all_headers(self, headers):
-        if not self.result[0]:
+        if not self.result:
             return
+        for d, r in self.deps:
+            if hasattr(d, 'get_all_headers'):
+                d.get_all_headers(headers)
         headers += [h for h in self.hdrs if h not in headers]
-        for d, r 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'
+        hdrs = []
+        for d, r in self.deps:
+            if hasattr(d, 'get_all_headers'):
+                d.get_all_headers(hdrs)
         if headers is None:
-            hdrs = list(self.hdrs)
-        else:
-            hdrs = list(headers)
-        for d, r in self.deps:
-            d.get_all_headers(hdrs)
+            hdrs += list(self.hdrs)
+        else:
+            hdrs += list(headers)
         for h in hdrs:
             src += '#include<' + h + '>\n'
         return src
@@ -573,39 +480,3 @@ int main(int argc, char* argv[]) {
             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 8a40e35540f4 -r 20a5169ced28 config/SConfig/SConscript
--- a/config/SConfig/SConscript	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/SConscript	Thu Mar 27 23:02:56 2008 +0000
@@ -6,23 +6,60 @@ from SCons.Script.SConscript import SCon
 # Setup the Package system.
 #
 
-def Package(env, pkg_module, options=None):
-    # Setup the SCons environment to hold packages if not already
-    # done.
+def Package(env, pkg_module, options, required=False):
+    """Create a new package to be configured."""
     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.packages[pkg_module] = pkg_module(env, options, required)
         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 configure_packages(env, options=None, output='config.cfg'):
+    # Get rid of the temporary directory to make sure we're building
+    # from scratch.
+    if os.path.exists('.sconsign.dblite'):
+        os.remove('.sconsign.dblite')
+
+    # Finish setting everything up.
+    for pkg in env.package_list:
+        pkg.setup()
+
+    # Update dependencies and requirements.
+    pkgs_rem = list(env.package_list)
+    while len(pkgs_rem):
+        pkg = pkgs_rem.pop()
+        if pkg.required:
+            for d, r in pkg.deps:
+                if r and not d.required:
+                    d.required = True
+                    pkgs_rem += [d]
+
+    # Call the packages checker.
+    sconf = Configure(pkg.env, custom_tests={'CheckPackages': CheckPackages})
+    sconf.CheckPackages(env.package_list)
+    sconf.Finish()
+
+    # Dump results to our output file.
+    for pkg in env.package_list: # Put the results on this environment.
+        if pkg.result:
+            pkg.enable(env)
+    vars = ['CFLAGS', 'CCFLAGS',
+            'CPPPATH', 'CPPDEFINES',
+            'LIBPATH', 'LIBS', 'RPATH',
+            'FRAMEWORKS']
+    vars += options.keys()
+    env.save_config(output, vars)
+
+    # Print out build message.
+    print '\n*****************************************'
+    print "* Now run 'scons' to build the project. *"
+    print '*****************************************\n'
 
 def save_config(env, filename, vars):
     d = {}
@@ -49,51 +86,6 @@ def load_config(env, filename):
     for k, v in d.iteritems():
         env[k] = v
 
-def force_required(pkg):
-    for d in pkg.deps:
-        d.required = True
-        force_required(d)
-
-def configure_packages(env, options=None, output='config.cfg'):
-    sconf = Configure(env, custom_tests={'CheckPackages': CheckPackages})
-
-    # Get rid of the temporary directory to make sure we're building
-    # from scratch.
-    if os.path.exists('.sconsign.dblite'):
-        os.remove('.sconsign.dblite')
-
-    # Add dependencies needed for shared libraries.
-    for pkg in env.package_list:
-        if pkg.require_shared:
-            pkg.pkg_dl = pkg.dependency(SConfig.packages.dl)
-
-    # Update dependencies and requirements.
-    pkgs_rem = list(env.package_list)
-    while len(pkgs_rem):
-        pkg = pkgs_rem.pop()
-        if pkg.required:
-            for d, r in pkg.deps:
-                if r and not d.required:
-                    d.required = True
-                    pkgs_rem += [d]
-
-    # 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)
-
-    # Print out build message.
-    print '\n*****************************************'
-    print "* Now run 'scons' to build the project. *"
-    print '*****************************************\n'
-
 SConsEnvironment.Package = Package
 SConsEnvironment.configure_packages = configure_packages
 SConsEnvironment.save_config = save_config
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/__init__.py
--- a/config/SConfig/__init__.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/__init__.py	Thu Mar 27 23:02:56 2008 +0000
@@ -1,2 +1,4 @@ from Package import Package
+from Node import Node
+from Platform import Platform
 from Package import Package
 import packages
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/BlasLapack.py
--- a/config/SConfig/packages/BlasLapack.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/BlasLapack.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,14 +2,13 @@ import SConfig
 import SConfig
 
 class BlasLapack(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.cmath = self.dependency(SConfig.packages.cmath)
         self.libraries = [['blas', 'lapack'],
                           ['cblas', 'clapack'],
                           ['mkl', 'mkl_lapack']]
         self.frameworks = [['Accelerate']]
-        self.use_rpath = True
         self.symbols = [(['dgeev'], 'FORTRAN_NORMAL'),
                         (['dgeev_'], 'FORTRAN_SINGLE_TRAILINGBAR'),
                         (['dgeev__'], 'FORTRAN_DOUBLE_TRAILINGBAR'),
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/CompilerFlags.py
--- a/config/SConfig/packages/CompilerFlags.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/CompilerFlags.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,20 +2,18 @@ import SCons.Script
 import SCons.Script
 import SConfig
 
-class CompilerFlags(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+class CompilerFlags(SConfig.Node):
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Node.__init__(self, scons_env, scons_opts, required)
         self.checks = [self.check_bit_flags,
                        self.check_architecture]
 
     def setup_options(self):
-        SConfig.Package.setup_options(self)
-        if not self.opts:
-            return
-        self.command_options += ['with_32bit']
+        SConfig.Node.setup_options(self)
         self.opts.AddOptions(
             SCons.Script.BoolOption('with_32bit', 'Generate 32bit code', 0),
-            SCons.Script.BoolOption('with_64bit', 'Generate 64bit code', 0))
+            SCons.Script.BoolOption('with_64bit', 'Generate 64bit code', 0)
+            )
 
     def check_architecture(self):
         if (platform.platform().find('x86_64') != -1 or \
@@ -34,7 +32,7 @@ class CompilerFlags(SConfig.Package):
                 self.env.MergeFlags(self.flag_32bit)
                 if self.env.subst('$CC') == self.env.subst('$LINK'):
                     self.env.AppendUnique(LINKFLAGS=[self.flag_32bit])
-        return [1, '', '']
+        return True
 
     def check_bit_flags(self):
         if self.try_flag('-m32')[0]:
@@ -49,7 +47,7 @@ class CompilerFlags(SConfig.Package):
             self.flag_64bit = '-q64'
         else:
             self.flag_64bit = ''
-        return [1, '', '']
+        return True
 
     def try_flag(self, flag):
         state = self.env.ParseFlags(flag)
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/HDF5.py
--- a/config/SConfig/packages/HDF5.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/HDF5.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,7 @@ import SConfig
 import SConfig
 
 class HDF5(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.headers = [['hdf5.h']]
         self.libraries = [['hdf5']]
-        self.have_define = 'HAVE_HDF5'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/MPI.py
--- a/config/SConfig/packages/MPI.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/MPI.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class MPI(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.CompilerFlags)
         self.base_patterns = ['mpich*', 'MPICH*']
         self.header_sub_dir = 'mpi'
@@ -12,14 +12,18 @@ class MPI(SConfig.Package):
                           ['mpich', 'pmpich'],
                           ['mpich', 'rt'],
                           ['mpich', 'pmpich', 'rt'],
-                          ['mpi']]
+                          ['mpi'],
+                          ['lam', 'mpi']]
+        self.shared_libraries = ['mpich', 'pmpich', 'mpi', 'lam']
         self.require_shared = True
-        self.use_rpath = True
+        self.symbols = [(['MPI_Init', 'MPI_Finalize'], '')]
+        self.symbol_calls = ['%s(&argc, &argv);', '%s();']
 
-    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] + location[2]
-        return [1, '', '']
+    def generate_locations(self):
+        for loc in SConfig.Package.generate_locations(self):
+            for lib_dir in loc[2]:
+                shared_dir = os.path.join(lib_dir, 'shared')
+                path = os.path.join(loc[0], shared_dir)
+                if os.path.exists(path):
+                    loc[2] = [shared_dir] + loc[2]
+            yield loc
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/OSMesa.py
--- a/config/SConfig/packages/OSMesa.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/OSMesa.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,7 +2,7 @@ import SConfig
 import SConfig
 
 class OSMesa(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.libraries = [['GL', 'GLU']]
         self.have_define = 'HAVE_MESA'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/OpenGL.py
--- a/config/SConfig/packages/OpenGL.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/OpenGL.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,11 +2,10 @@ import SConfig
 import SConfig
 
 class OpenGL(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.header_sub_dir = 'GL'
-        self.headers = [['gl.h', 'glu.h'],
-                        ['OpenGL/gl.h', 'OpenGL/glu.h']] # For framework.
+        self.headers = [['gl.h', 'glu.h']]
         self.libraries = [['GL', 'GLU']]
         self.frameworks = [['OpenGL']]
         self.have_define = 'HAVE_GL'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/PETSc.py
--- a/config/SConfig/packages/PETSc.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/PETSc.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class PETSc(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.MPI)
         self.base_patterns = ['petsc*', 'PETSC*', 'PETSc*']
         self.header_sub_dir = 'petsc'
@@ -14,45 +14,41 @@ class PETSc(SConfig.Package):
                            'petscmat', 'petscvec',
                            'petscdm', 'petsc',]]
         self.require_shared = True
-        self.use_rpath = True
-        self.have_define = 'HAVE_PETSC'
+        self.symbols = [(['PetscInitialize', 'PetscFinalize'], '')]
+        self.symbol_calls = ['%s(&argc, &argv, NULL, NULL);', '%s();']
 
-        # Other stuff.
+        # Will be set after configuration.
         self.arch = ''
 
-    def validate_location(self, location):
-        # Must have a base directory.
-        if not location[0]:
-            return (1, '', '')
+    def generate_locations(self):
+        for loc in SConfig.Package.generate_locations(self):
+            if not loc[0]:
+                yield loc
+                continue
 
-        # Get the architecture.
-        arch = self.get_petsc_arch(location[0])
-        if not arch:
-            return (0, '', 'Could not read architecture from petscconf.')
-        self.arch = arch
+            arch = self.get_petsc_arch(loc[0])
+            if not arch:
+                yield loc
+                continue
+            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 bmake/arch include directory.
+            hdr_dir = os.path.join('bmake', arch)
+            if not os.path.exists(os.path.join(loc[0], hdr_dir)):
+                continue
+            if hdr_dir not in loc[1]:
+                loc[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]
+            # Add the lib/arch library directory.
+            if 'lib' in loc[2]:
+                loc[2].remove('lib')
+            lib_dir = os.path.join('lib', arch)
+            if not os.path.exists(os.path.join(loc[0], lib_dir)):
+                continue
+            if lib_dir not in loc[2]:
+                loc[2] += [lib_dir]
 
-        return [1, '', '']
-
-    def get_headers_error_message(self, console):
-        if console.find('MPI_') != -1:
-            return 'Incompatible implementation of MPI.'
-        return ''
+            yield loc
 
     def get_petsc_arch(self, base_dir):
         petscconf = os.path.join(base_dir, 'bmake',
@@ -63,3 +59,9 @@ class PETSc(SConfig.Package):
         arch = f.readline().split('=')[1][:-1]
         f.close()
         return arch
+
+    def get_check_headers_fail_reason(self, fail_logs):
+        for log in fail_logs:
+            if log.find('MPI_') != -1:
+                return 'Selected MPI implementation incompatible.'
+        return ''
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/SDL.py
--- a/config/SConfig/packages/SDL.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/SDL.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,11 +2,10 @@ import SConfig
 import SConfig
 
 class SDL(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         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 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/SVNRevision.py
--- a/config/SConfig/packages/SVNRevision.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/SVNRevision.py	Thu Mar 27 23:02:56 2008 +0000
@@ -1,25 +1,29 @@ import os
 import os
 import SConfig
 
-class SVNRevision(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+class SVNRevision(SConfig.Node):
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Node.__init__(self, scons_env, scons_opts, required)
         self.checks = [self.extract_revision]
         self.define_name = 'VERSION'
         self.checkout_path = os.getcwd()
 
-    def setup_options(self):
-        pass
+        # Will be set after configuration.
+        self.revision = 0
 
     def extract_revision(self):
         svn_path = os.path.join(self.checkout_path, '.svn', 'entries')
         if not os.path.exists(svn_path):
             return [0, '', 'Could not find .svn directory']
         f = file(svn_path, 'r')
-        f.readline()
-        f.readline()
-        f.readline()
-        ver = self.env['ESCAPE']('"' + str(int(f.readline())) + '"')
+	all_lines = f.readlines()
         f.close()
-        self.cpp_defines += [(self.define_name, ver)]
-        return [1, '', '']
+
+	for l in all_lines:
+            ind = l.rfind('revision=')
+            if ind != -1:
+                self.revision = int(l[ind + 10:l.rfind('"')])
+                return True
+
+        self.revision = int(all_lines[3])
+        return True
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/X11.py
--- a/config/SConfig/packages/X11.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/X11.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,12 +2,11 @@ import SConfig
 import SConfig
 
 class X11(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.header_sub_dir = 'X11'
         self.headers = [['Xlib.h']]
         self.libraries = [['X11', 'Xmu']]
-        self.have_define = 'HAVE_X11'
         self.symbols = [(['XOpenDisplay'], '')]
         self.symbol_setup = 'void* display;'
         self.symbol_calls = ['display = %s(NULL);']
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/cmath.py
--- a/config/SConfig/packages/cmath.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/cmath.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,7 +2,7 @@ import SConfig
 import SConfig
 
 class cmath(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.CompilerFlags)
         self.libraries = [['m']]
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/dl.py
--- a/config/SConfig/packages/dl.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/dl.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class dl(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.CompilerFlags)
         self.headers = [['dlfcn.h']]
         self.libraries = [['dl']]
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libFAME.py
--- a/config/SConfig/packages/libFAME.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libFAME.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libFAME(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.headers = [['fame.h']]
         self.libraries = [['fame']]
         self.have_define = 'HAVE_FAME'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libJPEG.py
--- a/config/SConfig/packages/libJPEG.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libJPEG.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libJPEG(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.headers = [['jpeglib.h']]
         self.libraries = [['jpeg']]
         self.have_define = 'HAVE_JPEG'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libPNG.py
--- a/config/SConfig/packages/libPNG.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libPNG.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libPNG(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.headers = [['png.h']]
         self.libraries = [['png']]
         self.have_define = 'HAVE_PNG'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libTIFF.py
--- a/config/SConfig/packages/libTIFF.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libTIFF.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libTIFF(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.headers = [['tiff.h']]
         self.libraries = [['tiff']]
         self.have_define = 'HAVE_TIFF'
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libXML2.py
--- a/config/SConfig/packages/libXML2.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libXML2.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libXML2(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.CompilerFlags)
         self.header_sub_dir = 'libxml2'
         self.headers = [[os.path.join('libxml', 'parser.h')]]
diff -r 8a40e35540f4 -r 20a5169ced28 config/SConfig/packages/libavcodec.py
--- a/config/SConfig/packages/libavcodec.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/SConfig/packages/libavcodec.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,8 +2,8 @@ import SConfig
 import SConfig
 
 class libavcodec(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options)
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Package.__init__(self, scons_env, scons_opts, required)
         self.header_sub_dir = 'ffmpeg'
         self.headers = [['avcodec.h']]
         self.libraries = [['avcodec']]
diff -r 8a40e35540f4 -r 20a5169ced28 config/packages/stgMagma.py
--- a/config/packages/stgMagma.py	Fri Mar 14 01:17:43 2008 +0000
+++ b/config/packages/stgMagma.py	Thu Mar 27 23:02:56 2008 +0000
@@ -2,18 +2,17 @@ import SConfig
 import SConfig
 import SCons.Script
 
-class stgMagma(SConfig.Package):
-    def __init__(self, env, options):
-        SConfig.Package.__init__(self, env, options, True)
-        self.checks = [self.setup_environment]
+class stgMagma(SConfig.Node):
+    def __init__(self, scons_env, scons_opts, required=False):
+        SConfig.Node.__init__(self, scons_env, scons_opts, required)
         self.dependency(SConfig.packages.cmath)
         self.dependency(SConfig.packages.libXML2)
         self.dependency(SConfig.packages.MPI)
-        self.dependency(SConfig.packages.SVNRevision)
+        self.svnrevision = self.dependency(SConfig.packages.SVNRevision)
         self.dependency(SConfig.packages.BlasLapack)
         self.dependency(SConfig.packages.PETSc)
         self.dependency(SConfig.packages.PETScExt)
-        self.dependency(SConfig.packages.HDF5)
+        self.dependency(SConfig.packages.HDF5, False)
         if self.env['with_glucifer']:
             self.dependency(SConfig.packages.OpenGL)
             self.dependency(SConfig.packages.OSMesa, False)
@@ -26,41 +25,51 @@ class stgMagma(SConfig.Package):
             self.dependency(SConfig.packages.libTIFF, 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'))
+        SConfig.Node.setup_options(self)
+        self.opts.AddOptions(
+            SCons.Script.BoolOption('debug',
+                                    'Enable debugging', 1),
+            SCons.Script.BoolOption('static_libraries',
+                                    'Build static libraries', 0),
+            SCons.Script.BoolOption('shared_libraries',
+                                    'Build shared libraries', 1),
+            SCons.Script.BoolOption('with_glucifer', 'Enable the gLucifer module', 1),
+            ('buildPath', 'Temporary build path', 'build')
+            )
+        self.option_map = {'debug': None,
+                           'static_libraries': None,
+                           'shared_libraries': None,
+                           'with_glucifer': None}
 
-    def setup_environment(self):
+    def enable(self, scons_env):
+        SConfig.Node.enable(self, scons_env)
+
         # Setup the build path.
-        if not os.path.isabs(self.env['buildPath']):
-            self.env['buildPath'] = '#' + self.env['buildPath']
+        if not os.path.isabs(scons_env['buildPath']):
+            scons_env['buildPath'] = '#' + scons_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])
+        lib_dir = os.path.join(scons_env['buildPath'], 'lib')
+        abs_lib_dir = scons_env.Dir(lib_dir).abspath
+        scons_env.AppendUnique(CPPDEFINES=[('LIB_DIR',
+                                           scons_env['ESCAPE']('"' + abs_lib_dir + '"'))])
+        scons_env.PrependUnique(LIBPATH=[lib_dir])
 
         # Setup the RPATH.
-        self.env.PrependUnique(RPATH=[self.env.Dir(abs_lib_dir).abspath])
+        scons_env.PrependUnique(RPATH=[scons_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)])
+        ext = scons_env['ESCAPE']('"' + scons_env['SHLIBSUFFIX'][1:] + '"')
+        scons_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])
+        inc_path = os.path.join(scons_env['buildPath'], 'include')
+        scons_env.AppendUnique(CPPPATH=[inc_path])
 
         # Setup debugging.
-        if self.env['debug']:
-            self.env.MergeFlags('-g')
+        if scons_env['debug']:
+            scons_env.MergeFlags('-g')
 
-        return [1, '', '']
+        # Setup the revision number.
+        ver = scons_env['ESCAPE']('"' + str(self.svnrevision.revision) + '"')
+        scons_env.Append(CPPDEFINES=[('VERSION', ver)])



More information about the CIG-COMMITS mailing list