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

Annotation of /trunk/scons/sundials.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2706 - (hide annotations) (download) (as text)
Sat Aug 17 10:16:07 2013 UTC (8 years, 11 months ago) by jpye
File MIME type: text/x-python
File size: 5145 byte(s)
changes for MinGW-w64
1 mahesh 2150 import os, os.path, platform, subprocess
2     from SCons.Script import *
3 jpye 2706 from SCons.Util import WhereIs
4 mahesh 2150 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 jpye 2552 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 mahesh 2150 def generate(env):
49     """
50     Detect SUNDIALS (IDA) settings and add them to the environment.
51     """
52     try:
53     if platform.system()=="Windows":
54 jpye 2170 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 jpye 2706 sundialsconfig = find_sundials_config(env)
69     if not sundialsconfig:
70     raise RuntimeError("Unable to locate sundials-config in Windows PATH")
71     # if someone has installed sundials with ./configure --prefix=/MinGW using MSYS, then
72 jpye 2170 # this should work, but we would like to make this a lot more robust!
73 jpye 2706 cmd = ['sh.exe',sundialsconfig,'-mida','-ts','-lc']
74 jpye 2170 env1 = env.Clone()
75     env1['CPPPATH'] = None
76     env1['LIBPATH'] = None
77     env1['LIBS'] = None
78 jpye 2706 #print "RUNNING sundials-config"
79 jpye 2170 env1.ParseConfig(cmd)
80 jpye 2552 env['SUNDIALS_CPPPATH'] = [munge(winpath(p)) for p in env1.get('CPPPATH')]
81     env['SUNDIALS_LIBPATH'] = [munge(winpath(p)) for p in env1.get('LIBPATH')]
82 jpye 2170 env['SUNDIALS_LIBS'] = env1.get('LIBS')
83     env['HAVE_SUNDIALS'] = True
84 mahesh 2150
85     env['HAVE_SUNDIALS'] = True
86    
87     else:
88 jpye 2706 sundialsconfig = env.WhereIs("sundials-config")
89     if not sundialsconfig:
90     raise RuntimeError("Unable to locate 'sundials-config' in PATH")
91 mahesh 2150 cmd = ['sundials-config','-mida','-ts','-lc']
92     env1 = env.Clone()
93     env1['CPPPATH'] = None
94     env1['LIBPATH'] = None
95     env1['LIBS'] = None
96     env1.ParseConfig(cmd)
97 jpye 2551
98     # tricky stuff to detect the necessary extra 'lapack' linkage if required
99     if os.path.exists("/etc/lsb-release"):
100     print "CHECKING SUNDIALS"
101     s = env.WhereIs('sundials-config')
102     if s == "/usr/bin/sundials-config":
103     print "STANDARD CONFIG"
104     # With Ubuntu 11.10 onwards, we need to explicitly add lapack (and blas?)
105     f = file("/etc/lsb-release")
106     v = {}
107     for l in f:
108     x = l.strip().split("=")
109     v[x[0]] = x[1]
110     print v
111     if v['DISTRIB_ID']=="Ubuntu" and float(v['DISTRIB_RELEASE'])>=11.10:
112     print "ADDING LAPACK"
113     env1['LIBS'].append("lapack")
114    
115 mahesh 2150 env['SUNDIALS_CPPPATH'] = env1.get('CPPPATH')
116     env['SUNDIALS_LIBPATH'] = env1.get('LIBPATH')
117     env['SUNDIALS_LIBS'] = env1.get('LIBS')
118     env['HAVE_SUNDIALS'] = True
119    
120     print "SUNDIALS_LIBS =",env.get('SUNDIALS_LIBS')
121     print "SUNDIALS_LIBPATH =",env.get('SUNDIALS_LIBPATH')
122     print "SUNDIALS_CPPPATH =",env.get('SUNDIALS_CPPPATH')
123    
124 jpye 2170 except Exception, e:
125 jpye 2413 print "FAILED SUNDIALS DETECTION (%s):" % platform.system(),e.__class__,str(e)
126 mahesh 2150 env['HAVE_SUNDIALS'] = False
127    
128 jpye 2706 def find_sundials_config(env):
129     """
130     Try and figure out if sundials-config is installed on this machine, and if so, where.
131     """
132     if SCons.Util.can_read_reg:
133     # If we can read the registry, get the NSIS command from it
134     try:
135     # 0x20019 is KEY_READ,
136     k = SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,'SOFTWARE\\NSIS',0,0x20019)
137     val, tok = SCons.Util.RegQueryValueEx(k,None)
138     ret = val + os.path.sep + 'makensis.exe'
139     if os.path.exists(ret):
140     return '"' + ret + '"'
141     else:
142     return None
143     except:
144     pass # Couldn't find the key, just act like we can't read the registry
145     # Hope it's on the path, but note that we have to be careful with PATHEXT since sundials-config doesn't have an
146     # an executable-signifying suffix (seems like a weakness with env.WhereIs in SCons??
147     return WhereIs('sundials-config',path=os.environ['PATH'],pathext="")
148    
149 mahesh 2150 def exists(env):
150 jpye 2706 if find_sundials_config(env) != None:
151     return 1
152     return 0
153 mahesh 2150

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