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 generate(env): |
23 |
""" |
24 |
Detect SUNDIALS (IDA) settings and add them to the environment. |
25 |
""" |
26 |
try: |
27 |
if platform.system()=="Windows": |
28 |
try: |
29 |
# one day, we'll provide a SUNDIALS installer so that people don't have to |
30 |
# build their own SUNDIALS. In that case, look for the settings in the registry |
31 |
import _winreg |
32 |
x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) |
33 |
y= _winreg.OpenKey(x,r"SOFTWARE\SUNDIALS") |
34 |
PATH,t = _winreg.QueryValueEx(y,"InstallPath") |
35 |
LIB = os.path.join(PATH,"lib") |
36 |
BIN = os.path.join(PATH,"bin") |
37 |
INCLUDE = os.path.join(PATH,"include") |
38 |
env['SUNDIALS_CPPPATH'] = [munge(INCLUDE)] |
39 |
env['SUNDIALS_LIBPATH'] = [munge(BIN)] |
40 |
env['SUNDIALS_LIBS'] = ['sundials_ida','sundials_nvecserial','m'] |
41 |
except WindowsError: |
42 |
# if someone has installed sundials with ./configure --prefix=/MinGW using MSYS, then |
43 |
# this should work, but we would like to make this a lot more robust! |
44 |
cmd = ['c:\\MSYS\\1.0\\bin\\sh.exe','/MinGW/bin/sundials-config','-mida','-ts','-lc'] |
45 |
env1 = env.Clone() |
46 |
env1['CPPPATH'] = None |
47 |
env1['LIBPATH'] = None |
48 |
env1['LIBS'] = None |
49 |
env1.ParseConfig(cmd) |
50 |
env['SUNDIALS_CPPPATH'] = env1.get('CPPPATH') |
51 |
env['SUNDIALS_LIBPATH'] = env1.get('LIBPATH') |
52 |
env['SUNDIALS_LIBS'] = env1.get('LIBS') |
53 |
env['HAVE_SUNDIALS'] = True |
54 |
|
55 |
env['HAVE_SUNDIALS'] = True |
56 |
|
57 |
else: |
58 |
cmd = ['sundials-config','-mida','-ts','-lc'] |
59 |
env1 = env.Clone() |
60 |
env1['CPPPATH'] = None |
61 |
env1['LIBPATH'] = None |
62 |
env1['LIBS'] = None |
63 |
env1.ParseConfig(cmd) |
64 |
env['SUNDIALS_CPPPATH'] = env1.get('CPPPATH') |
65 |
env['SUNDIALS_LIBPATH'] = env1.get('LIBPATH') |
66 |
env['SUNDIALS_LIBS'] = env1.get('LIBS') |
67 |
env['HAVE_SUNDIALS'] = True |
68 |
|
69 |
print "SUNDIALS_LIBS =",env.get('SUNDIALS_LIBS') |
70 |
print "SUNDIALS_LIBPATH =",env.get('SUNDIALS_LIBPATH') |
71 |
print "SUNDIALS_CPPPATH =",env.get('SUNDIALS_CPPPATH') |
72 |
|
73 |
except Exception, e: |
74 |
print "FAILED SUNDIALS DETECTION:",e.__class__,str(e) |
75 |
env['HAVE_SUNDIALS'] = False |
76 |
|
77 |
def exists(env): |
78 |
""" |
79 |
Make sure this tool exists. |
80 |
""" |
81 |
if platform.system()=="Windows": |
82 |
try: |
83 |
import _winreg |
84 |
x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) |
85 |
y= _winreg.OpenKey(x,r"SOFTWARE\SUNDIALS") |
86 |
INCLUDE,t = _winreg.QueryValueEx(y,'INSTALL_INCLUDE') |
87 |
return True |
88 |
except: |
89 |
return False |
90 |
else: |
91 |
if not subprocess.call('sundials-config -h'): |
92 |
return True |
93 |
return False |
94 |
|