source: branches/newfiller/scons/utils.py@ 2950

Last change on this file since 2950 was 1757, checked in by Kana Sugimoto, 15 years ago

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


File size: 4.5 KB
Line 
1import sys
2import os
3import glob
4import re
5import platform
6
7def generate(env):
8
9 def SGlob(pattern, excludedirs=[], recursive=False):
10 # always exclude .svn
11 excludedirs.append(".svn")
12 path = env.GetBuildPath('SConscript').replace('SConscript', '')
13 if recursive:
14 # remove '*' from pattern is accidentally specified
15 pattern=pattern.replace("*", "")
16 out = []
17 for d, ld, fls in os.walk(path):
18 # remove directorys to be excluded
19 for exd in excludedirs:
20 if exd in ld:
21 ld.remove(exd)
22 for f in fls:
23 if f.endswith(pattern):
24 drel=d.replace(path,"")
25 out.append(os.path.join(drel,f))
26 return out
27 else:
28 return [ i.replace(path, '') for i in glob.glob(path + pattern) ]
29 env.SGlob = SGlob
30
31 def AddCustomPath(path=None):
32 if path is None or not os.path.exists(path):
33 env.Exit(1)
34 env.PrependUnique(CPPPATH = [os.path.join(path, "include")])
35 env.PrependUnique(LIBPATH = [os.path.join(path, "lib")])
36 env.AddCustomPath = AddCustomPath
37
38 def AddCustomPackage(pkgname=None):
39 if pkgname is None:
40 return
41 pkgroot = env.get("%sroot" % pkgname, None)
42 pkgincd = env.get("%sincdir" % pkgname, None)
43 pkglibd = env.get("%slibdir" % pkgname, None)
44 incd = None
45 libd = None
46 if pkgroot is not None:
47 incd = os.path.join(pkgroot, "include")
48 libd = os.path.join(pkgroot, "lib")
49 else:
50 if pkgincd is not None:
51 incd = pkgincd
52 if pkglibd is not None:
53 libd = pkglibd
54 if incd is not None:
55 if not os.path.exists(incd):
56 print "Custom %s include dir '%s' not found" % (pkgname, incd)
57 env.Exit(1)
58 env.PrependUnique(CPPPATH = [incd])
59 if libd is not None:
60 if not os.path.exists(libd):
61 print "Custom %s lib dir '%s' not found" % (pkgname, libd)
62 env.Exit(1)
63 env.PrependUnique(LIBPATH = [libd])
64
65 env.AddCustomPackage = AddCustomPackage
66
67 def PlatformIdent():
68 p = sys.platform
69 # replace the trailing 2 in linux2
70 p = re.sub(re.compile("2$"), "", p)
71 return p + "_" + platform.machine()
72 env.PlatformIdent = PlatformIdent
73
74 def MergeFlags():
75 def _to_list(xf):
76 if xf.count(","):
77 return xf.split(",")
78 return xf.split()
79
80 xf=env.get("extracppflags", None)
81 if xf:
82 env.AppendUnique(CPPFLAGS=_to_list(xf))
83 xf=env.get("extralinkflags", None)
84 if xf:
85 env.AppendUnique(LINKFLAGS=_to_list(xf))
86 env.AppendUnique(SHLINKFLAGS=_to_list(xf))
87 xf=env.get("extracxxflags", None)
88 if xf:
89 env.AppendUnique(CXXFLAGS=_to_list(xf))
90 xf=env.get("extrafflags", None)
91 if xf:
92 env.AppendUnique(FORTRANFLAGS=_to_list(xf))
93 env.AppendUnique(SHFORTRANFLAGS=_to_list(xf))
94 xf=env.get("extracflags", None)
95 if xf:
96 env.AppendUnique(CCFLAGS=_to_list(xf))
97 # set the extra flags if available
98 MergeFlags()
99
100 def CheckFortran(conf):
101
102 def getf2clib(fc):
103 fdict = {'gfortran': 'gfortran', 'g77': 'g2c', 'f77': 'f2c'}
104 return fdict[fc]
105
106
107 if not conf.env.has_key("FORTRAN"):
108 # auto-detect fortran
109 detect_fortran = conf.env.Detect(['gfortran', 'g77', 'f77'])
110 conf.env["FORTRAN"] = detect_fortran
111 f2clib = conf.env.get("f2clib", getf2clib(conf.env["FORTRAN"]))
112 if not conf.CheckLib(f2clib):
113 conf.env.Exit(1)
114
115 if conf.env["FORTRAN"].startswith("g77"):
116 fflags = ["-Wno-globals", "-fno-second-underscore"]
117 conf.env.AppendUnique(SHFORTRANFLAGS=fflags)
118 conf.env.AppendUnique(FORTRANFLAGS=fflags)
119 conf.env.AppendUnique(SHFORTRANFLAGS=['-fPIC'])
120
121 env.CheckFortran = CheckFortran
122
123 def WalkDirTree(targetroot, sourceroot, sources):
124 ifiles = []
125 ofiles = []
126 for s in sources:
127 if os.path.isdir(os.path.join(sourceroot ,s)):
128 for d,ld,f in os.walk(os.path.join(sourceroot ,s)):
129 for fl in f:
130 ifile = os.path.join(d, fl)
131 ifiles.append(ifile)
132 ofile = ifile.replace(sourceroot, targetroot)
133 ofiles.append(ofile)
134 return ofiles, ifiles
135 env.WalkDirTree = WalkDirTree
136
137
138 def null_action(target, source, env): return 0
139
140 def message(target, source, env):
141 return "%s" % target[0]
142 env.MessageAction = env.Action(null_action, message)
143
144def exists(env):
145 try:
146 import os
147 import glob
148 except ImportError:
149 return False
150 else:
151 return True
Note: See TracBrowser for help on using the repository browser.