[cig-commits] commit: Updating stgMagma to the same point as stgUnderworld.

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


changeset:   29:cff250571157
user:        LukeHodkinson
date:        Thu Feb 14 23:33:46 2008 +0000
files:       SConfigure SConsUtils SConstruct
description:
Updating stgMagma to the same point as stgUnderworld.


diff -r 988d32ff5aa4 -r cff250571157 SConfigure
--- a/SConfigure	Tue Feb 12 04:41:40 2008 +0000
+++ b/SConfigure	Thu Feb 14 23:33:46 2008 +0000
@@ -1,5 +1,5 @@ import os, sys, platform
 import os, sys, platform
-Import('env opts build_opts')
+Import('env')
 
 #
 # Custom configuration checks.
@@ -47,6 +47,22 @@ void METHOD(int *i){printf("FORTRAN_UPPE
         return res[0]
 
     env.Append(CPPDEFINES=[res[1]])
+    ctx.Result(res[0])
+    return res[0]
+
+def CheckPetscMpich(ctx):
+    src="""
+#include<mpi.h>
+#include<petsc.h>
+int main(int argc, char** argv) {
+MPI_Init(&argc, &argv);
+PetscInitialize(&argc, &argv, NULL, NULL);
+PetscFinalize();
+MPI_Finalize();
+}
+"""
+    ctx.Message('Checking that PETSc and MPI are compatible ...')
+    res = ctx.TryRun(src, '.c')
     ctx.Result(res[0])
     return res[0]
 
@@ -132,404 +148,298 @@ def petsc_check_state(state):
     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.
-    env['PACKAGES'] = {}
+# Create all the packages we need so their options will already be in the
+# option database.
+#
+
+opts = Options('config.cache')
+env['PACKAGES'] = {}
+
+mpich = env.Package('MPICH', env)
+mpich.pkg_dirs = ['mpich*', 'MPICH*']
+mpich.hdr_sub_dirs = ['', 'mpi']
+mpich.lib_sub_dirs = ['', 'shared']
+mpich.hdrs = ['mpi.h']
+mpich.libs = ['mpich',
+              ('mpich', 'pmpich'),
+              ('mpich', 'rt'),
+              ('mpich', 'pmpich', 'rt'),
+              'mpi']
+mpich.require_shared = True
+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();'
+mpich.add_options(opts)
+
+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.require_shared = True
+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
+petsc.func_src = """PetscInitialize(&argc, &argv, NULL, NULL);
+PetscFinalize();"""
+petsc.add_options(opts)
+
+petscext = env.Package('PETScExt', env)
+petscext.pkg_dirs = ['petscext*', 'PETScExt*', 'PETSCEXT*']
+state = env['PACKAGES'].get('PETSc', None)
+if state:
+    petscext.lib_sub_dirs = ['', state.arch]
+petscext.hdrs = ['petscext.h']
+petscext.libs = [('petscext_vec', 'petscext_mat',
+                  'petscext_ksp', 'petscext_pc',
+                  'petscext_snes', 'petscext_utils')]
+petscext.use_rpath = True
+petscext.require_shared = True
+petscext.func_src = """PetscInitialize(&argc, &argv, NULL, NULL);
+PetscFinalize();"""
+
+libxml = env.Package('libXML2', env)
+libxml.pkg_dirs = ['libxml2', 'libXML2']
+libxml.hdr_sub_dirs = ['libxml2']
+libxml.hdrs = ['libxml/xmlIO.h']
+libxml.libs = ['libxml2']
+libxml.add_options(opts)
+
+lapack = env.Package('blaslapack', env)
+lapack.libs = [('blas', 'lapack'),
+               'lapack',
+               'mkl']
+lapack.frameworks = ['Accelerate']
+lapack.add_options(opts)
+
+ogl = env.Package('OpenGL', env)
+ogl.hdr_sub_dirs = ['GL']
+ogl.hdrs = ['gl.h', 'glu.h']
+ogl.libs = [('GL', 'GLU')]
+ogl.frameworks = ['OpenGL']
+ogl.framework_hdr_prefix = 'OpenGL'
+ogl.add_options(opts)
+
+mesa = env.Package('OSMesa', env)
+mesa.libs = ['OSMesa']
+mesa.add_options(opts)
+
+sdl = env.Package('SDL', env)
+sdl.hdrs = ['SDL/SDL.h']
+sdl.libs = ['SDL']
+sdl.frameworks = ['SDL', 'Cocoa']
+sdl.add_options(opts)
+
+png = env.Package('libPNG', env)
+png.hdrs = ['png.h']
+png.libs = ['png']
+png.add_options(opts)
+
+jpeg = env.Package('libJPEG', env)
+jpeg.hdrs = ['jpeglib.h']
+jpeg.libs = ['jpeg']
+jpeg.add_options(opts)
+
+tiff = env.Package('libTIFF', env)
+tiff.hdrs = ['tiff.h']
+tiff.libs = ['tiff']
+tiff.add_options(opts)
+
+fame = env.Package('libFAME', env)
+fame.hdrs = ['fame.h']
+fame.libs = ['fame']
+fame.add_options(opts)
+
+avc = env.Package('libavcodec', env)
+avc.hdrs = ['ffmpeg/avcodec.h']
+avc.libs = ['avcodec']
+avc.add_options(opts)
+
+hdf = env.Package('HDF5', env)
+hdf.hdrs = ['hdf5.h']
+hdf.libs = ['hdf5']
+avc.add_options(opts)
+
+# 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')
+    )
+
+opts.Update(env)
+opts.Save('config.cache', env)
+
+#
+# Okay, now actually perform the configuration.
+#
+
+if not 'help' in COMMAND_LINE_TARGETS:
+    cfg = Configure(env,
+                    custom_tests={'CheckPackage': env.CheckPackage,
+                                  'CheckFortranSymbol': CheckFortranSymbol,
+                                  'CheckPetscMpich': CheckPetscMpich})
 
     # 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
-
-    #
+    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
+
     # Need to modify building shared libraries when on Mac OS X.
-    #
-
     if platform.system() == 'Darwin':
-	env.AppendUnique(SHLINKFLAGS=['-flat_namespace', '-single_module', '-undefined', 'suppress'])
-
-    #
+        env.AppendUnique(SHLINKFLAGS=['-flat_namespace',
+                                      '-single_module',
+                                      '-undefined', 'suppress'])
+
+        # And fix RPATHs.
+        import SCons.Util
+        env['LINKFLAGS'] = SCons.Util.CLVar('')
+        env['RPATHPREFIX'] = ''
+        env['RPATHSUFFIX'] = ''
+        env['_RPATH'] = ''
+
     # 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()
-
-    #
+    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.hdr_sub_dirs = ['', 'mpi']
-    mpich.lib_sub_dirs = ['', 'shared']
-    mpich.hdrs = ['mpi.h']
-    mpich.libs = ['mpich',
-                  ('mpich', 'pmpich'),
-                  ('mpich', 'rt'),
-                  ('mpich', 'pmpich', 'rt'),
-                  'mpi']
-    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):
-            mpich.print_opts_help()
-            env.Exit()
-        opts.Save('config.cache', env)
+    if not cfg.CheckPackage(mpich):
+        mpich.print_opts_help()
+        env.Exit()
+
+    # Check for an implementation of PETSc.
+    if not cfg.CheckPackage(petsc):
+        petsc.print_opts_help()
+        env.Exit()
+    env.Append(CPPDEFINES=['HAVE_PETSC'])
+
+    # Check for an implementation of PETScExt.
+    if not cfg.CheckPackage(petscext):
+        petscext.print_opts_help()
+        env.Exit()
+    env.Append(CPPDEFINES=['HAVE_PETSCEXT'])
+
+    # Make sure both PETSc and MPICH are compatible.
+    if not cfg.CheckPetscMpich():
+        print '   Selected versions of MPI and PETSc are incompatible,'
+        print '   please choose another combination.\n'
+        env.Exit()
+
+    # Check for libXML2.
+    if not cfg.CheckPackage(libxml):
+        libxml.print_opts_help()
+        env.Exit()
+
+    # Check for an implementation of lapack and blas.
+    if not cfg.CheckPackage(lapack):
+        lapack.print_opts_help()
+        env.Exit()
+
+    # Setup OpenGL.
+    if not cfg.CheckPackage(ogl):
+        ogl.print_opts_help()
+        env.Exit()
+    env.Append(CPPDEFINES=['HAVE_GL'])
+
+    # Setup Mesa.
+    if not cfg.CheckPackage(mesa):
+        print "   Couldn't find OSMesa - off screen rendering disabled\n"
     else:
-        mpich.add_options(opts)
-
-    #
-    # Check for libXML2.
-    #
-
-    libxml = env.Package('libXML2', env)
-    libxml.pkg_dirs = ['libxml2', 'libXML2']
-    libxml.hdr_sub_dirs = ['libxml2']
-    libxml.hdrs = ['libxml/xmlIO.h']
-    libxml.libs = ['libxml2']
-
-    if not build_opts:
-        if not cfg.CheckPackage(libxml):
-            libxml.print_opts_help()
-            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):
-            lapack.print_opts_help()
-            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):
-            petsc.print_opts_help()
-            env.Exit()
-        env.Append(CPPDEFINES='HAVE_PETSC')
-        opts.Save('config.cache', env)
-    else:
-        petsc.add_options(opts)
-
-    #
-    # Check for Mayhem's PETSc extensions.
-    #
-
-    petsc = env.Package('PETScExt', env)
-    petsc.pkg_dirs = ['petscext*', 'PETScExt*', 'PETSCEXT*']
-    state = env['PACKAGES'].get('PETSc', None)
-    if state:
-        petsc.lib_sub_dirs = ['', state.arch]
-    petsc.hdrs = ['petscext.h']
-    petsc.libs = [('petscext_vec', 'petscext_mat',
-                   'petscext_ksp', 'petscext_pc',
-                   'petscext_snes', 'petscext_utils')]
-    petsc.use_rpath = True
-
-    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_dirs = ['GL']
-    ogl.hdrs = ['gl.h', 'glu.h']
-    ogl.libs = [('GL', 'GLU')]
-    ogl.frameworks = ['OpenGL']
-    ogl.framework_hdr_prefix = 'OpenGL'
-
-    if not build_opts:
-        if not cfg.CheckPackage(ogl):
-            ogl.print_opts_help()
-            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)
-
-    #
+        env.Append(CPPDEFINES=['HAVE_MESA'])
+
     # 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)
-
-    #
+    if cfg.CheckPackage(sdl):
+        env.Append(CPPDEFINES=['HAVE_SDL'])
+
     # 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)
-
-    #
+    if cfg.CheckPackage(png):
+        env.Append(CPPDEFINES=['HAVE_PNG'])
+
+    if cfg.CheckPackage(jpeg):
+        env.Append(CPPDEFINES=['HAVE_JPEG'])
+
+    if cfg.CheckPackage(tiff):
+        env.Append(CPPDEFINES=['HAVE_TIFF'])
+
     # 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)
-
-    #
+    if cfg.CheckPackage(fame):
+        env.Append(CPPDEFINES=['HAVE_FAME'])
+
     # 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)
-
-    #
+    if cfg.CheckPackage(avc):
+        env.Append(CPPDEFINES=['HAVE_AVCODEC'])
+
     # Setup HDF5.
-    #
-
-    hdf = env.Package('HDF5', env)
-    hdf.hdrs = ['hdf5.h']
-    hdf.libs = ['hdf5']
-
-    if not build_opts:
-        if not cfg.CheckPackage(hdf):
-            hdf.print_opts_help()
-            env.Exit()
-        env.Append(CPPDEFINES='HAVE_HDF5')
-        opts.Save('config.cache', env)
-    else:
-        hdf.add_options(opts)
-
-    #
+    if cfg.CheckPackage(hdf):
+        env.Append(CPPDEFINES=['HAVE_HDF5'])
+
     # Check Fortran symbol type.
-    #
-
-    if not build_opts:
-        if not cfg.CheckFortranSymbol():
-            print '   Failed to compile and run a simple fortran program,'
-            print "   please check 'config.log' for the cause of the error."
-            env.Exit()
-
-    #
+    if not cfg.CheckFortranSymbol():
+        print '   Failed to compile and run a simple fortran program,'
+        print "   please check 'config.log' for the cause of the error."
+        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()
-
-    #
+    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)])
-
-    #
+    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)])
-
-    #
+    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')])
+    env.Append(RPATH=[os.path.join(Dir('.').abspath, 'build', 'lib')])
 
     # Finish the configuration.
-    if not build_opts:
-        env = cfg.Finish()
-
-
-"""
-        # Check that there isn't a conflict in PETSc's MPICH.
-        petsc_state = env['PACKAGES']['PETSc']
-        mpich_state = env['PACKAGES']['MPICH']
-        libs = petsc_get_libs(petsc_state.base_dir, petsc_state.arch, 'MPI')
-        okay = True
-        for l in libs[0]:
-            if l not in mpich.lib_dirs:
-                okay = False
-                break
-        if okay:
-            for l in libs[1]:
-                if l not in mpich.libs:
-                    okay = False
-                    break
-        if okay:
-            mpi_inc_dir = petsc_get_opt(petsc_state.base_dir,
-                                         petsc_state.arch,
-                                         'MPI_INCLUDE')
-            if mpi_inc_dir:
-                mpi_inc_dir = [d[len(env['INCPREFIX']):] \
-                                   for d in mpi_inc_dir.split(' ')]
-                state_hdr_dirs = [os.path.realpath(h) for h in state.hdr_dirs]
-                for dir in mpi_inc_dir:
-                    if os.path.realpath(dir) not in state_hdr_dirs:
-                        okay = False
-                        break
-        if not okay and not env['ignorePetscMpichConflict']:
-            print '   Error: PETSc is using a different MPI implementation'
-            print '          than the located version...'
-            print ''
-            if mpi_inc_dir:
-                print '      PETSc: Header paths: %s' % str(mpi_inc_dir)
-            if libs[0]:
-                print '      PETSc: Lib paths: %s' % str(libs[0])
-            if libs[1]:
-                print '      PETSc: Libs: %s' % str(libs[1])
-            print '\n',
-            print mpich_state.text('      MPICH: ')
-            print '\n',
-            print '   If you are sure this is okay, override this error'
-            print '   with \'ignorePetscMpichConflict\''
-            print '\n',
-            env.Exit()
-
-        elif not okay:
-            print '   Warning: PETSc is using a different MPI implementation'
-            print '            than the located version...\n'
-"""
+    env = cfg.Finish()
+
+opts.Update(env)
+opts.Save('config.cache', env)
+
+if 'config' in COMMAND_LINE_TARGETS:
+    print "\nWriting out 'config.state' ... ",
+    env.dump_cfg('config.state',
+                 opts.keys() + ['CPPPATH', 'CPPDEFINES',
+                                'LIBPATH', 'LIBS', 'RPATH',
+                                'FRAMEWORKS'])
+    print 'done\n'
+    print '*************************************'
+    print "* Run 'scons' to build the project. *"
+    print '*************************************\n'
+
+if 'help' in COMMAND_LINE_TARGETS:
+    print opts.GenerateHelpText(env)
diff -r 988d32ff5aa4 -r cff250571157 SConsUtils
--- a/SConsUtils	Tue Feb 12 04:41:40 2008 +0000
+++ b/SConsUtils	Thu Feb 14 23:33:46 2008 +0000
@@ -1,4 +1,4 @@ import os, glob as pyglob, platform
-import os, glob as pyglob, platform
+import os, glob as pyglob, platform, pickle
 from SCons.Script.SConscript import SConsEnvironment
 Import('env')
 
@@ -40,13 +40,16 @@ def copy_file(env, dst, src):
         os.chdir(old)
 
 # Temporarily replace some paths.
-def push_state(env, state):
+def push_state(env, state, append=False):
     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)
+        old[k] = env.get(k, None)
+    if append:
+        env.AppendUnique(**copy)
+    else:
+        env.PrependUnique(**copy)
     return old
 
 # Replace old paths.
@@ -59,6 +62,37 @@ SConsEnvironment.copy_file = copy_file
 SConsEnvironment.copy_file = copy_file
 SConsEnvironment.push_state = push_state
 SConsEnvironment.pop_state = pop_state
+
+#
+# Setup some utilities for dumping configurations.
+#
+
+# Dump a set of environment variables.
+def dump_cfg(env, filename, vars):
+    d = {}
+    for a in vars:
+        if a in env._dict:
+            d[a] = env[a]
+    f = file(filename, 'w')
+    pickle.dump(d, f)
+    f.close()
+
+# Load a configuration dump.
+def load_cfg(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')
+    d = pickle.load(f)
+    f.close()
+    for k, v in d.iteritems():
+        env[k] = v
+
+SConsEnvironment.dump_cfg = dump_cfg
+SConsEnvironment.load_cfg = load_cfg
 
 #
 # Setup the hierarchical build stuff.
@@ -112,14 +146,13 @@ class PackageState(object):
         self.state = {}
         self.old = None
 
-    def setup(self, env):
-        self.build_state()
+    def enable(self, env):
         if self.old != None:
             print 'Error'
             env.Exit()
         self.old = env.push_state(self.state)
 
-    def teardown(self, env):
+    def disable(self, env):
         env.pop_state(self.old)
         self.old = None
 
@@ -210,6 +243,9 @@ return 0;
 
         # Set this flag if RPATH's are needed for this package.
         self.use_rpath = False
+
+        # Set to force presence of shared libs.
+        self.require_shared = False
 
         # Use this member to specify a callback function for
         # customising search states.
@@ -477,17 +513,75 @@ return 0;
 
         # Begin trialing states.
         for s in self.states:
-            s.setup(ctx.env)
+            s.build_state()
             yield s
-            s.teardown(ctx.env)
 
     def check(self, ctx, state):
         hdr_src = self.string_hdrs(state)
         ver_src = self.string_ver()
         src = self.check_src % (hdr_src, ver_src, self.func_src)
 
-        env = ctx.env
+        state.enable(ctx.env)
         res = ctx.TryRun(src, '.c')
+        state.disable(ctx.env)
+        if not res:
+            return res
+
+        if self.require_shared:
+            res = self.check_shared(ctx, state)
+        return res
+
+    def check_shared(self, ctx, state):
+        lib_src = """
+%s
+void _dummy_func(int argc, char** argv) {
+%s
+}
+"""
+        main_src="""
+void _dummy_func(int argc, char** argv);
+int main(int argc, char** argv) {
+_dummy_func(argc, argv);
+return 0;
+}
+"""
+
+        # Must have a function to call from the library.
+        if not self.func_src:
+            print '\n'
+            print '   Error: need a function from the library to call in order'
+            print '      to check for shared libraries.\n'
+            env.Exit()
+
+        # Create the shared object.
+        hdr_src = self.string_hdrs(state)
+        state.enable(ctx.env)
+        res = ctx.TryBuild(env.SharedObject,
+                           lib_src % (hdr_src, self.func_src),
+                           '*.c')
+        state.disable(ctx.env)
+        if not res:
+            return (res, '')
+
+        # Create the shared library.
+        lib_obj = ctx.lastTarget
+        old = env.push_state({'LIBS': [lib_obj]})
+        res = ctx.TryBuild(env.SharedLibrary, '', '*.c')
+        env.pop_state(old)
+        if not res:
+            return (res, '')
+        lib = ctx.lastTarget
+
+        # Build the program and try to run, but make sure the symbols are
+        # passed to the linker out of order.
+        state.enable(env)
+        old = env.push_state({'LIBS': [lib]}, append=True)
+        res = ctx.TryRun(main_src, '*.c')
+        env.pop_state(old)
+        state.disable(env)
+        if not res[0]:
+            res = (res[0], 'no shared libraries available')
+
         return res
 
     def string_hdrs(self, state):
@@ -554,6 +648,19 @@ self.env_opts."""
         print '   Was unable to locate a working version of package:'
         print '      %s\n' % self.name
         print "   Please check 'config.log' for the cause of the failure.\n"
+
+        if len(self.opts):
+            print '   The following options were used:'
+            for k, v in self.opts.iteritems():
+                if self.cmd_opts[k] in env._dict:
+                    print '      %s: ' % self.cmd_opts[k],
+                    print '%s' % env[self.cmd_opts[k]]
+                else:
+                    print '      %s: ' % self.env_opts[k],
+                    print '%s' % env['ENV'][self.env_opts[k]]
+            print ''
+            return
+
         if len(self.cmd_opts):
             print '   You could try specifying any of the following command'
             print '   line options:'
@@ -571,7 +678,7 @@ self.env_opts."""
                 print '      %s' % e
             print ''
         if len(self.cmd_opts) or len(self.env_opts):
-            print "   Please run 'scons -h' to see more details on using"
+            print "   Please run 'scons help' to see more details on using"
             print '   these options.\n'
 
 def CheckPackage(ctx, pkg):
@@ -601,6 +708,7 @@ def CheckPackage(ctx, pkg):
             ctx.Display(state.text(prefix='   '))
             ctx.Display('\n')
             env['PACKAGES'][pkg.name] = state
+            state.enable(env)
             return 1
 
         # No.
diff -r 988d32ff5aa4 -r cff250571157 SConstruct
--- a/SConstruct	Tue Feb 12 04:41:40 2008 +0000
+++ b/SConstruct	Thu Feb 14 23:33:46 2008 +0000
@@ -14,103 +14,58 @@ env = Environment(ENV=os.environ)
 # these things we need).
 SConscript('SConsUtils', exports='env')
 
-#
-# Setup our option database.
-#
+# Are we configuring or building?
+if ('config' in COMMAND_LINE_TARGETS or 'help' in COMMAND_LINE_TARGETS) \
+        and not env.GetOption('clean'):
+    SConscript('SConfigure', exports='env')
+    env.Alias('config', '.')
+    env.Alias('help', '.')
 
-# Create the options object.
-opts = Options('config.cache')
+else:
+    # Setup all our StGermain specific utilities.
+    SConscript('StgSCons', exports='env')
 
-# 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
+    # Load the configuration.
+    env.load_cfg('config.state')
 
-# 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'),
-    BoolOption('ignorePetscMpichConflict',
-               'Allow PETSc to use a different MPICH implementation',
-               0)
-    )
+    # Add any variables that get used throughout the whole build.
+    if env['debug']:
+        env.Append(CCFLAGS='-g')
+    env.Prepend(CPPPATH=['#build/include'])
+    env.Prepend(LIBPATH=['#build/lib'])
 
-#
-# Fill in our substitution environment with useful things.
-#
+    # Setup any additional build targets.
+    env.Alias('install', env['prefix'])
 
-opts.Update(env)
-opts.Save('config.cache', env)
+    #
+    # Call target SConscripts.
+    #
 
-# BEGIN MAC HACK FIX
-import SCons.Util
-env['LINKFLAGS'] = SCons.Util.CLVar('')
-env['RPATHPREFIX'] = ''
-env['RPATHSUFFIX'] = ''
-env['_RPATH'] = ''
-# END MAC HACK FIX
+    env.BuildDir('build', '.', duplicate=0)
 
-# Generate some help text at this point.
-env.Help(opts.GenerateHelpText(env))
+    env.clear_all()
+    SConscript('build/StGermain/SConscript', exports='env')
+    env.Prepend(LIBS=['StGermain'])
 
-# 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['CPPFLAGS'] = env['CPPFLAGS'] if 'CPPFLAGS' 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 []
+    env.clear_all()
+    SConscript('build/StgDomain/SConscript', exports='env')
+    env.Prepend(LIBS=['StgDomain'])
 
-# Setup all our StGermain specific utilities.
-SConscript('StgSCons', exports='env')
+    env.clear_all()
+    SConscript('build/StgFEM/SConscript', exports='env')
+    env.Prepend(LIBS=['StgFEM'])
 
-# Configure the environment.
-build_opts = False
-SConscript('SConfigure', exports='env opts build_opts')
+    env.clear_all()
+    SConscript('build/PICellerator/SConscript', exports='env')
+    env.Prepend(LIBS=['PICellerator'])
 
-# Add any variables that get used throughout the whole build.
-if env['debug']:
-    env.Append(CCFLAGS='-g')
-env.Prepend(CPPPATH=['#build/include'])
-env.Prepend(LIBPATH=['#build/lib'])
+    env.clear_all()
+    SConscript('build/Underworld/SConscript', exports='env')
+    env.Prepend(LIBS=['Underworld'])
 
-# Setup any additional build targets.
-env.Alias('install', env['prefix'])
+    env.clear_all()
+    SConscript('build/Magma/SConscript', exports='env')
+    env.Prepend(LIBS=['Magma'])
 
-#
-# Call target SConscripts.
-#
-
-env.BuildDir('build', '.', duplicate=0)
-
-env.clear_all()
-SConscript('build/StGermain/SConscript', exports='env')
-env.Append(LIBS=['StGermain'])
-
-env.clear_all()
-SConscript('build/StgDomain/SConscript', exports='env')
-env.Append(LIBS=['StgDomain'])
-
-env.clear_all()
-SConscript('build/StgFEM/SConscript', exports='env')
-env.Append(LIBS=['StgFEM'])
-
-env.clear_all()
-SConscript('build/PICellerator/SConscript', exports='env')
-env.Append(LIBS=['PICellerator'])
-
-env.clear_all()
-SConscript('build/Underworld/SConscript', exports='env')
-env.Append(LIBS=['Underworld'])
-
-env.clear_all()
-SConscript('build/Magma/SConscript', exports='env')
-env.Append(LIBS=['Magma'])
-
-env.clear_all()
-SConscript('build/gLucifer/SConscript', exports='env')
+    env.clear_all()
+    SConscript('build/gLucifer/SConscript', exports='env')



More information about the CIG-COMMITS mailing list