[cig-commits] commit:

Mercurial hg at geodynamics.org
Mon Nov 24 11:58:25 PST 2008


changeset:   40:1926c51319ff
user:        LukeHodkinson
date:        Mon Mar 03 05:14:13 2008 +0000
files:       config/SConfig/Package.py config/SConfig/SConscript config/SConfig/__init__.py config/SConfig/packages/BlasLapack.py config/SConfig/packages/MPI.py config/SConfig/packages/PETSc.py config/SConfig/packages/PICellerator.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/libXML2.py config/packages/StgDomain.py config/packages/__init__.py
description:
Adding the structure for the new configuration
scheme.


diff -r f76b33690068 -r 1926c51319ff config/SConfig/Package.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/Package.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,497 @@
+import os, platform, glob
+import SCons.Script
+
+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()
+
+        # Setup some system specific information.
+        self.system = platform.system()
+
+        # Is this package essential?
+        self.required          = required
+
+        # Dependency list.
+        self.dependencies      = [] #[<module>]
+
+        # Language options.
+        self.language          = 'C' # 'C' | 'CXX' | 'F77'
+        self.have_define       = ''
+
+        # Search options.
+        self.base_dirs         = [] #['']
+        self.base_patterns     = [] #['']
+        self.sub_dirs          = [] #[[[''], ['']]]
+
+        # Header options.
+        self.headers            = [] #['']
+        self.dependency_headers = [] # ['']
+
+        # Library options.
+        self.libraries         = [] #[['']]
+        self.require_shared    = False
+        self.use_rpath         = 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.base_dir = ''
+        self.hdr_dirs = []
+        self.lib_dirs = []
+        self.libs = []
+        self.have_shared = None
+        self.fworks = []
+        self.state = {}
+
+        # Private stuff.
+        self.sconf = None
+        self.env = env
+        self.opts = options
+
+    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
+
+    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']]]
+
+        # 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.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 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 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."""
+        # TODO
+        return [1, '', '']
+
+    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_headers(self, location):
+        """Determine if the required headers are available with the current construction
+        environment settings."""
+        src = self.get_header_source()
+        result = self.run_scons_cmd(self.ctx.TryCompile, src, '.c')
+        msg = self.get_headers_error_message(result[1])
+        if not msg:
+            msg = 'Failed to locate headers.'
+        return [result[0], '', msg]
+
+    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 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
+
+        # Process dependencies first.
+        self.process_dependencies()
+
+        # Perfrom actual configuration.
+        for check in self.checks:
+            result = check()
+            if not result[0]:
+                break
+
+        # Required?
+        if self.required and not result[0]:
+            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 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 setup_dependencies(self):
+        # If the package doesn't yet exist, create it.
+        for pkg_module in self.dependencies:
+            if pkg_module not in self.env.packages:
+                self.env.Package(pkg_module, self.opts)
+
+    def process_dependencies(self):
+        """Ensure all dependencies have been configured before this package."""
+        for pkg_module in self.dependencies:
+            # Configure the dependency now.
+            pkg = self.env.packages[pkg_module]
+            pkg.sconf = self.sconf
+            pkg.configure(self.ctx)
+
+    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:
+                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)]
+
+    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 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_header_source(self):
+        src = '#include<stdlib.h>\n#include<stdio.h>\n#include<string.h>\n'
+        for h in self.dependency_headers + self.headers:
+            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 dump(self, env, file):
+        pass
diff -r f76b33690068 -r 1926c51319ff config/SConfig/SConscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/SConscript	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,81 @@
+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 we already have this package we can return now.
+    if pkg_module in env.packages:
+        return
+
+    # Add an instance of this package.
+    env.packages[pkg_module] = pkg_module(env, options)
+    env.package_list += [env.packages[pkg_module]]
+
+def CheckPackages(ctx, pkg_list):
+    for pkg in pkg_list:
+        pkg.configure(ctx)
+
+def setup_packages(env, options=None):
+    for pkg in env.package_list:
+        pkg.setup_dependencies()
+    if options:
+        options.Update(env)
+        options.Save('config.cache', env)
+
+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})
+
+    # Set the configure object to all packages.
+    for pkg in env.package_list:
+        pkg.sconf = sconf
+
+    # 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.setup_packages = setup_packages
+SConsEnvironment.configure_packages = configure_packages
+SConsEnvironment.save_config = save_config
+SConsEnvironment.load_config = load_config
diff -r f76b33690068 -r 1926c51319ff config/SConfig/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/__init__.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,2 @@
+from Package import Package
+import packages
diff -r f76b33690068 -r 1926c51319ff config/SConfig/packages/BlasLapack.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/BlasLapack.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,49 @@
+import os
+import SConfig
+
+class BlasLapack(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.libraries = [['blas', 'lapack']]
+        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 f76b33690068 -r 1926c51319ff config/SConfig/packages/MPI.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/MPI.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,18 @@
+import os
+import SConfig
+
+class MPI(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.base_patterns = ['mpich*', 'MPICH*']
+        self.sub_dirs += [[[os.path.join('include', 'mpi')], ['lib']]]
+        self.headers = ['mpi.h']
+        self.libraries = [['mpich'],
+                          ['mpich', 'pmpich'],
+                          ['mpich', 'rt'],
+                          ['mpich', 'pmpich', 'rt'],
+                          ['mpi']]
+        self.require_shared = True
+        self.use_rpath = True
diff -r f76b33690068 -r 1926c51319ff config/SConfig/packages/PETSc.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/PETSc.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,67 @@
+import os
+import SConfig
+
+class PETSc(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.dependencies = [SConfig.packages.MPI]
+        self.base_patterns = ['petsc*', 'PETSC*', 'PETSc*']
+        self.sub_dirs += [[[os.path.join('include', 'petsc')], ['lib']]]
+        self.headers = ['petsc.h',
+                        'petscvec.h', 'petscmat.h',
+                        'petscksp.h', 'petscsnes.h']
+        self.libraries = [['petsc', 'petscdm',
+                           'petscvec', 'petscmat',
+                           'petscksp', 'petscsnes']]
+        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 f76b33690068 -r 1926c51319ff config/SConfig/packages/PICellerator.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/PICellerator.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,31 @@
+import os
+import SConfig
+
+class PICellerator(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.dependencies = [SConfig.packages.StGermain]
+        self.base_patterns = ['PICellerator*']
+        self.headers = [os.path.join('PICellerator', 'PICellerator.h')]
+        self.dependency_headers = [os.path.join('StGermain', 'StGermain.h'),
+                                   os.path.join('StgDomain', 'StgDomain.h'),
+                                   os.path.join('StgFEM', 'StgFEM.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 f76b33690068 -r 1926c51319ff config/SConfig/packages/SVNRevision.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/SVNRevision.py	Mon Mar 03 05:14:13 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 f76b33690068 -r 1926c51319ff config/SConfig/packages/StGermain.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StGermain.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,24 @@
+import os
+import SConfig
+
+class StGermain(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.dependencies = [SConfig.packages.cmath,
+                             SConfig.packages.libXML2,
+                             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 f76b33690068 -r 1926c51319ff config/SConfig/packages/StgDomain.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StgDomain.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,27 @@
+import os
+import SConfig
+
+class StgDomain(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.dependencies = [SConfig.packages.StGermain]
+        self.base_patterns = ['StgDomain*']
+        self.headers = [os.path.join('StgDomain', 'StgDomain.h')]
+        self.dependency_headers = [os.path.join('StGermain', 'StGermain.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 f76b33690068 -r 1926c51319ff config/SConfig/packages/StgFEM.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/StgFEM.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,28 @@
+import os
+import SConfig
+
+class StgFEM(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.dependencies = [SConfig.packages.StGermain]
+        self.base_patterns = ['StgFEM*']
+        self.headers = [os.path.join('StgFEM', 'StgFEM.h')]
+        self.dependency_headers = [os.path.join('StGermain', 'StGermain.h'),
+                                   os.path.join('StgDomain', 'StgDomain.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 f76b33690068 -r 1926c51319ff config/SConfig/packages/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/__init__.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,10 @@
+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
diff -r f76b33690068 -r 1926c51319ff config/SConfig/packages/cmath.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/cmath.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,8 @@
+import os
+import SConfig
+
+class cmath(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_options()
+        self.libraries = [['m']]
diff -r f76b33690068 -r 1926c51319ff config/SConfig/packages/libXML2.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SConfig/packages/libXML2.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,11 @@
+import os
+import SConfig
+
+class libXML2(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.setup_search_defaults()
+        self.setup_options()
+        self.sub_dirs += [[[os.path.join('include', 'libxml2')], ['lib']]]
+        self.headers = [os.path.join('libxml', 'parser.h')]
+        self.libraries = [['xml2']]
diff -r f76b33690068 -r 1926c51319ff config/packages/StgDomain.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/packages/StgDomain.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,51 @@
+import os
+import SConfig
+import SCons.Script
+
+class StgDomain(SConfig.Package):
+    def __init__(self, env, options):
+        SConfig.Package.__init__(self, env, options)
+        self.checks = [self.setup_environment]
+        self.dependencies = [SConfig.packages.cmath,
+                             SConfig.packages.libXML2,
+                             SConfig.packages.MPI,
+                             SConfig.packages.SVNRevision,
+                             SConfig.packages.BlasLapack,
+                             SConfig.packages.StGermain]
+        if self.opts:
+            self.opts.AddOptions(
+                SCons.Script.BoolOption('debug',
+                                        'Enable debugging', 1),
+                SCons.Script.BoolOption('staticLibraries',
+                                        'Build static libraries only', 0),
+                ('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])
+        self.env.AppendUnique(CPPPATH=[os.path.join(inc_path, 'StgDomain')])
+
+        # Setup debugging.
+        if self.env['debug']:
+            self.env.MergeFlags('-g')
+
+        return [1, '', '']
diff -r f76b33690068 -r 1926c51319ff config/packages/__init__.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/packages/__init__.py	Mon Mar 03 05:14:13 2008 +0000
@@ -0,0 +1,1 @@
+from StgDomain import StgDomain



More information about the CIG-COMMITS mailing list