/[ascend]/branches/python3/SConstruct
ViewVC logotype

Diff of /branches/python3/SConstruct

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

revision 3505 by jpye, Tue Feb 28 00:38:51 2023 UTC revision 3506 by jpye, Wed Mar 8 23:02:10 2023 UTC
# Line 301  vars.Add(BoolVariable('WITH_PYTHON' Line 301  vars.Add(BoolVariable('WITH_PYTHON'
301      , True      , True
302  ))  ))
303    
304    vars.Add(
305        'PYTHON'
306        ,"Python executable"
307        ,sys.executable
308    )
309    
310    vars.Add(
311        'PYTHON_PKG'
312        ,"Python package name in pkg-config"
313        ,"python-%d.%d" % (sys.version_info[0],sys.version_info[1])
314    )
315    
316    
317  # Which solvers will we allow?  # Which solvers will we allow?
318  vars.Add(ListVariable('WITH_SOLVERS'  vars.Add(ListVariable('WITH_SOLVERS'
319      ,"List of the solvers you want to build. The default is the minimum that"        ,"List of the solvers you want to build. The default is the minimum that"  
# Line 860  if env['ENV'].get('HOST_PREFIX'): Line 873  if env['ENV'].get('HOST_PREFIX'):
873  with_tcltk = env.get('WITH_TCLTK')  with_tcltk = env.get('WITH_TCLTK')
874  without_tcltk_reason = "disabled by options/config.py"  without_tcltk_reason = "disabled by options/config.py"
875    
 with_python = env.get('WITH_PYTHON')  
 without_python_reason = "disabled by options/config.py"  
   
876  with_cunit = env.get('WITH_CUNIT')  with_cunit = env.get('WITH_CUNIT')
877  without_cunit_reason = "not requested"  without_cunit_reason = "not requested"
878    
# Line 1049  def CheckASan(context): Line 1059  def CheckASan(context):
1059      return is_ok      return is_ok
1060    
1061  #----------------  #----------------
 # SWIG  
   
 import os,re  
   
 def get_swig_version(env):  
     if not WhereIs(env['SWIG']):  
         raise RuntimeError("'%s' not found in PATH"%env.subst("$SWIG"))  
     cmd = [env['SWIG'],'-version']  
     p = subprocess.Popen(cmd,stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')  
     output, err = p.communicate()  
       
     restr = r"\s*SWIG\s+Version\s+(?P<maj>[0-9]+)\.(?P<min>[0-9]+)\.(?P<pat>[0-9]+)\b"  
     expr = re.compile(restr,re.MULTILINE|re.IGNORECASE);  
     m = expr.match(output);  
     if not m:  
         raise RuntimeError("Failed match on output '%s'"  % output)  
     maj = int(m.group('maj'))  
     min = int(m.group('min'))  
     pat = int(m.group('pat'))  
   
     return (maj,min,pat)  
       
   
 def CheckSwigVersion(context):  
       
     try:  
         context.Message("Checking version of SWIG... ")  
         maj,min,pat = get_swig_version(context.env)  
     except Exception as e:  
         context.Result("Failed (%s)" % str(e))  
         return False;  
       
     context.env['SWIGVERSION']=tuple([maj,min,pat])  
       
     msg = "too old"  
     res = False  
     if maj == 1 and (  
             min > 3  
             or (min == 3 and pat >= 24)  
         ):  
         msg = "ok"  
         res = True  
     elif maj >= 2:  
         msg = "ok"  
         res = True  
   
     context.Result("%s, %d.%d.%d" % (msg, maj,min,pat))  
     return res;  
   
 #----------------  
1062  # Scrollkeeper (Linux documentation system)  # Scrollkeeper (Linux documentation system)
1063    
1064  def get_scrollkeeper_omfdir(env):  def get_scrollkeeper_omfdir(env):
# Line 1560  def CheckDLOpen(context): Line 1520  def CheckDLOpen(context):
1520      return is_ok      return is_ok
1521    
1522  #----------------  #----------------
 # libpython test  
   
 libpython_test_text = """  
 #include <Python.h>  
 PyObject *get10(void){  
     PyObject *p = Py_BuildValue("i", 10);  
     return p;  
 }  
 int main(void){  
     return 0;  
 }  
 """  
   
 def CheckPythonLib(context):  
     context.Message('Checking for libpython... ')  
   
     if platform.system()=="Windows":  
         python_lib='python%d%d'  
     else:  
         python_lib='python%d.%d'  
   
     try:  
         python_libs = [python_lib % (sys.version_info[0],sys.version_info[1])]  
         python_cpppath = [distutils.sysconfig.get_python_inc()]  
         cfig = distutils.sysconfig.get_config_vars()      
     except:  
         context.Result("not found")  
         return 0          
       
     lastLIBS = context.env.get('LIBS')  
     lastLIBPATH = context.env.get('LIBPATH')  
     lastCPPPATH = context.env.get('CPPPATH')  
     lastLINKFLAGS = context.env.get('LINKFLAGS')  
   
     python_libpath = []  
     python_linkflags = []  
     if platform.system()=="Windows":  
         python_libpath += [os.path.join(sys.prefix,"libs")]  
         print("Python libpath =",python_libpath)  
     elif platform.system()=="Darwin":  
         python_libpath += [cfig['LIBPL']]  
         python_linkflags += cfig['LIBS'].split(' ')  
     else:  
         # checked on Linux and SunOS  
         if cfig['LDLIBRARY']==cfig['LIBRARY']:  
             sys.stdout.write("(static)")  
             python_libpath += [cfig['LIBPL']]  
             python_linkflags += cfig['LIBS'].split(' ')  
   
     context.env.AppendUnique(LIBS=python_libs)  
     context.env.AppendUnique(LIBPATH=python_libpath)  
     context.env.AppendUnique(CPPPATH=python_cpppath)  
     context.env.AppendUnique(LINKFLAGS=python_linkflags)  
     result = context.TryLink(libpython_test_text,".c");  
   
     context.Result(result)    
   
     if(result):  
         context.env['PYTHON_LIBPATH']=python_libpath  
         context.env['PYTHON_LIB']=python_libs  
         context.env['PYTHON_CPPPATH']=python_cpppath  
         context.env['PYTHON_LINKFLAGS']=python_linkflags  
   
     context.env['LIBS'] = lastLIBS  
     context.env['LIBPATH'] = lastLIBPATH  
     context.env['CPPPATH'] = lastCPPPATH  
     context.env['LINKFLAGS'] = lastLINKFLAGS  
   
     return result  
   
 #----------------  
1523  # IDA test  # IDA test
1524    
1525  sundials_version_major_required = 2  sundials_version_major_required = 2
# Line 2090  conf = Configure(env Line 1979  conf = Configure(env
1979          , 'CheckMalloc' : CheckMalloc          , 'CheckMalloc' : CheckMalloc
1980          , 'CheckASan' : CheckASan          , 'CheckASan' : CheckASan
1981          , 'CheckDLOpen' : CheckDLOpen          , 'CheckDLOpen' : CheckDLOpen
1982          , 'CheckSwigVersion' : CheckSwigVersion  #       , 'CheckSwigVersion' : CheckSwigVersion
1983          , 'CheckPythonLib' : CheckPythonLib  #       , 'CheckPythonLib' : CheckPythonLib
1984          , 'CheckCUnit' : CheckCUnit          , 'CheckCUnit' : CheckCUnit
1985          , 'CheckDMalloc' : CheckDMalloc          , 'CheckDMalloc' : CheckDMalloc
1986          , 'CheckLyx' : CheckLyx          , 'CheckLyx' : CheckLyx
# Line 2334  if with_tcltk: Line 2223  if with_tcltk:
2223  if env['STATIC_TCLTK']:  if env['STATIC_TCLTK']:
2224      conf.CheckX11()      conf.CheckX11()
2225    
 # Python... obviously we're already running python, so we just need to  
 # check that we can link to the python library OK:  
   
 if not conf.CheckPythonLib():  
     without_python_reason = 'libpython2.x not found or not linkable'  
     with_python = False  
     env['WITH_PYTHON']=False  
   
 # SWIG version  
   
 if with_python and conf.CheckSwigVersion() is False:  
     without_python_reason = 'SWIG >= 1.3.24 is required'  
     with_python = False  
     env['WITH_PYTHON']=False  
   
2226  # CUnit  # CUnit
2227    
2228  if with_cunit:  if with_cunit:
# Line 2486  if platform.system()=="Windows" and 'MSV Line 2360  if platform.system()=="Windows" and 'MSV
2360          with_python = 0;          with_python = 0;
2361          without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."          without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
2362    
2363  print("1. SIZEOF_VOID_P = %s"%(conf.env['SIZEOF_VOID_P']))  #print("1. SIZEOF_VOID_P = %s"%(conf.env['SIZEOF_VOID_P']))
2364  env = conf.Finish()  env = conf.Finish()
2365  print("2. SIZEOF_VOID_P = %s"%(env['SIZEOF_VOID_P']))  #print("2. SIZEOF_VOID_P = %s"%(env['SIZEOF_VOID_P']))
2366  #print "-=-=-=-=-=-=-=-=- LIBS =",env.get('LIBS')  #print "-=-=-=-=-=-=-=-=- LIBS =",env.get('LIBS')
2367    
2368  #---------------------------------------  #---------------------------------------
# Line 2560  subst_dict = { Line 2434  subst_dict = {
2434      , '@SIZEOF_ULONG@' : env['SIZEOF_ULONG']      , '@SIZEOF_ULONG@' : env['SIZEOF_ULONG']
2435      , '@SIZEOF_ULONGLONG@' : env['SIZEOF_ULONGLONG']      , '@SIZEOF_ULONGLONG@' : env['SIZEOF_ULONGLONG']
2436      , '@WITH_SOLVERS@' : ",".join(env.get('WITH_SOLVERS'))      , '@WITH_SOLVERS@' : ",".join(env.get('WITH_SOLVERS'))
2437        , '@ASCXX_USE_PYTHON@' : "1" if env['WITH_PYTHON'] else "0"
2438  }  }
2439    
2440    
# Line 2591  for k,v in { Line 2466  for k,v in {
2466      else:      else:
2467          subst_dict['@%s@' %(k,)] = "// %s is not set." %(k,)          subst_dict['@%s@' %(k,)] = "// %s is not set." %(k,)
2468    
 if with_python:  
     subst_dict['@ASCXX_USE_PYTHON@']="1"  
     env['WITH_PYTHON']=1;  
   
2469  if with_latex2html:  if with_latex2html:
2470      env['WITH_LATEX2HTML']=1      env['WITH_LATEX2HTML']=1
2471    
# Line 2609  env.Append(SUBST_DICT=subst_dict) Line 2480  env.Append(SUBST_DICT=subst_dict)
2480  # REMOVED: long command-line support on Win2k  # REMOVED: long command-line support on Win2k
2481    
2482  #------------------------------------------------------  #------------------------------------------------------
 # RECIPE: SWIG scanner  
   
 import SCons.Script  
   
 SWIGScanner = SCons.Scanner.ClassicCPP(  
     "SWIGScan"  
     , ".i"  
     , "CPPPATH"  
     , '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'  
 )  
   
 env.Append(SCANNERS=[SWIGScanner])  
   
 #------------------------------------------------------  
2483  # Recipe for 'CHMOD' ACTION        # Recipe for 'CHMOD' ACTION      
2484            
2485  import SCons      import SCons    
# Line 2693  if with_graphviz and env.get('GRAPHVIZ_R Line 2550  if with_graphviz and env.get('GRAPHVIZ_R
2550      env.Append(RPATH=env['GRAPHVIZ_RPATH'])      env.Append(RPATH=env['GRAPHVIZ_RPATH'])
2551    
2552  #-------------  #-------------
 # TCL/TK GUI  
   
 if with_tcltk:  
     env.SConscript(['tcltk/SConscript'],'env')  
 else:  
     print("Skipping... Tcl/Tk bindings aren't being built:",without_tcltk_reason)  
   
 #-------------  
2553  # PYTHON INTERFACE  # PYTHON INTERFACE
2554    
2555  if with_python:  if env.get('WITH_PYTHON'):  
2556        subst_dict['@ASCXX_USE_PYTHON@']="1"
2557        env['WITH_PYTHON']=1;
2558    
2559      env.SConscript(['ascxx/SConscript'],'env')      env.SConscript(['ascxx/SConscript'],'env')
2560      env.SConscript(['pygtk/SConscript'],'env')      env.SConscript(['pygtk/SConscript'],'env')
2561  else:  else:
2562      print("Skipping... Python bindings aren't being built:",without_python_reason)      print("Skipping... Python bindings aren't being built:",without_python_reason)
2563    
2564    #-------------
2565    # TCL/TK GUI
2566    
2567    if with_tcltk:
2568        env.SConscript(['tcltk/SConscript'],'env')
2569    else:
2570        print("Skipping... Tcl/Tk bindings aren't being built:",without_tcltk_reason)
2571    
2572  #------------  #------------
2573  # BASE/GENERIC SUBDIRECTORIES  # BASE/GENERIC SUBDIRECTORIES
2574    
# Line 3047  else: Line 2907  else:
2907  default_targets =['libascend','solvers',a4cmd]  default_targets =['libascend','solvers',a4cmd]
2908  if with_tcltk:  if with_tcltk:
2909      default_targets.append('tcltk')      default_targets.append('tcltk')
2910  if with_python:  if 'WITH_PYTHON' in env:
2911      default_targets.append('ascxx')      default_targets.append('ascxx')
2912      default_targets.append('pygtk')  #   default_targets.append('pygtk')
2913      default_targets.append('pyfprops')  #   default_targets.append('pyfprops')
2914  if with_extfns:  if with_extfns:
2915      default_targets.append('extfns')      default_targets.append('extfns')
2916  if with_doc_build:  if with_doc_build:
# Line 3060  env.Default(default_targets) Line 2920  env.Default(default_targets)
2920    
2921  print("Building targets:"," ".join([str(i) for i in BUILD_TARGETS]))  print("Building targets:"," ".join([str(i) for i in BUILD_TARGETS]))
2922    
2923  # vim: set syntax=python:  # vim: ts=4:sw=4:noet:syntax=python

Legend:
Removed from v.3505  
changed lines
  Added in v.3506

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