~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to scons/simula-scons/simula_scons/Customize.py

  • Committer: Niclas Jansson
  • Date: 2010-10-17 10:21:52 UTC
  • Revision ID: njansson@csc.kth.se-20101017102152-e6u3c9uwxa4z19c8
Minor fixes in configure.ac

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import SCons.Util, SCons.Scanner
2
 
 
3
 
import os, sys, re
4
 
 
5
 
 
6
 
def darwinCxx(env):
7
 
    """Change the cxx parts of env for the Darwin platform"""
8
 
    env["CXXFLAGS"] += " -undefined dynamic_lookup"
9
 
    env["SHLINKFLAGS"] += " -undefined dynamic_lookup"
10
 
    env["LDMODULEFLAGS"] += " -undefined dynamic_lookup"
11
 
    if not env.GetOption("clean"):
12
 
        # remove /usr/lib if present in LIBPATH.
13
 
        # there should maybe be some testing here to make sure 
14
 
        # it doesn't blow in our face.
15
 
        try:
16
 
            env["LIBPATH"].remove('/usr/lib')
17
 
        except:
18
 
            pass
19
 
    return env
20
 
 
21
 
def darwinSwig(env):
22
 
    """Change the swig parts of env for the Darwin platform"""
23
 
    env['SHLINKFLAGS'] = env['LDMODULEFLAGS']
24
 
    env['SHLINKCOM'] = env['LDMODULECOM']
25
 
    env["SHLIBSUFFIX"] = ".so"
26
 
    return env
27
 
 
28
 
 
29
 
def swigScanner(node, env, path):
30
 
    """SCons scanner hook to scan swig files for dependencies.
31
 
    @return: list of files depended on.
32
 
    """
33
 
    include_pattern = re.compile(r"%include\s+(\S+)")
34
 
 
35
 
    def recurse(path, search_path):
36
 
        """Scan recursively."""
37
 
        f = open(path)
38
 
        try: contents = f.read()
39
 
        finally: f.close()
40
 
 
41
 
        found = []
42
 
        for m in include_pattern.finditer(contents):
43
 
            inc_fpath = m.group(1)
44
 
            # Strip off quotes
45
 
            inc_fpath = inc_fpath.strip("'").strip('"')
46
 
            # Strip off site include marks
47
 
            inc_fpath = inc_fpath.strip('<').strip('>')
48
 
            real_fpath = os.path.realpath(inc_fpath)
49
 
            if os.path.dirname(real_fpath) != os.path.dirname(path):
50
 
                # Not in same directory as original swig file
51
 
                if os.path.isfile(real_fpath):
52
 
                    found.append(real_fpath)
53
 
                    continue
54
 
            
55
 
            # Look for unqualified filename on path
56
 
            for dpath in search_path:
57
 
                abs_path = os.path.join(dpath, inc_fpath)
58
 
                if os.path.isfile(abs_path):
59
 
                    found.append(abs_path)
60
 
                    break
61
 
        
62
 
        for f in [f for f in found if os.path.splitext(f)[1] == ".i"]:
63
 
            found += recurse(f, search_path)
64
 
        return found
65
 
    
66
 
    fpath = node.srcnode().path
67
 
    search_path = [os.path.abspath(d) for d in re.findall(r"-I(\S+)", " ".join(env["SWIGFLAGS"]))]
68
 
    search_path.insert(0, os.path.abspath(os.path.dirname(fpath)))
69
 
    r = recurse(fpath, search_path)
70
 
    return r
71
 
 
72
 
swigscanner = SCons.Scanner.Scanner(function=swigScanner, skeys=[".i"])
73
 
 
74
 
def swigEmitter(target, source, env):
75
 
    for src in source:
76
 
        src = str(src)
77
 
        if "-python" in SCons.Util.CLVar(env.subst("$SWIGFLAGS")):
78
 
            target.append(os.path.splitext(src)[0] + ".py")
79
 
    return (target, source)
80
 
 
81
 
class Dependency:
82
 
 
83
 
    def __init__(self, cppPath=None, libPath=None, libs=None, linkOpts=None, version=None, compiler=None):
84
 
        self.cppPath, self.libPath, self.libs, self.linkOpts, self.version, self.compiler  = cppPath, libPath, libs, linkOpts, version, compiler
85
 
 
86
 
    def __str__(self):
87
 
        return "\ncppPath: %s\nlibPath: %s\nlibs: %s\nlibs: %s\ncompiler: %s\n" % \
88
 
               (self.cppPath,self.libPath,self.libs,self.linkOpts,self.compiler)
89
 
 
90