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

Diff of /trunk/scons/sundials.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2705 by jpye, Thu Feb 2 20:54:40 2012 UTC revision 2706 by jpye, Sat Aug 17 10:16:07 2013 UTC
# Line 1  Line 1 
1  import os, os.path, platform, subprocess  import os, os.path, platform, subprocess
2  from SCons.Script import *  from SCons.Script import *
3    from SCons.Util import WhereIs
4  munge = lambda s: s  munge = lambda s: s
5    
6  try:  try:
# Line 65  def generate(env): Line 65  def generate(env):
65                  env['SUNDIALS_LIBPATH'] = [munge(BIN)]                  env['SUNDIALS_LIBPATH'] = [munge(BIN)]
66                  env['SUNDIALS_LIBS'] = ['sundials_ida','sundials_nvecserial','m']                  env['SUNDIALS_LIBS'] = ['sundials_ida','sundials_nvecserial','m']
67              except WindowsError:              except WindowsError:
68                  # if someone has installed sundials with ./configure --prefix=/MinGW using MSYS, then                  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                  # this should work, but we would like to make this a lot more robust!                  # this should work, but we would like to make this a lot more robust!
73                  cmd = ['sh.exe','/mingw/bin/sundials-config','-mida','-ts','-lc']                  cmd = ['sh.exe',sundialsconfig,'-mida','-ts','-lc']
74                  env1 = env.Clone()                  env1 = env.Clone()
75                  env1['CPPPATH'] = None                  env1['CPPPATH'] = None
76                  env1['LIBPATH'] = None                  env1['LIBPATH'] = None
77                  env1['LIBS'] = None                  env1['LIBS'] = None
78                  print "RUNNING sundials-config"                  #print "RUNNING sundials-config"
79                  env1.ParseConfig(cmd)                  env1.ParseConfig(cmd)
80                  env['SUNDIALS_CPPPATH'] = [munge(winpath(p)) for p in env1.get('CPPPATH')]                  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')]                  env['SUNDIALS_LIBPATH'] = [munge(winpath(p)) for p in env1.get('LIBPATH')]
# Line 82  def generate(env): Line 85  def generate(env):
85              env['HAVE_SUNDIALS'] = True              env['HAVE_SUNDIALS'] = True
86                                                                            
87          else:          else:
88                sundialsconfig = env.WhereIs("sundials-config")
89                if not sundialsconfig:
90                    raise RuntimeError("Unable to locate 'sundials-config' in PATH")
91              cmd = ['sundials-config','-mida','-ts','-lc']              cmd = ['sundials-config','-mida','-ts','-lc']
92              env1 = env.Clone()              env1 = env.Clone()
93              env1['CPPPATH'] = None              env1['CPPPATH'] = None
# Line 119  def generate(env): Line 125  def generate(env):
125          print "FAILED SUNDIALS DETECTION (%s):" % platform.system(),e.__class__,str(e)          print "FAILED SUNDIALS DETECTION (%s):" % platform.system(),e.__class__,str(e)
126          env['HAVE_SUNDIALS'] = False          env['HAVE_SUNDIALS'] = False
127    
128    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  def exists(env):  def exists(env):
150      """      if find_sundials_config(env) != None:
151      Make sure this tool exists.          return 1
152      """      return 0
     if platform.system()=="Windows":  
         try:  
             import _winreg  
             x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)  
             y= _winreg.OpenKey(x,r"SOFTWARE\SUNDIALS")  
             INCLUDE,t = _winreg.QueryValueEx(y,'INSTALL_INCLUDE')  
             return True  
         except:  
             return False  
     else:  
         if not subprocess.call('sundials-config -h'):  
             return True  
         return False  
153    

Legend:
Removed from v.2705  
changed lines
  Added in v.2706

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