[cig-commits] commit: Adding SCons scripts to the Magma repository.
Mercurial
hg at geodynamics.org
Mon Nov 24 11:22:38 PST 2008
changeset: 11:c6ee62cae62f
user: LukeHodkinson
date: Thu Feb 07 04:14:00 2008 +0000
files: SConfigure SConsUtils SConstruct
description:
Adding SCons scripts to the Magma repository.
diff -r b41b68d8d2fe -r c6ee62cae62f SConfigure
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SConfigure Thu Feb 07 04:14:00 2008 +0000
@@ -0,0 +1,405 @@
+import os, sys, platform
+Import('env opts build_opts')
+
+#
+# Custom configuration checks.
+#
+
+def CheckFortranSymbol(ctx):
+ fSrc = """
+ Program Conftest
+ external method
+ integer i
+ call method(i)
+ stop
+ end
+"""
+ cSrc = """
+#include <stdio.h>
+void method(int *i){printf("FORTRAN_NORMAL");}
+void method_(int *i){printf("FORTRAN_SINGLE_TRAILINGBAR");}
+void method__(int *i){printf("FORTRAN_DOUBLE_TRAILINGBAR");}
+void METHOD(int *i){printf("FORTRAN_UPPERCASE");}
+"""
+ ctx.Message('Checking for fortran symbol type... ')
+
+ res = ctx.TryCompile(cSrc, '.c')
+ if not res:
+ ctx.Result(res)
+ return res
+ cObj = ctx.lastTarget
+
+ oldLINK = env['LINK'] if 'LINK' in env._dict else None
+ oldLINKFLAGS = env['LINKFLAGS'] if 'LINKFLAGS' in env._dict else None
+ oldLIBS = env['LIBS'] if 'LIBS' in env._dict else None
+ env['LINK'] = env['_FORTRAND']
+ env['LINKFLAGS'] = str(cObj)
+ env['LIBS'] = []
+ res = ctx.TryRun(fSrc, '.F')
+ env['LINK'] = oldLINK
+ env['LINKFLAGS'] = oldLINKFLAGS
+ env['LIBS'] = oldLIBS
+ if not res[0]:
+ ctx.Result(res[0])
+ return res[0]
+
+ env.Append(CPPDEFINES=[res[1]])
+ ctx.Result(res[0])
+ return res[0]
+
+#
+# Custom package classes.
+#
+
+def petsc_get_arch(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
+
+def petsc_get_x11_libs(base_dir, arch):
+ petscconf = os.path.join(base_dir, 'bmake',
+ arch, 'petscconf')
+ if not os.path.exists(petscconf):
+ return None
+ f = file(petscconf, 'r')
+ libs = []
+ lib_dirs = []
+ for l in f.readlines():
+ if l[:7] == 'X11_LIB':
+ libs = l.split('=')[1].strip().split(' ')
+ libs = [lib[2:] for lib in libs \
+ if lib[:2] == env['LIBLINKPREFIX']]
+ lib_dirs = [lib[2:] for lib in libs \
+ if lib[:2] == env['LIBDIRPREFIX']]
+ break
+ f.close()
+ return (lib_dirs, libs)
+
+def petsc_check_state(state):
+ arch = petsc_get_arch(state.base_dir)
+ if not arch:
+ return False
+
+ x11_libs = petsc_get_x11_libs(state.base_dir, arch)
+ if x11_libs is None:
+ return False
+
+ hdr_dir = os.path.join(state.base_dir, 'bmake', arch)
+ if hdr_dir not in state.hdr_dirs:
+ state.hdr_dirs.append(hdr_dir)
+
+ lib_dir = os.path.join(state.base_dir, 'lib')
+ if lib_dir in state.lib_dirs:
+ state.lib_dirs.remove(lib_dir)
+ lib_dir = os.path.join(lib_dir, arch)
+ if lib_dir not in state.lib_dirs:
+ state.lib_dirs.append(lib_dir)
+
+ for l in x11_libs[0]:
+ if l not in state.lib_dirs:
+ state.lib_dirs.append(l)
+ for l in x11_libs[1]:
+ if l not in state.libs:
+ state.libs.append(l)
+
+ return True
+
+#
+# Do configuration.
+#
+
+if not env.GetOption('clean'):
+ if not build_opts:
+ cfg = Configure(env,
+ custom_tests={'CheckPackage':
+ env.CheckPackage,
+ 'CheckFortranSymbol':
+ CheckFortranSymbol})
+
+ # Add a member to 'env' for storing package results.
+ if not build_opts:
+ env['PACKAGES'] = {}
+
+ # Print out a message about what architecture we're
+ # planning on using.
+ if not build_opts:
+ print 'Configuring for %s' % platform.system(),
+ if env._dict.get('force32bit', None):
+ bits = 32
+ else:
+ bits = 64 if \
+ platform.architecture()[0].find('64') != -1 else 32
+ print '%dbit ...' % bits
+
+ #
+ # Check for the C math library.
+ #
+
+ if not build_opts:
+ if not cfg.CheckLib('m'):
+ print "Couldn't find the C standard math libaray."
+ env.Exit()
+
+ #
+ # Check for MPICH.
+ #
+
+ mpich = env.Package('MPICH', env)
+ mpich.pkg_dirs = ['mpich*', 'MPICH*']
+ mpich.hdrs = ['mpi.h']
+ mpich.libs = ['mpich',
+ ('mpich', 'pmpich'),
+ ('mpich', 'rt'),
+ ('mpich', 'pmpich', 'rt')]
+ mpich.use_rpath = True
+ mpich.major_macro = 'MPI_VERSION'
+ mpich.minor_macro = 'MPI_SUBVERSION'
+ mpich.major_ver = 1
+ mpich.minor_ver = 2
+ mpich.func_src = 'MPI_Init(&argc, &argv);\nMPI_Finalize();'
+
+ if not build_opts:
+ if not cfg.CheckPackage(mpich):
+ env.Exit()
+ opts.Save('config.cache', env)
+ else:
+ mpich.add_options(opts)
+
+ #
+ # Check for libXML2.
+ #
+
+ libxml = env.Package('libXML2', env)
+ libxml.pkg_dirs = ['libxml2', 'libXML2']
+ libxml.hdr_sub_dir = 'libxml2'
+ libxml.hdrs = ['libxml/xmlIO.h']
+ libxml.libs = ['libxml2']
+
+ if not build_opts:
+ if not cfg.CheckPackage(libxml):
+ env.Exit()
+ opts.Save('config.cache', env)
+ else:
+ libxml.add_options(opts)
+
+ #
+ # Check for an implementation of lapack and blas.
+ #
+
+ lapack = env.Package('blaslapack', env)
+ lapack.libs = [('blas', 'lapack'),
+ 'lapack',
+ 'mkl']
+ lapack.frameworks = ['Accelerate']
+
+ if not build_opts:
+ if not cfg.CheckPackage(lapack):
+ env.Exit()
+ opts.Save('config.cache', env)
+ else:
+ lapack.add_options(opts)
+
+ #
+ # Check for an implementation of PETSc
+ #
+
+ petsc = env.Package('PETSc', env)
+ petsc.pkg_dirs = ['petsc*', 'PETSc*', 'PETSC*']
+ petsc.hdrs = ['petsc.h',
+ 'petscvec.h', 'petscmat.h',
+ 'petscksp.h', 'petscsnes.h']
+ petsc.libs = [('petsc', 'petscdm',
+ 'petscvec', 'petscmat',
+ 'petscksp', 'petscsnes')]
+ petsc.use_rpath = True
+ petsc.check_state = petsc_check_state
+ petsc.major_macro = 'PETSC_VERSION_MAJOR'
+ petsc.minor_macro = 'PETSC_VERSION_MINOR'
+ petsc.major_ver = 2
+ petsc.minor_ver = 3
+
+ if not build_opts:
+ if not cfg.CheckPackage(petsc):
+ env.Exit()
+ env.Append(CPPDEFINES='HAVE_PETSC')
+ opts.Save('config.cache', env)
+ else:
+ petsc.add_options(opts)
+
+ #
+ # Setup OpenGL.
+ #
+
+ ogl = env.Package('OpenGL', env)
+ ogl.hdr_sub_dir = 'GL'
+ ogl.hdrs = ['gl.h', 'glu.h']
+ ogl.libs = [('GL', 'GLU')]
+ ogl.frameworks = ['OpenGL']
+
+ if not build_opts:
+ if not cfg.CheckPackage(ogl):
+ env.Exit()
+ env.Append(CPPDEFINES='HAVE_GL')
+ opts.Save('config.cache', env)
+ else:
+ ogl.add_options(opts)
+
+ #
+ # Setup Mesa.
+ #
+
+ mesa = env.Package('OSMesa', env)
+ mesa.libs = ['OSMesa']
+
+ if not build_opts:
+ if not cfg.CheckPackage(mesa):
+ print " Couldn't find OSMesa - off screen"
+ print " rendering disabled."
+ else:
+ env.Append(CPPDEFINES='HAVE_MESA')
+ opts.Save('config.cache', env)
+ else:
+ mesa.add_options(opts)
+
+ #
+ # Setup SDL.
+ #
+
+ sdl = env.Package('SDL', env)
+ sdl.hdrs = ['SDL/SDL.h']
+ sdl.libs = ['SDL']
+ sdl.frameworks = ['SDL', 'Cocoa']
+
+ if not build_opts:
+ if cfg.CheckPackage(sdl):
+ env.Append(CPPDEFINES='HAVE_SDL')
+ opts.Save('config.cache', env)
+ else:
+ sdl.add_options(opts)
+
+ #
+ # Setup various image formats.
+ #
+
+ png = env.Package('libPNG', env)
+ png.hdrs = ['png.h']
+ png.libs = ['png']
+
+ if not build_opts:
+ if cfg.CheckPackage(png):
+ env.Append(CPPDEFINES='HAVE_PNG')
+ opts.Save('config.cache', env)
+ else:
+ png.add_options(opts)
+
+ jpeg = env.Package('libJPEG', env)
+ jpeg.hdrs = ['jpeglib.h']
+ jpeg.libs = ['jpeg']
+
+ if not build_opts:
+ if cfg.CheckPackage(jpeg):
+ env.Append(CPPDEFINES='HAVE_JPEG')
+ opts.Save('config.cache', env)
+ else:
+ jpeg.add_options(opts)
+
+ tiff = env.Package('libTIFF', env)
+ tiff.hdrs = ['tiff.h']
+ tiff.libs = ['tiff']
+
+ if not build_opts:
+ if cfg.CheckPackage(tiff):
+ env.Append(CPPDEFINES='HAVE_TIFF')
+ opts.Save('config.cache', env)
+ else:
+ tiff.add_options(opts)
+
+ #
+ # Setup libFAME.
+ #
+
+ fame = env.Package('libFAME', env)
+ fame.hdrs = ['fame.h']
+ fame.libs = ['fame']
+
+ if not build_opts:
+ if cfg.CheckPackage(fame):
+ env.Append(CPPDEFINES='HAVE_FAME')
+ opts.Save('config.cache', env)
+ else:
+ fame.add_options(opts)
+
+ #
+ # Setup libavcodec.
+ #
+
+ avc = env.Package('libavcodec', env)
+ avc.hdrs = ['ffmpeg/avcodec.h']
+ avc.libs = ['avcodec']
+
+ if not build_opts:
+ if cfg.CheckPackage(avc):
+ env.Append(CPPDEFINES='HAVE_AVCODEC')
+ opts.Save('config.cache', env)
+ else:
+ avc.add_options(opts)
+
+ #
+ # Check Fortran symbol type.
+ #
+
+ if not build_opts:
+ if not cfg.CheckFortranSymbol():
+ env.Exit()
+
+ #
+ # Extract revision number.
+ #
+
+ if not build_opts:
+ svnPath = Dir('.').srcnode().abspath
+ svnPath = os.path.join(svnPath, '.svn', 'entries')
+ if not os.path.exists(svnPath):
+ print "\nYou appear to be building the code from something"
+ print "that wasn't checked out of a repository. Bummer."
+ env.Exit()
+ f = file(svnPath, 'r')
+ f.readline()
+ f.readline()
+ f.readline()
+ ver = env['ESCAPE']('"' + str(int(f.readline())) + '"')
+ env.Append(CPPDEFINES=[('VERSION', ver)])
+ f.close()
+
+ #
+ # Add module extension to build commands.
+ #
+
+ if not build_opts:
+ ext = env['ESCAPE']('"' + env['SHLIBSUFFIX'][1:] + '"')
+ env.Append(CPPDEFINES=[('MODULE_EXT', ext)])
+
+ #
+ # Add the library directory.
+ #
+
+ if not build_opts:
+ libDir = os.path.join(Dir('.').abspath, 'build', 'lib')
+ libDir = env['ESCAPE']('"' + libDir + '"')
+ env.Append(CPPDEFINES=[('LIB_DIR', libDir)])
+
+ #
+ # Setup the dynamic library search paths.
+ #
+
+ if not build_opts:
+ env.Append(RPATH=[os.path.join(Dir('.').abspath, 'build', 'lib')])
+
+ # Finish the configuration.
+ if not build_opts:
+ env = cfg.Finish()
diff -r b41b68d8d2fe -r c6ee62cae62f SConsUtils
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SConsUtils Thu Feb 07 04:14:00 2008 +0000
@@ -0,0 +1,538 @@
+import os, glob as pyglob, platform
+from SCons.Script.SConscript import SConsEnvironment
+Import('env')
+
+#
+# Setup some basic path utilities.
+#
+
+# Globbing for hierarchical SCons scripts.
+def glob(env, ptrn):
+ if not os.path.isabs(ptrn):
+ old = os.getcwd()
+ os.chdir(Dir('.').srcnode().abspath)
+ res = pyglob.glob(ptrn)
+ os.chdir(old)
+ else:
+ res = pyglob.glob(ptrn)
+ return res
+
+# Normalise an SCons path to the project root.
+def norm_path(env, path):
+ cur_dir = env.Dir('.').srcnode().path
+ if path[0] != '#':
+ path = os.path.join(cur_dir, path)
+ else:
+ path = path[1:]
+ return path
+
+# Copy a file immediately.
+def copy_file(env, dst, src):
+ dst = env.norm_path(dst)
+ old = os.getcwd()
+ os.chdir(env.GetLaunchDir())
+ if not File(os.path.abspath(dst)).current():
+ src = env.norm_path(src)
+ dst_dir = os.path.dirname(dst)
+ if not os.path.exists(dst_dir):
+ Execute(Mkdir(dst_dir))
+ Execute(Copy(dst, src))
+ os.chdir(old)
+
+# Temporarily replace some paths.
+def push_state(env, state):
+ old = {}
+ copy = dict(state)
+ for k, v in copy.iteritems():
+ copy[k] = v if isinstance(v, list) else [v]
+ old[k] = env[k]
+ env.AppendUnique(**copy)
+ return old
+
+# Replace old paths.
+def pop_state(env, state):
+ env.Replace(**state)
+
+# Add to the SCons main class.
+SConsEnvironment.glob = glob
+SConsEnvironment.norm_path = norm_path
+SConsEnvironment.copy_file = copy_file
+SConsEnvironment.push_state = push_state
+SConsEnvironment.pop_state = pop_state
+
+#
+# Setup the hierarchical build stuff.
+#
+
+def hbuild(env, builder, hpath, store=True, *args, **kw):
+ nodes = builder(*args, **kw)
+ if store:
+ if builder not in env.hnodes:
+ env.hnodes[builder] = {}
+ place = env.hnodes[builder]
+ if '.' not in place:
+ place['.'] = []
+ place['.'].append(nodes)
+ for h in hpath.split(os.path.sep):
+ if h not in place:
+ place[h] = {}
+ place = place[h]
+ if '.' not in place:
+ place['.'] = []
+ place['.'].append(nodes)
+ return nodes
+
+def get_hnodes(env, builder, hpath=None):
+ place = env.hnodes[builder]
+ if hpath:
+ for h in hpath.split(os.path.sep):
+ place = place[h]
+ return place['.']
+
+def hclear(env):
+ env.hnodes = {}
+
+SConsEnvironment.hbuild = hbuild
+SConsEnvironment.get_hnodes = get_hnodes
+SConsEnvironment.hclear = hclear
+
+#
+# Setup some utilities for handling package configuration.
+#
+
+class PackageState(object):
+ def __init__(self, pkg, base_dir, hdr_dirs, lib_dirs,
+ libs, frameworks):
+ self.pkg = pkg
+ self.base_dir = base_dir
+ self.hdr_dirs = hdr_dirs
+ self.lib_dirs = lib_dirs
+ self.libs = libs
+ self.frameworks = frameworks
+ self.state = {}
+ self.old = None
+
+ def setup(self, env):
+ self.build_state()
+ if self.old != None:
+ print 'Error'
+ env.Exit()
+ self.old = env.push_state(self.state)
+
+ def teardown(self, env):
+ env.pop_state(self.old)
+ self.old = None
+
+ def build_state(self):
+ self.state = {}
+ if not self.frameworks:
+ if self.hdr_dirs:
+ self.state['CPPPATH'] = self.hdr_dirs
+ if self.lib_dirs:
+ self.state['LIBPATH'] = self.lib_dirs
+ if self.pkg.use_rpath:
+ self.state['RPATH'] = self.lib_dirs
+ if self.libs:
+ self.state['LIBS'] = self.libs
+ else:
+ self.state['FRAMEWORKS'] = self.frameworks
+
+ def text(self, prefix=''):
+ txt = ''
+ if self.base_dir:
+ txt += prefix + 'Base path: %s\n' % self.base_dir
+ if self.hdr_dirs:
+ txt += prefix + 'Header paths: %s\n' % str(self.hdr_dirs)
+ if self.lib_dirs:
+ txt += prefix + 'Lib paths: %s\n' % str(self.lib_dirs)
+ if self.libs:
+ txt += prefix + 'Libs: %s\n'% str(self.libs)
+ if self.frameworks:
+ txt += prefix + 'Frameworks: %s\n' % str(self.frameworks)
+ return txt
+
+ def __str__(self):
+ return self.text()
+
+
+class Package(object):
+ check_src = """
+#include<stdlib.h>
+#include<stdio.h>
+%s
+int main(int argc, char** argv) {
+%s
+%s
+return 0;
+}
+"""
+
+ def __init__(self, name, env):
+ self.name = name
+ self.env = env
+
+ # Setup some system specific information.
+ self.system = platform.system()
+ if env._dict.get('force32bit', None):
+ self.bits = 32
+ else:
+ self.bits = 64 if \
+ platform.architecture()[0].find('64') != -1 else 32
+
+ # Provide a list (or a single) of strings to override the
+ # generated search base directories.
+ self.base_dirs = []
+
+ # Specify a list of directories that are common
+ # sub-directories for installations of this package.
+ self.pkg_dirs = []
+
+ # Setup header and library subdirectories; can be a list of (or
+ # just a single) tuple(s) containing the header/library sub-
+ # directory or a tuple containing simultaneous header/library
+ # subdirectories.
+ self.sub_dirs = []
+
+ # Some libraries pack headers under their own subdirectory
+ # (i.e. libXML2).
+ self.hdr_sub_dir = ''
+
+ # Place any headers that should be checked for here.
+ self.hdrs = []
+
+ # Setup default library names.
+ self.libs = [] # can be a list or a list of tuples
+
+ # Add any frameworks that may exist representing this package here.
+ self.frameworks = []
+
+ # Set this flag if RPATH's are needed for this package.
+ self.use_rpath = False
+
+ # Use this member to specify a callback function for
+ # customising search states.
+ self.check_state = None
+
+ # Set these to perform version checks.
+ self.major_macro = None
+ self.minor_macro = None
+ self.major_ver = None
+ self.minor_ver = None
+
+ # Insert any library function calls to perform here.
+ self.func_src = ''
+
+ # Prepare default options.
+ self.cmd_opts = None
+ self.env_opts = None
+ self.opt_entries = None
+ self.build_options()
+
+ def build_options(self):
+ # Build the command line options.
+ if not self.cmd_opts:
+ low = self.name.lower()
+ self.cmd_opts = {'base_dir': low + 'Dir',
+ 'hdr_dir': low + 'IncDir',
+ 'lib_dir': low + 'LibDir',
+ 'libs': low + 'Libs',
+ 'framework': low + 'Framework'}
+
+ # Build environment options.
+ if not self.env_opts:
+ upp = self.name.upper()
+ self.env_opts = {'base_dir': upp + '_DIR',
+ 'hdr_dir': upp + '_INC_DIR',
+ 'lib_dir': upp + '_LIB_DIR',
+ 'libs': upp + '_LIBS',
+ 'framework': upp + '_FRAMEWORK'}
+
+ # Setup option entries.
+ self.opt_entries = [
+ PathOption(self.cmd_opts['base_dir'],
+ '%s installation path' % self.name,
+ None, PathOption.PathIsDir),
+ PathOption(self.cmd_opts['hdr_dir'],
+ '%s header installation path' % self.name,
+ None, PathOption.PathIsDir),
+ PathOption(self.cmd_opts['lib_dir'],
+ '%s library installation path' % self.name,
+ None, PathOption.PathIsDir),
+ (self.cmd_opts['libs'],
+ '%s libraries' % self.name,
+ None, None),
+ (self.cmd_opts['framework'],
+ '%s framework' % self.name,
+ None, None)
+ ]
+
+ def add_options(self, opts):
+ opts.AddOptions(*self.opt_entries)
+
+ def build_search_dirs(self):
+ if not self.base_dirs:
+ # Setup some default search directories based on the
+ # kind of platform we're on.
+ if self.system in ['Darwin', 'Linux']:
+ # Setup the base directories.
+ self.base_dirs = []
+ if self.system == 'Darwin':
+ # Darwin specific
+ self.base_dirs += ['/sw']
+
+ # Common to both Darwin and Linux
+ self.base_dirs += ['/usr', '/usr/local']
+ for d in self.pkg_dirs:
+ ptrn = os.path.join('/usr/local', d)
+ self.base_dirs += pyglob.glob(ptrn)
+ ptrn = os.path.join(env['ENV']['HOME'], d)
+ self.base_dirs += pyglob.glob(ptrn)
+
+ elif self.system == 'Windows':
+ pass # TODO
+
+ # Strip out any directories that don't exist or aren't
+ # directories.
+ self.base_dirs = [d for d in self.base_dirs \
+ if os.path.exists(d) and \
+ os.path.isdir(d)]
+
+ if not self.sub_dirs:
+ # Now append any usual subdirectories to our list.
+ if self.system in ['Darwin', 'Linux']:
+ lib_dir = 'lib' if self.bits == 32 else 'lib64'
+ self.sub_dirs = [('include', lib_dir)]
+ if self.hdr_sub_dir:
+ self.sub_dirs += [(os.path.join('include',
+ self.hdr_sub_dir),
+ lib_dir)]
+
+ elif self.system == 'Windows':
+ pass # TODO
+
+ def build_states(self):
+ # If we have options of any kind, use those exclusively.
+ if len(self.opts):
+ # Grab all the options we have.
+ base_dir = self.opts.get('base_dir', '')
+ ohdr_dir = self.opts.get('hdr_dir', '')
+ ohdr_dir = [ohdr_dir] if ohdr_dir else []
+ olib_dir = self.opts.get('lib_dir', '')
+ olib_dir = [olib_dir] if olib_dir else []
+ libs = self.opts.get('libs', '')
+ libs = [libs] if libs else []
+ fw = self.opts.get('fw', '')
+ fw = [fw] if fw else []
+
+ # If certain specific options were given then use only
+ # options to locate the package.
+ if (ohdr_dir and olib_dir and libs) or fw:
+ state = PackageState(self, base_dir, ohdr_dir, olib_dir,
+ libs, fw)
+ if self.check_state:
+ self.check_state(state)
+ self.states = [state]
+ return
+
+ # Figure out what to alias.
+ if ohdr_dir and olib_dir:
+ # Place a dummy value in here so the loop below iterates
+ # once.
+ sub_dir = [('', '')]
+ else:
+ sub_dir = self.sub_dirs
+
+ base_dir = [base_dir] if base_dir else self.base_dirs
+ if not libs:
+ libs = self.libs
+ if not fw:
+ fw = self.frameworks
+
+ else:
+ # Alias to use defaults.
+ base_dir = self.base_dirs
+ libs = self.libs
+ sub_dir = self.sub_dirs
+ fw = self.frameworks
+
+ # Clear out other values.
+ ohdr_dir = None
+ olib_dir = None
+
+ self.states = []
+ if not (ohdr_dir or olib_dir) and not self.opts.get('base_dir', ''):
+ # Before formulating other states, insert a blank state to
+ # check if the package has been made available.
+ for l in libs:
+ state = PackageState(self, '', [], [], l, None)
+ self.states += [state]
+
+ # Begin forming states from default search locations.
+ for base in base_dir:
+ for sub in sub_dir:
+ # Were we given header directories?
+ if ohdr_dir:
+ hdr_dir = ohdr_dir
+ else:
+ # Combine header dirs.
+ if isinstance(sub[0], tuple):
+ hdr_dir = [os.path.join(base, s) for s in sub[0]]
+ else:
+ hdr_dir = [os.path.join(base, sub[0])]
+
+ # Were we given library directories?
+ if olib_dir:
+ lib_dir = olib_dir
+ else:
+ # Combine library dirs.
+ if isinstance(sub[0], tuple):
+ lib_dir = [os.path.join(base, s) for s in sub[1]]
+ else:
+ lib_dir = [os.path.join(base, sub[1])]
+
+ # Permute with libraries.
+ for l in libs:
+ if isinstance(l, tuple):
+ l = list(l)
+
+ # Create our package state.
+ state = PackageState(self, base, hdr_dir, lib_dir,
+ l, None)
+
+ # If we have a callback, use it.
+ if self.check_state:
+ if not self.check_state(state):
+ continue
+
+ # Store in state array.
+ self.states += [state]
+
+ # Add a state for any alternate frameworks (if they were given).
+ if fw:
+ self.states += [PackageState(self, '', [], [], [], fw)]
+
+ def next_state(self, ctx):
+ # Set everything up.
+ self.build_options()
+ self.process_opts(ctx.env)
+ self.build_search_dirs()
+ self.build_states()
+
+ # Begin trialing states.
+ for s in self.states:
+ s.setup(ctx.env)
+ yield s
+ s.teardown(ctx.env)
+
+ def check(self, ctx, state):
+ hdr_src = self.string_hdrs()
+ ver_src = self.string_ver()
+ src = self.check_src % (hdr_src, ver_src, self.func_src)
+
+ env = ctx.env
+ res = ctx.TryRun(src, '.c')
+ return res
+
+ def string_hdrs(self):
+ txt = ''
+ if self.hdrs:
+ for h in self.hdrs:
+ txt += '#include<%s>\n' % h
+ return txt
+
+ def string_ver(self):
+ if self.major_macro and self.major_ver:
+ txt = '(%s >= %d)' % (self.major_macro, self.major_ver)
+ if self.minor_macro and self.minor_ver:
+ txt = '(%s ? 0 : (%s == %d && %s >= %d)' % \
+ (txt, self.major_macro, self.major_ver,
+ self.minor_macro, self.minor_ver)
+ txt += ' ? 0 : 1'
+ if self.minor_macro and self.minor_ver:
+ txt += ')'
+ txt = 'if( %s )' % txt
+ txt = '%s {\n printf("invalid version (v%s' % (txt, '%d')
+ if self.minor_macro:
+ txt = '%s.\%s), requires ' % (txt, '%d')
+ else:
+ txt = '%s)' % txt
+ txt = '%s, requires v%d' % (txt, self.major_ver)
+ if self.minor_ver is not None:
+ txt = '%s.%d' % (txt, self.minor_ver)
+ txt = '%s", %s' % (txt, self.major_macro)
+ if self.minor_macro:
+ txt = '%s, %s' % (txt, self.minor_macro)
+ txt = '%s);\n}\n' % (txt)
+ else:
+ txt = ''
+ return txt
+
+ def process_opts(self, env):
+ """Processes all options specified in self.cmd_opts and
+self.env_opts."""
+
+ # Clear any existing options.
+ self.opts = {}
+
+ # Fill in values from command line options first.
+ for k, v in self.cmd_opts.iteritems():
+ val = env.get(v, None)
+ if val:
+ self.opts[k] = val
+
+ # If command line options were given, don't check environment
+ # options (we don't want to mix and match just yet).
+ if len(self.opts):
+ return
+
+ # Now process environment options.
+ for k, v in self.env_opts.iteritems():
+ val = env['ENV'].get(v, None)
+ if val:
+ self.opts[k] = val
+
+def CheckPackage(ctx, pkg):
+ env = ctx.env
+ ctx.Message('Checking for package %s ... ' % pkg.name)
+ res = 0
+ first = True
+ for state in pkg.next_state(ctx):
+ # Log some information.
+ ctx.Log('**********************************\n')
+ ctx.Log('* Package state *\n')
+ ctx.Log('**********************************\n')
+ ctx.Log(str(state))
+ ctx.Log('**********************************\n')
+
+ # Perform the check.
+ res = pkg.check(ctx, state)
+
+ # Did it pass?
+ if res[0] and res[1] == '':
+ ctx.Log('**********************************\n')
+ ctx.Log('* Result *\n')
+ ctx.Log('**********************************\n')
+ ctx.Log('Passed\n')
+ ctx.Log('**********************************\n')
+ ctx.Result(1)
+ ctx.Display(state.text(prefix=' '))
+ ctx.Display('\n')
+ env['PACKAGES'][pkg.name] = state
+ return 1
+
+ # No.
+ ctx.Log('**********************************\n')
+ ctx.Log('* Result *\n')
+ ctx.Log('**********************************\n')
+ if res[1]:
+ ctx.Log('Failed: ' + res[1] + '\n')
+ else:
+ ctx.Log('Failed\n')
+ ctx.Log('**********************************\n')
+ ctx.Result(0)
+ return 0
+
+# Need to store these guys on the environment.
+env.Package = Package
+env.PackageState = PackageState
+env.CheckPackage = CheckPackage
diff -r b41b68d8d2fe -r c6ee62cae62f SConstruct
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SConstruct Thu Feb 07 04:14:00 2008 +0000
@@ -0,0 +1,112 @@
+import os
+
+# Check versions of some things.
+EnsurePythonVersion(2, 5)
+EnsureSConsVersion(0, 97)
+
+#
+# Create our substitution environment.
+#
+
+env = Environment(CC='cc', ENV=os.environ)
+
+# Include our SCons utils (hopefully they'll add stuff to do
+# these things we need).
+SConscript('SConsUtils', exports='env')
+
+#
+# Setup our option database.
+#
+
+# Create the options object.
+opts = Options('config.cache')
+
+# Do something hacky to get all the options from our configuration
+# script.
+build_opts = True
+SConscript('SConfigure', exports='env opts build_opts')
+build_opts = False
+
+# Add other options.
+opts.AddOptions(
+ BoolOption('debug', 'Enable debugging version', 1),
+ BoolOption('useMpiRecord', 'Don''t know what this does...', 0),
+ PathOption('prefix', 'Installation path',
+ '/usr/local', PathOption.PathIsDirCreate),
+ BoolOption('force32bit', 'Force the use of 32-bit libraries', 0),
+ PackageOption('csoap', 'Enable use of the package CSoap', 'no'))
+
+#
+# Fill in our substitution environment with useful things.
+#
+
+opts.Update(env)
+opts.Save('config.cache', env)
+
+# Generate some help text at this point.
+env.Help(opts.GenerateHelpText(env))
+
+# We need to add these guys so we don't get dictionary key errors.
+env['CPPPATH'] = env['CPPPATH'] if 'CPPPATH' in env._dict else []
+env['LIBPATH'] = env['LIBPATH'] if 'LIBPATH' in env._dict else []
+env['CPPDEFINES'] = env['CPPDEFINES'] if 'CPPDEFINES' in env._dict else []
+env['LIBS'] = env['LIBS'] if 'LIBS' in env._dict else []
+env['RPATH'] = env['RPATH'] if 'RPATH' in env._dict else []
+
+# Add any variables that get used throughout the whole build.
+if env['debug']:
+ env.Append(CCFLAGS='-g')
+env.Append(CPPPATH=['#build/include'])
+env.Append(LIBPATH=['#build/lib'])
+
+# Setup any additional build targets.
+env.Alias('install', env['prefix'])
+
+# Setup all our StGermain specific utilities.
+SConscript('StgSCons', exports='env')
+
+#
+# Configuration section.
+#
+
+build_opts = False
+SConscript('SConfigure', exports='env opts build_opts')
+
+#
+# Call target SConscripts.
+#
+
+env.BuildDir('build', '.', duplicate=0)
+
+env.clear_all()
+SConscript('build/StGermain/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/StGermain'])
+env.Append(LIBS=['StGermain'])
+
+env.clear_all()
+SConscript('build/StgDomain/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/StgDomain'])
+env.Append(LIBS=['StgDomain'])
+
+env.clear_all()
+SConscript('build/StgFEM/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/StgFEM'])
+env.Append(LIBS=['StgFEM'])
+
+env.clear_all()
+SConscript('build/PICellerator/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/PICellerator'])
+env.Append(LIBS=['PICellerator'])
+
+env.clear_all()
+SConscript('build/Underworld/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/Underworld'])
+env.Append(LIBS=['Underworld'])
+
+env.clear_all()
+SConscript('build/Experimental/SConscript', exports='env')
+#env.Append(CPPPATH=['#build/include/Experimental'])
+env.Append(LIBS=['Underworld'])
+
+env.clear_all()
+SConscript('build/gLucifer/SConscript', exports='env')
More information about the CIG-COMMITS
mailing list