/[ascend]/trunk/scons/sundials.py
ViewVC logotype

Contents of /trunk/scons/sundials.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2552 - (show annotations) (download) (as text)
Thu Feb 2 20:54:40 2012 UTC (6 years, 7 months ago) by jpye
File MIME type: text/x-python
File size: 4277 byte(s)
Fix detection of SUNDIALS in MinGW-w64.
Fix paths in test_ida and test_lsode.
1 import os, os.path, platform, subprocess
2 from SCons.Script import *
3
4 munge = lambda s: s
5
6 try:
7 # if we have access to GetShortPathName, we'll use it...
8 import win32api
9 def munge1(s):
10 s1 = s
11 try:
12 # we can only munge the path if it actually exists
13 s1 = win32api.GetShortPathName(s)
14 except:
15 # if it doesn't exist, we just return the un-munged path
16 pass
17 return s1
18 munge = munge1
19 except:
20 pass
21
22 def winpath(path):
23 """
24 Convert a MSYS path to a native Windows path, so that we can pass values correctly to GCC
25 """
26 import subprocess
27 import os
28 #print "path = %s"%path
29 fn = "scons%d" % os.getpid()
30 while os.path.exists(fn):
31 fn = fn + "0"
32 try:
33 f = file(fn,"w")
34 f.write("#!python\nimport sys\nprint sys.argv[1]")
35 f.close()
36 #print "FILE %s FOUND? %d"%(fn,os.path.exists(fn))
37 p1 = subprocess.Popen(["sh.exe","-c","%s %s"%(fn,path)], stdout=subprocess.PIPE)
38 #p1 = subprocess.Popen(["sh.exe","-c","echo hello"], stdout=subprocess.PIPE)
39 out = p1.communicate()[0].strip()
40 #print "NEW PATH IS '%s'" % out
41 except Exception,e:
42 print "FAILED: %s"%str(e)
43 finally:
44 #print "Deleting %s" % fn
45 os.unlink(fn)
46 return out
47
48 def generate(env):
49 """
50 Detect SUNDIALS (IDA) settings and add them to the environment.
51 """
52 try:
53 if platform.system()=="Windows":
54 try:
55 # one day, we'll provide a SUNDIALS installer so that people don't have to
56 # build their own SUNDIALS. In that case, look for the settings in the registry
57 import _winreg
58 x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
59 y= _winreg.OpenKey(x,r"SOFTWARE\SUNDIALS")
60 PATH,t = _winreg.QueryValueEx(y,"InstallPath")
61 LIB = os.path.join(PATH,"lib")
62 BIN = os.path.join(PATH,"bin")
63 INCLUDE = os.path.join(PATH,"include")
64 env['SUNDIALS_CPPPATH'] = [munge(INCLUDE)]
65 env['SUNDIALS_LIBPATH'] = [munge(BIN)]
66 env['SUNDIALS_LIBS'] = ['sundials_ida','sundials_nvecserial','m']
67 except WindowsError:
68 # if someone has installed sundials with ./configure --prefix=/MinGW using MSYS, then
69 # this should work, but we would like to make this a lot more robust!
70 cmd = ['sh.exe','/mingw/bin/sundials-config','-mida','-ts','-lc']
71 env1 = env.Clone()
72 env1['CPPPATH'] = None
73 env1['LIBPATH'] = None
74 env1['LIBS'] = None
75 print "RUNNING sundials-config"
76 env1.ParseConfig(cmd)
77 env['SUNDIALS_CPPPATH'] = [munge(winpath(p)) for p in env1.get('CPPPATH')]
78 env['SUNDIALS_LIBPATH'] = [munge(winpath(p)) for p in env1.get('LIBPATH')]
79 env['SUNDIALS_LIBS'] = env1.get('LIBS')
80 env['HAVE_SUNDIALS'] = True
81
82 env['HAVE_SUNDIALS'] = True
83
84 else:
85 cmd = ['sundials-config','-mida','-ts','-lc']
86 env1 = env.Clone()
87 env1['CPPPATH'] = None
88 env1['LIBPATH'] = None
89 env1['LIBS'] = None
90 env1.ParseConfig(cmd)
91
92 # tricky stuff to detect the necessary extra 'lapack' linkage if required
93 if os.path.exists("/etc/lsb-release"):
94 print "CHECKING SUNDIALS"
95 s = env.WhereIs('sundials-config')
96 if s == "/usr/bin/sundials-config":
97 print "STANDARD CONFIG"
98 # With Ubuntu 11.10 onwards, we need to explicitly add lapack (and blas?)
99 f = file("/etc/lsb-release")
100 v = {}
101 for l in f:
102 x = l.strip().split("=")
103 v[x[0]] = x[1]
104 print v
105 if v['DISTRIB_ID']=="Ubuntu" and float(v['DISTRIB_RELEASE'])>=11.10:
106 print "ADDING LAPACK"
107 env1['LIBS'].append("lapack")
108
109 env['SUNDIALS_CPPPATH'] = env1.get('CPPPATH')
110 env['SUNDIALS_LIBPATH'] = env1.get('LIBPATH')
111 env['SUNDIALS_LIBS'] = env1.get('LIBS')
112 env['HAVE_SUNDIALS'] = True
113
114 print "SUNDIALS_LIBS =",env.get('SUNDIALS_LIBS')
115 print "SUNDIALS_LIBPATH =",env.get('SUNDIALS_LIBPATH')
116 print "SUNDIALS_CPPPATH =",env.get('SUNDIALS_CPPPATH')
117
118 except Exception, e:
119 print "FAILED SUNDIALS DETECTION (%s):" % platform.system(),e.__class__,str(e)
120 env['HAVE_SUNDIALS'] = False
121
122 def exists(env):
123 """
124 Make sure this tool exists.
125 """
126 if platform.system()=="Windows":
127 try:
128 import _winreg
129 x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
130 y= _winreg.OpenKey(x,r"SOFTWARE\SUNDIALS")
131 INCLUDE,t = _winreg.QueryValueEx(y,'INSTALL_INCLUDE')
132 return True
133 except:
134 return False
135 else:
136 if not subprocess.call('sundials-config -h'):
137 return True
138 return False
139

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22