source: branches/alma/scons/utils.py@ 1391

Last change on this file since 1391 was 1332, checked in by mar637, 18 years ago

small patch for fortran detection, when no fortran is found.

File size: 3.5 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 if not detect_fortran:
52 print "No fortran compiler found. Specify FORTRAN and f2clib."
53 conf.env.Exit(1)
54 conf.env["FORTRAN"] = detect_fortran
55 fdict = {'gfortran': 'gfortran', 'g77': 'g2c', 'f77': 'f2c'}
56 f2clib = conf.env.get("f2clib", fdict[detect_fortran])
57 if not conf.CheckLib(f2clib):
58 env.Exit(1)
59 else:
60 if not conf.env.has_key("f2clib"):
61 print "A custom fortran compiler also needs f2clib defined"
62 env.Exit(1)
63 else:
64 if not conf.CheckLib(env["f2clib"]):
65 env.Exit(1)
66 if conf.env["FORTRAN"].startswith("g77"):
67 fflags = ["-Wno-globals", "-fno-second-underscore"]
68 conf.env.Append(SHFORTRANFLAGS=fflags)
69 conf.env.Append(FORTRANFLAGS=fflags)
70 env.CheckFortran = CheckFortran
71
72 def WalkDirTree(targetroot, sourceroot, sources):
73 ifiles = []
74 ofiles = []
75 for s in sources:
76 if os.path.isdir(os.path.join(sourceroot ,s)):
77 for d,ld,f in os.walk(os.path.join(sourceroot ,s)):
78 for fl in f:
79 ifile = os.path.join(d, fl)
80 ifiles.append(ifile)
81 ofile = ifile.replace(sourceroot, targetroot)
82 ofiles.append(ofile)
83 return ofiles, ifiles
84 env.WalkDirTree = WalkDirTree
85
86 def null_action(target, source, env): return 0
87
88 def message(target, source, env):
89 return "%s" % target[0]
90 env.MessageAction = env.Action(null_action, message)
91
92def exists(env):
93 try:
94 import os
95 import glob
96 except ImportError:
97 return False
98 else:
99 return True
Note: See TracBrowser for help on using the repository browser.