[cig-commits] commit:

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


changeset:   26:6f4ec87b4472
user:        LukeHodkinson
date:        Wed Feb 06 00:40:32 2008 +0000
files:       SConfigure SConscript StgSCons
description:
Adding a SConscript for target specification local
to StgDomain.


diff -r bdb6d1414317 -r 6f4ec87b4472 SConfigure
--- a/SConfigure	Wed Jan 30 07:02:40 2008 +0000
+++ b/SConfigure	Wed Feb 06 00:40:32 2008 +0000
@@ -6,9 +6,11 @@ Import('env opts')
 #
 
 def push_paths(cpp=[], lib=[]):
-    cpp = [cpp] if isinstance(cpp, str) else cpp
-    lib = [lib] if isinstance(lib, str) else lib
-    old = [env['CPPPATH'], env['LIBPATH']]
+    cpp = [cpp] if not isinstance(cpp, list) else cpp
+    cpp = [p for p in cpp if p is not None]
+    lib = [lib] if not isinstance(lib, list) else lib
+    lib = [p for p in lib if p is not None]
+    old = [list(env['CPPPATH']), list(env['LIBPATH'])]
     env.AppendUnique(CPPPATH=cpp)
     env.AppendUnique(LIBPATH=lib)
     return old
@@ -50,7 +52,7 @@ def CheckPackage(ctx, name, check, state
     # If options given, use that. If fails then fatal.
     for state in state_gen('options'):
         old = push_paths(state[0], state[1])
-        for libs in lib_gen():
+        for libs in lib_gen(state):
             libs = [libs] if isinstance(libs, str) else libs
             res = check(ctx, libs, state[1])
             if res:
@@ -74,7 +76,7 @@ def CheckPackage(ctx, name, check, state
     # Try and extract package location from shell environment.
     for state in state_gen('environment'):
         old = push_paths(state[0], state[1])
-        for libs in lib_gen():
+        for libs in lib_gen(state):
             libs = [libs] if isinstance(libs, str) else libs
             res = check(ctx, libs, state[1])
             if res:
@@ -88,7 +90,7 @@ def CheckPackage(ctx, name, check, state
     # Cycle through default locations.
     for state in state_gen('default'):
         old = push_paths(state[0], state[1])
-        for libs in lib_gen():
+        for libs in lib_gen(state):
             libs = [libs] if isinstance(libs, str) else libs
             res = check(ctx, libs, state[1])
             if res:
@@ -166,7 +168,7 @@ def mpich_state_gen(type):
         yield ('/usr/include/mpich', '/usr/lib')
         yield ('/usr/local/mpich/include', '/usr/local/mpich/lib')
 
-def mpich_lib_gen():
+def mpich_lib_gen(state=None):
     yield ['mpich']
     yield ['pmpich']
     yield ['mpich', 'pmpich']
@@ -183,7 +185,7 @@ return (MPI_VERSION == 2) ? 0 : 1;
 return (MPI_VERSION == 2) ? 0 : 1;
 }
 """
-    old = env['LIBS'], env['RPATH']
+    old = list(env['LIBS']), list(env['RPATH'])
     env.Append(LIBS=libs)
     env.Append(RPATH=libpath)
     res = ctx.TryRun(src, '.c')[0]
@@ -217,7 +219,7 @@ def libxml2_state_gen(type):
         yield ('/usr/include/libxml2', '/usr/lib')
         yield ('/usr/local/libxml2/include', '/usr/local/libxml2/lib')
 
-def libxml2_lib_gen():
+def libxml2_lib_gen(state=None):
     yield ['libxml2']
 
 def check_libxml2(ctx, libs, libpath=None):
@@ -227,8 +229,8 @@ return 0;
 return 0;
 }
 """
-    old = env['LIBS']
-    env.Append(LIBS=libs)
+    old = list(env['LIBS'])
+    env.Replace(LIBS=libs)
     res = ctx.TryLink(src, '.c')
     env.Replace(LIBS=old)
     if not res:
@@ -257,7 +259,7 @@ def stgermain_state_gen(type):
     elif type == 'default':
         yield ('../StGermain/build/include', '../StGermain/build/lib')
 
-def stgermain_lib_gen():
+def stgermain_lib_gen(state=None):
     yield ['StGermain']
 
 def check_stgermain(ctx, libs, libpath=None):
@@ -269,7 +271,48 @@ return 0;
 return 0;
 }
 """
-    old = env['LIBS']
+    old = list(env['LIBS'])
+    env.Replace(LIBS=libs)
+    res = ctx.TryLink(src, '.c')
+    env.Replace(LIBS=old)
+    if not res:
+        return res
+
+    env.AppendUnique(LIBS=libs)
+    return res
+
+## StgDomain ##
+
+def stgdomain_state_gen(type):
+    if type == 'options':
+        if 'stgdomainDir' in env._dict:
+            yield (os.path.join(env['stgdomainDir'], 'include'),
+                   os.path.join(env['stgdomainDir'], 'lib'))
+        elif 'stgdomainLibDir' in env._dict or 'stgdomainIncDir' in env._dict:
+            inc = env['stgdomainIncDir'] \
+                if 'stgdomainIncDir' in env._dict else None
+            lib = env['stgdomainLibDir'] \
+                if 'stgdomainLibDir' in env._dict else None
+            yield (inc, lib)
+    elif type == 'environment':
+        if 'STGDOMAIN_DIR' in env['ENV']:
+            yield (os.path.join(env['ENV']['STGDOMAIN_DIR'], 'include'),
+                   os.path.join(env['ENV']['STGDOMAIN_DIR'], 'lib'))
+    elif type == 'default':
+        yield ('../StgDomain/build/include', '../StgDomain/build/lib')
+
+def stgdomain_lib_gen(state=None):
+    yield ['StgDomain']
+
+def check_stgdomain(ctx, libs, libpath=None):
+    src = """
+#include<StGermain/StGermain.h>
+#include<StgDomain/StgDomain.h>
+int main(int argc, char** argv) {
+return 0;
+}
+"""
+    old = list(env['LIBS'])
     env.Append(LIBS=libs)
     res = ctx.TryLink(src, '.c')
     env.Replace(LIBS=old)
@@ -295,17 +338,17 @@ def lapack_state_gen(type):
     elif type == 'default':
         yield (None, '/usr/lib')
 
-def lapack_lib_gen():
+def lapack_lib_gen(state=None):
     yield ['lapack']
 
-def check_lapack(ctx, libs):
+def check_lapack(ctx, libs, libpath=None):
     src = """
 int main(int argc, char** argv) {
 return 0;
 }
 """
-    old = env['LIBS']
-    env.Append(LIBS=libs)
+    old = list(env['LIBS'])
+    env.Replace(LIBS=libs)
     res = ctx.TryLink(src, '.c')
     env.Replace(LIBS=old)
     if not res:
@@ -314,16 +357,110 @@ return 0;
     env.AppendUnique(LIBS=libs)
     return res
 
+## PETSc ##
+
+def petsc_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_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 = []
+    for l in f.readlines():
+        if l[:7] == 'X11_LIB':
+            libs = l.split('=')[1].strip().split(' ')
+            libs = [lib[2:] for lib in libs]
+            break
+    f.close()
+    return libs
+
+def petsc_state_gen(type):
+    if type == 'options':
+        if 'petscDir' in env._dict:
+            arch = petsc_arch(env['petscDir'])
+            if arch:
+                yield ([os.path.join(env['petscDir'], 'include'),
+                        os.path.join(env['petscDir'], 'bmake', arch)],
+                       os.path.join(env['petscDir'], 'lib', arch),
+                       env['petscDir'],
+                       arch)
+    elif type == 'environment':
+        if 'PETSC_DIR' in env['ENV']:
+            dir = env['ENV']['PETSC_DIR']
+            if 'PETSC_ARCH' in env['ENV']:
+                arch = env['ENV']['PETSC_ARCH']
+            else:
+                arch = petsc_arch(dir)
+            if arch:
+                yield ([os.path.join(dir, 'include'),
+                        os.path.join(dir, 'bmake', arch)],
+                       os.path.join(dir, 'lib', arch),
+                       dir,
+                       arch)
+    elif type == 'default':
+        dir = '/usr/local/petsc'
+        arch = petsc_arch(dir)
+        if arch:
+            yield ([os.path.join(dir, 'include'),
+                    os.path.join(dir, 'bmake', arch)],
+                   os.path.join(dir, 'lib', arch),
+                   dir,
+                   arch)
+
+def petsc_lib_gen(state=None):
+    if state:
+        libs = petsc_x11_libs(state[2], state[3])
+    else:
+        libs = []
+    yield ['petsc', 'petscvec', 'petscmat', 'petscksp',
+           'petscsnes', 'petscdm'] + libs
+
+def check_petsc(ctx, libs, libpath=None):
+    src = """
+#include <petsc.h>
+#include <petscvec.h>
+#include <petscmat.h>
+#include <petscksp.h>
+int main(int argc, char** argv) {
+/*PetscInitialize();*/
+/*PetscFinalise();*/
+if( (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR < 3) ||
+    (PETSC_VERSION_MAJOR != 2) )
+printf("wrong version, need at least 2.3.2");
+return 0;
+}
+"""
+    old = list(env['LIBS']), list(env['RPATH'])
+    env.Append(LIBS=libs)
+    env.Append(RPATH=libpath)
+    res = ctx.TryRun(src, '.c')
+    env.Replace(LIBS=old[0])
+    env.Replace(RPATH=old[1])
+    if not res[0] or res[1] != '':
+        ctx.Log('  ! Output: ' + res[1] + '\n')
+        return 0
+
+    env.AppendUnique(LIBS=libs)
+    return res[0]
+
 #
 # Do configuration.
 #
 
 if not env.GetOption('clean'):
     cfg = Configure(env,
-                    custom_tests={'CheckFortranSymbol':
-                                      CheckFortranSymbol,
-                                  'CheckPackage':
-                                      CheckPackage})
+                    custom_tests={'CheckPackage':
+                                      CheckPackage,
+                                  'CheckFortranSymbol':
+                                      CheckFortranSymbol})
 
     # Add a member to 'env' for storing package results.
     env['PACKAGES'] = {}
@@ -364,11 +501,30 @@ if not env.GetOption('clean'):
     opts.Save('config.cache', env)
 
     #
+    # Check for an implementation of PETSc
+    #
+
+    if not cfg.CheckPackage('PETSc', check_petsc,
+                            petsc_state_gen, petsc_lib_gen):
+        env.Exit()
+    env.Append(CPPDEFINES='HAVE_PETSC')
+    opts.Save('config.cache', env)
+
+    #
     # Check for StGermain.
     #
 
     if not cfg.CheckPackage('StGermain', check_stgermain,
                             stgermain_state_gen, stgermain_lib_gen):
+        env.Exit()
+    opts.Save('config.cache', env)
+
+    #
+    # Check for StgDomain.
+    #
+
+    if not cfg.CheckPackage('StgDomain', check_stgdomain,
+                            stgdomain_state_gen, stgdomain_lib_gen):
         env.Exit()
     opts.Save('config.cache', env)
 
diff -r bdb6d1414317 -r 6f4ec87b4472 SConscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SConscript	Wed Feb 06 00:40:32 2008 +0000
@@ -0,0 +1,33 @@
+Import('env')
+
+# Need to copy the environment for use here.
+env = env.Copy()
+
+# Add some extra stuff.
+env.proj = 'StgDomain'
+env.Append(CPPPATH=['#build/include/' + env.proj])
+
+#
+# Target specification section.
+#
+
+env.build_directory('Geometry')
+env.build_directory('Shape')
+env.build_directory('Mesh')
+env.build_directory('Utils')
+env.build_directory('Swarm')
+
+env.build_headers(env.glob('libStgDomain/src/*.h'), 'StgDomain')
+env.build_objects(env.glob('libStgDomain/src/*.c'), 'libStgDomain')
+env.build_objects(env.glob('libStgDomain/Toolbox/*.c'), 'Toolbox')
+env.build_metadata(env.glob('libStgDomain/src/*.meta'), 'libStgDomain')
+env.build_metadata(env.glob('libStgDomain/Toolbox/*.meta'), 'Toolbox')
+
+env.build_library(env.get_hnodes(env.SharedObject), 'StgDomain')
+
+env.build_library(env.get_hnodes(env.SharedObject, 'Toolbox'),
+                  'StgDomain_Toolboxmodule',
+                  True)
+
+env.build_tests(env.glob('libStgDomain/tests/test*.c'),
+                'StgDomain', libs='StgDomain')
diff -r bdb6d1414317 -r 6f4ec87b4472 StgSCons
--- a/StgSCons	Wed Jan 30 07:02:40 2008 +0000
+++ b/StgSCons	Wed Feb 06 00:40:32 2008 +0000
@@ -1,4 +1,4 @@ import os, glob
-import os, glob
+import os
 Import('env')
 
 # Setup a few global variables.
@@ -32,22 +32,19 @@ def find_objs(hpath):
         nodes = nodes[h]
     return nodes['.']
 
-def copy_file(dst, src):
-    if env.GetOption(['clean']):
-        return
-    dstDir = os.path.dirname(dst)
-    if not os.path.exists(dstDir):
-        Execute(Mkdir(dstDir))
-    Execute(Copy(dst, src))
-
 def copy_includes(files, dst, inc_nodes, force=False):
     files = files if isinstance(files, list) else [files]
-    dst = os.path.join('build', 'include', dst)
+    dst = os.path.join('#build', 'include', dst)
     for i in files:
-        cur_node = env.Install(dst, os.path.join('build', i))
-        inc_nodes.append(cur_node)
-        if force and not File(cur_node[0].path).current():
-            copy_file(cur_node[0].path, i)
+        node = env.Install(dst, i)
+        inc_nodes.append(node)
+        dst_path = os.path.join(dst, os.path.basename(i))
+        if force:
+            env.copy_file(dst_path, i)
+
+#
+# Builder helpers.
+#
 
 def build_defines(files, dst):
     copy_includes(files, dst, env.def_nodes, True)
@@ -60,10 +57,9 @@ def build_objects(files, hpath, store=Tr
     nodes = []
     name = env.proj + ''.join(hpath.split(os.path.sep))
     mod = [('CURR_MODULE_NAME', env['ESCAPE']('"' + name + '"'))]
-    for s in files:
-        src = os.path.join('build', s)
+    for src in files:
         cur_node = env.SharedObject(src,
-                                   CPPDEFINES=env['CPPDEFINES'] + mod)
+                                    CPPDEFINES=env['CPPDEFINES'] + mod)
         nodes.append(cur_node)
     if store:
         insert_objs(nodes, hpath)
@@ -73,7 +69,7 @@ def build_metadata(files, hpath):
     files = files if isinstance(files, list) else [files]
     nodes = []
     for m in files:
-        src = env.Meta(os.path.join('build', m))
+        src = env.Meta(m)
         cur_node = env.SharedObject(src)
         nodes.append(cur_node)
     insert_objs(nodes, hpath)
@@ -81,7 +77,7 @@ def build_metadata(files, hpath):
 
 def build_library(objs, name, force_name=False):
     objs = objs if isinstance(objs, list) else [objs]
-    dst = os.path.join('build', 'lib', name)
+    dst = os.path.join('#build', 'lib', name)
     if force_name:
         cur_node = env.LoadableModule(
             dst, objs,
@@ -97,10 +93,9 @@ def build_tests(files, name, sup_objs=[]
     nodes = env.test_nodes
     mod = [('CURR_MODULE_NAME', env['ESCAPE']('"' + name + '"'))]
     l = libs if isinstance(libs, list) else [libs]
-    for s in files:
-        src = os.path.join('build', s)
-        dst = os.path.join('build', 'tests',
-                           os.path.splitext(os.path.basename(s))[0])
+    for src in files:
+        dst = os.path.join('#build', 'tests',
+                           os.path.splitext(os.path.basename(src))[0])
         cur_node = env.Program(dst, [src] + sup_objs,
                                CPPDEFINES=env['CPPDEFINES'] + mod,
                                LIBS=env['LIBS'] + l)
@@ -115,21 +110,31 @@ def build_directory(dir, extra_objs=[], 
     hdrDir = os.path.join(env.proj, dir)
     mod = ''.join(hdrDir.split(os.path.sep))
 
-    build_defines(glob.glob(os.path.join(srcDir, '*.def')), hdrDir)
-    build_headers(glob.glob(os.path.join(srcDir, '*.h')), hdrDir)
-    build_metadata(glob.glob(os.path.join(srcDir, '*.meta')), dir)
-    build_objects(glob.glob(os.path.join(srcDir, '*.c')), dir)
+    build_defines(env.glob(os.path.join(srcDir, '*.def')), hdrDir)
+    build_headers(env.glob(os.path.join(srcDir, '*.h')), hdrDir)
+    build_metadata(env.glob(os.path.join(srcDir, '*.meta')), dir)
+    build_objects(env.glob(os.path.join(srcDir, '*.c')), dir)
     if build_lib:
         objs = find_objs(dir)
         build_library(objs + extra_objs, mod)
     if os.path.exists(tstDir):
-        tst_files = glob.glob(os.path.join(tstDir, 'test*.c'))
-        sup_gen = glob.iglob(os.path.join(tstDir, '*.c'))
+        tst_files = env.glob(os.path.join(tstDir, 'test*.c'))
+        sup_gen = env.glob(os.path.join(tstDir, '*.c'))
         sup_files = [f for f in sup_gen if f not in tst_files]
         sup = build_objects(sup_files, dir, False)
         build_tests(tst_files, mod,
                     sup_objs=sup,
                     libs=test_libs + [mod])
+
+def build_plugin(dir, hpath):
+    name = [env.proj] + hpath.split(os.path.sep)
+    name = '_'.join(name)
+    hdr_dir = os.path.join(env.proj, hpath.split(os.path.sep)[-1])
+
+    build_headers(env.glob(os.path.join(dir, '*.h')), hdr_dir)
+    objs = build_objects(env.glob(os.path.join(dir, '*.c')),
+                         hpath, False)
+    build_library(objs, name, True)
 
 env.build_defines = build_defines
 env.build_headers = build_headers
@@ -138,6 +143,7 @@ env.build_library = build_library
 env.build_library = build_library
 env.build_tests = build_tests
 env.build_directory = build_directory
+env.build_plugin = build_plugin
 
 #
 # Custom builders.



More information about the CIG-COMMITS mailing list