source: trunk/scons/utils.py @ 1325

Last change on this file since 1325 was 1325, checked in by mar637, 17 years ago

Changes to use casacore instead of casa_asap/aips++\nAdded atnf PKSIO library snapshot to external and linking against this local copy

File size: 3.3 KB
Line 
1import os
2import glob
3
4def generate(env):
5    def SGlob(pattern):
6        path = env.GetBuildPath('SConscript').replace('SConscript', '')
7        return [ i.replace(path, '') for i in glob.glob(path + pattern) ]
8    env.SGlob = SGlob
9
10    def AddCustomPath(path=""):
11        if not len(path) or not os.path.exists(path):
12            return
13        env.PrependUnique(CPPPATH = [os.path.join(path, "include")])
14        env.PrependUnique(LIBPATH = [os.path.join(path, "lib")])
15    env.AddCustomPath = AddCustomPath
16
17    def AddCustomPackage(pkgname=None):
18        if pkgname is None:
19            return
20        pkgroot = env.get("%sroot" % pkgname, None)
21        pkgincd = env.get("%sincdir" % pkgname, None)
22        pkglibd = env.get("%slibdir" % pkgname, None)
23        incd = None
24        libd = None
25        if pkgroot is not None:
26            incd = os.path.join(pkgroot, "include")
27            libd = os.path.join(pkgroot, "lib")
28        else:       
29            if pkgincd is not None:
30                incd = pkgincd
31            if pkglibd is not None:
32                libd = pkglibd
33        if incd is not None:
34            if not os.path.exists(incd):
35                print "Custom %s include dir '%s' not found" % (pkgname, incd)
36                env.Exit(1)
37            env.PrependUnique(CPPPATH = [incd])
38        if libd is not None:
39            if not os.path.exists(libd):
40                print "Custom %s lib dir '%s' not found" % (pkgname, libd)
41                env.Exit(1)
42            env.PrependUnique(LIBPATH = [libd])
43
44    env.AddCustomPackage = AddCustomPackage
45
46    def CheckFortran(conf):
47           
48        if not conf.env.has_key("FORTRAN"):
49            # auto-detect fortran
50            detect_fortran = conf.env.Detect(['gfortran', 'g77', 'f77'])
51            conf.env["FORTRAN"] = detect_fortran
52            fdict = {'gfortran': 'gfortran', 'g77': 'g2c', 'f77': 'f2c'}
53            f2clib = conf.env.get("f2clib", fdict[detect_fortran])
54            if not conf.CheckLib(f2clib):
55                env.Exit(1)
56        else:
57            if not conf.env.has_key("f2clib"):
58                print "A custom fortran compiler also needs f2clib defined"
59                env.Exit(1)
60            else:
61                if not conf.CheckLib(env["f2clib"]):
62                    env.Exit(1)
63        if conf.env["FORTRAN"].startswith("g77"):
64            fflags = ["-Wno-globals", "-fno-second-underscore"]
65            conf.env.Append(SHFORTRANFLAGS=fflags)
66            conf.env.Append(FORTRANFLAGS=fflags)
67    env.CheckFortran = CheckFortran
68
69    def WalkDirTree(targetroot, sourceroot, sources):
70        ifiles = []
71        ofiles = []
72        for s in sources:
73            if os.path.isdir(os.path.join(sourceroot ,s)):
74                for d,ld,f in os.walk(os.path.join(sourceroot ,s)):
75                    for fl in f:
76                        ifile = os.path.join(d, fl)
77                        ifiles.append(ifile)
78                        ofile = ifile.replace(sourceroot, targetroot)
79                        ofiles.append(ofile)
80        return ofiles, ifiles
81    env.WalkDirTree = WalkDirTree
82
83    def null_action(target, source, env): return 0
84
85    def message(target, source, env):
86        return "%s" % target[0]
87    env.MessageAction = env.Action(null_action, message)
88
89def exists(env):
90    try:
91        import os
92        import glob
93    except ImportError:
94        return False
95    else:
96        return True
Note: See TracBrowser for help on using the repository browser.