/[escript]/branches/inv2jf/SConstruct
ViewVC logotype

Diff of /branches/inv2jf/SConstruct

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

revision 3814 by caltinay, Thu Feb 9 00:11:08 2012 UTC revision 3896 by caltinay, Fri May 11 01:31:29 2012 UTC
# Line 16  EnsurePythonVersion(2,5) Line 16  EnsurePythonVersion(2,5)
16  import sys, os, platform, re  import sys, os, platform, re
17  from distutils import sysconfig  from distutils import sysconfig
18  from site_init import *  from site_init import *
19    import subprocess
20    from subprocess import PIPE, Popen
21    
22  # Version number to check for in options file. Increment when new features are  # Version number to check for in options file. Increment when new features are
23  # added or existing options changed.  # added or existing options changed.
# Line 126  vars.AddVariables( Line 128  vars.AddVariables(
128    ('sys_libs', 'Extra libraries to link with', []),    ('sys_libs', 'Extra libraries to link with', []),
129    ('escript_opts_version', 'Version of options file (do not specify on command line)'),    ('escript_opts_version', 'Version of options file (do not specify on command line)'),
130    ('SVN_VERSION', 'Do not use from options file', -2),    ('SVN_VERSION', 'Do not use from options file', -2),
131      ('pythoncmd', 'which python to compile with','python'),
132      ('usepython3', 'Is this a python3 build? (experimental)', False),
133      ('pythonlibname', 'Name of the python library to link. (This is found automatically for python2.X.)', ''),
134  )  )
135    
136  ##################### Create environment and help text #######################  ##################### Create environment and help text #######################
# Line 244  if env['cc_extra']  != '': env.Append(CF Line 249  if env['cc_extra']  != '': env.Append(CF
249  if env['cxx_extra'] != '': env.Append(CXXFLAGS = env['cxx_extra'])  if env['cxx_extra'] != '': env.Append(CXXFLAGS = env['cxx_extra'])
250  if env['ld_extra']  != '': env.Append(LINKFLAGS = env['ld_extra'])  if env['ld_extra']  != '': env.Append(LINKFLAGS = env['ld_extra'])
251    
252    if env['usepython3']:
253        env.Append(CPPDEFINES=['ESPYTHON3'])
254    
255  # set up the autolazy values  # set up the autolazy values
256  if env['forcelazy'] == 'on':  if env['forcelazy'] == 'on':
257      env.Append(CPPDEFINES=['FAUTOLAZYON'])      env.Append(CPPDEFINES=['FAUTOLAZYON'])
# Line 352  except KeyError: Line 360  except KeyError:
360    
361  ######################## Add some custom builders ############################  ######################## Add some custom builders ############################
362    
363  py_builder = Builder(action = build_py, suffix = '.pyc', src_suffix = '.py', single_source=True)  if env['pythoncmd']=='python':
364        py_builder = Builder(action = build_py, suffix = '.pyc', src_suffix = '.py', single_source=True)
365    else:
366        py_builder = Builder(action = env['pythoncmd']+" scripts/py_comp.py $SOURCE $TARGET", suffix = '.pyc', src_suffix = '.py', single_source=True)
367  env.Append(BUILDERS = {'PyCompile' : py_builder});  env.Append(BUILDERS = {'PyCompile' : py_builder});
368    
369  runUnitTest_builder = Builder(action = runUnitTest, suffix = '.passed', src_suffix=env['PROGSUFFIX'], single_source=True)  runUnitTest_builder = Builder(action = runUnitTest, suffix = '.passed', src_suffix=env['PROGSUFFIX'], single_source=True)
# Line 391  if conf.CheckFunc('gethostname'): Line 402  if conf.CheckFunc('gethostname'):
402    
403  ######## Python headers & library (required)  ######## Python headers & library (required)
404    
405  python_inc_path=sysconfig.get_python_inc()  # Use the python scons is running
406  if IS_WINDOWS:  if env['pythoncmd']=='python':
407      python_lib_path=os.path.join(sysconfig.get_config_var('prefix'), 'libs')      python_inc_path=sysconfig.get_python_inc()
408  elif env['PLATFORM']=='darwin':      if IS_WINDOWS:
409      python_lib_path=sysconfig.get_config_var('LIBPL')          python_lib_path=os.path.join(sysconfig.get_config_var('prefix'), 'libs')
410  else:      elif env['PLATFORM']=='darwin':
411      python_lib_path=sysconfig.get_config_var('LIBDIR')          python_lib_path=sysconfig.get_config_var('LIBPL')
412  #python_libs=[sysconfig.get_config_var('LDLIBRARY')] # only on linux      else:
413  if IS_WINDOWS:          python_lib_path=sysconfig.get_config_var('LIBDIR')
414      python_libs=['python%s%s'%(sys.version_info[0], sys.version_info[1])]  
415        #python_libs=[sysconfig.get_config_var('LDLIBRARY')] # only on linux
416        if IS_WINDOWS:
417            python_libs=['python%s%s'%(sys.version_info[0], sys.version_info[1])]
418        else:
419            python_libs=['python'+sysconfig.get_python_version()]
420    
421    #if we want to use a python other than the one scons is running
422  else:  else:
423      python_libs=['python'+sysconfig.get_python_version()]      initstring='from __future__ import print_function;from distutils import sysconfig;'
424        if env['pythonlibname']!='':
425            python_libs=env['pythonlibname']
426        else:   # work it out by calling python    
427            if IS_WINDOWS:
428                cmd='print("python%s%s"%(sys.version_info[0], sys.version_info[1]))'
429            else:
430                cmd='print("python"+sysconfig.get_python_version())'
431            p=Popen([env['pythoncmd'], '-c', initstring+cmd], stdout=PIPE)
432            python_libs=p.stdout.readline()
433            if env['usepython3']:       # This is to convert unicode str into py2 string
434                python_libs=python_libs.encode() # If scons runs on py3 then this must be rethought
435            p.wait()
436            python_libs=python_libs.strip()
437    
438      
439        # Now we know whether we are using python3 or not
440        p=Popen([env['pythoncmd'], '-c',  initstring+'print(sysconfig.get_python_inc())'], stdout=PIPE)
441        python_inc_path=p.stdout.readline()
442        if env['usepython3']:
443             python_inc_path=python_inc_path.encode()
444        p.wait()  
445        python_inc_path=python_inc_path.strip()
446        if IS_WINDOWS:
447            cmd="os.path.join(sysconfig.get_config_var('prefix'), 'libs')"
448        elif env['PLATFORM']=='darwin':
449            cmd="sysconfig.get_config_var(\"LIBPL\")"
450        else:
451            cmd="sysconfig.get_config_var(\"LIBDIR\")"
452    
453        p=Popen([env['pythoncmd'], '-c', initstring+'print('+cmd+')'], stdout=PIPE)
454        python_lib_path=p.stdout.readline()
455        if env['usepython3']:
456            python_lib_path=python_lib_path.decode()
457        p.wait()
458        python_lib_path=python_lib_path.strip()
459    
460  if sysheaderopt == '':  if sysheaderopt == '':
461      conf.env.AppendUnique(CPPPATH = [python_inc_path])      conf.env.AppendUnique(CPPPATH = [python_inc_path])
# Line 421  if not conf.CheckFunc('Py_Exit'): Line 474  if not conf.CheckFunc('Py_Exit'):
474      print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))      print("Cannot find python library method Py_Main (tried %s in directory %s)" % (python_libs, python_lib_path))
475      Exit(1)      Exit(1)
476    
477  # reuse conf to check for numpy header (optional)  ## reuse conf to check for numpy header (optional)
478  if conf.CheckCXXHeader(['Python.h','numpy/ndarrayobject.h']):  if env['usepython3']:
479      conf.env.Append(CPPDEFINES = ['HAVE_NUMPY_H'])      # FIXME: This is until we can work out how to make the checks in python 3
     conf.env['numpy_h']=True  
 else:  
480      conf.env['numpy_h']=False      conf.env['numpy_h']=False
481    else:
482        if conf.CheckCXXHeader(['Python.h','numpy/ndarrayobject.h']):
483            conf.env.Append(CPPDEFINES = ['HAVE_NUMPY_H'])
484            conf.env['numpy_h']=True
485        else:
486            conf.env['numpy_h']=False
487    
488  # Commit changes to environment  # Commit changes to environment
489  env = conf.Finish()  env = conf.Finish()
# Line 450  env.PrependENVPath(LD_LIBRARY_PATH_KEY, Line 507  env.PrependENVPath(LD_LIBRARY_PATH_KEY,
507    
508  ######## numpy (required)  ######## numpy (required)
509    
510  try:  if env['pythoncmd']=='python':
511      from numpy import identity      try:
512  except ImportError:        from numpy import identity
513      print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)      except ImportError:
514      Exit(1)        print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)
515          Exit(1)
516    else:
517        p=subprocess.call([env['pythoncmd'],'-c','import numpy'])
518        if p!=0:
519          print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)
520          Exit(1)
521    
522  ######## CppUnit (required for tests)  ######## CppUnit (required for tests)
523    
# Line 697  if env['numpy_h']: Line 760  if env['numpy_h']:
760      print("   numpy headers:  FOUND")      print("   numpy headers:  FOUND")
761  else:  else:
762      print("   numpy headers:  NOT FOUND")      print("   numpy headers:  NOT FOUND")
763    print("   vsl_random:  %s"%env['vsl_random'])
764            
765  if ((fatalwarning != '') and (env['werror'])):  if ((fatalwarning != '') and (env['werror'])):
766      print("  Treating warnings as errors")      print("  Treating warnings as errors")
# Line 742  env.SConscript(dirs = ['pycad/py_src'], Line 806  env.SConscript(dirs = ['pycad/py_src'],
806  env.SConscript(dirs = ['pythonMPI/src'], variant_dir='$BUILD_DIR/$PLATFORM/pythonMPI', duplicate=0)  env.SConscript(dirs = ['pythonMPI/src'], variant_dir='$BUILD_DIR/$PLATFORM/pythonMPI', duplicate=0)
807  env.SConscript(dirs = ['paso/profiling'], variant_dir='$BUILD_DIR/$PLATFORM/paso/profiling', duplicate=0)  env.SConscript(dirs = ['paso/profiling'], variant_dir='$BUILD_DIR/$PLATFORM/paso/profiling', duplicate=0)
808    
809    
810  ######################## Populate the buildvars file #########################  ######################## Populate the buildvars file #########################
811    
812  # remove obsolete file  # remove obsolete file
# Line 761  except StopIteration: Line 826  except StopIteration:
826      pass      pass
827  boosthpp.close()  boosthpp.close()
828    
829    
830  buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')  buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
831  buildvars.write("svn_revision="+str(global_revision)+"\n")  buildvars.write("svn_revision="+str(global_revision)+"\n")
832  buildvars.write("prefix="+prefix+"\n")  buildvars.write("prefix="+prefix+"\n")
833  buildvars.write("cc="+env['CC']+"\n")  buildvars.write("cc="+env['CC']+"\n")
834  buildvars.write("cxx="+env['CXX']+"\n")  buildvars.write("cxx="+env['CXX']+"\n")
835  buildvars.write("python="+sys.executable+"\n")  if env['pythoncmd']=='python':
836  buildvars.write("python_version="+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"\n")      buildvars.write("python="+sys.executable+"\n")
837        buildvars.write("python_version="+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"\n")
838    else:
839        buildvars.write("python="+env['pythoncmd']+"\n")
840        p=Popen([env['pythoncmd'], '-c', 'from __future__ import print_function;import sys;print(str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2]))'], stdout=PIPE)
841        verstring=p.stdout.readline().strip()
842        p.wait()
843        buildvars.write("python_version="+verstring+"\n")
844  buildvars.write("boost_inc_path="+boost_inc_path+"\n")  buildvars.write("boost_inc_path="+boost_inc_path+"\n")
845  buildvars.write("boost_lib_path="+boost_lib_path+"\n")  buildvars.write("boost_lib_path="+boost_lib_path+"\n")
846  buildvars.write("boost_version="+boostversion+"\n")  buildvars.write("boost_version="+boostversion+"\n")
# Line 807  env.Alias('install_escript', ['build_esc Line 880  env.Alias('install_escript', ['build_esc
880  env.Alias('build_pasowrap', ['install_pasowrap_headers', 'build_pasowrap_lib', 'build_pasowrapcpp_lib'])  env.Alias('build_pasowrap', ['install_pasowrap_headers', 'build_pasowrap_lib', 'build_pasowrapcpp_lib'])
881  env.Alias('install_pasowrap', ['build_pasowrap', 'install_pasowrap_lib', 'install_pasowrapcpp_lib', 'install_pasowrap_py'])  env.Alias('install_pasowrap', ['build_pasowrap', 'install_pasowrap_lib', 'install_pasowrapcpp_lib', 'install_pasowrap_py'])
882    
   
883  env.Alias('build_dudley', ['install_dudley_headers', 'build_dudley_lib', 'build_dudleycpp_lib'])  env.Alias('build_dudley', ['install_dudley_headers', 'build_dudley_lib', 'build_dudleycpp_lib'])
884  env.Alias('install_dudley', ['build_dudley', 'install_dudley_lib', 'install_dudleycpp_lib', 'install_dudley_py'])  env.Alias('install_dudley', ['build_dudley', 'install_dudley_lib', 'install_dudleycpp_lib', 'install_dudley_py'])
885    
# Line 849  install_all_list += ['install_finley'] Line 921  install_all_list += ['install_finley']
921  install_all_list += ['install_ripley']  install_all_list += ['install_ripley']
922  install_all_list += ['install_weipa']  install_all_list += ['install_weipa']
923  if not IS_WINDOWS: install_all_list += ['install_escriptreader']  if not IS_WINDOWS: install_all_list += ['install_escriptreader']
924  install_all_list += ['install_pyvisi_py']  #install_all_list += ['install_pyvisi_py']
925  install_all_list += ['install_modellib_py']  install_all_list += ['install_modellib_py']
926  install_all_list += ['install_pycad_py']  install_all_list += ['install_pycad_py']
927  if env['usempi']:   install_all_list += ['install_pythonMPI']  if env['usempi']:   install_all_list += ['install_pythonMPI']
# Line 882  if not IS_WINDOWS: Line 954  if not IS_WINDOWS:
954          for tests in TestGroups:          for tests in TestGroups:
955              utest.write(tests.makeString())              utest.write(tests.makeString())
956          utest.close()          utest.close()
957          Execute(Chmod('utest.sh', 0755))          Execute(Chmod('utest.sh', 0o755))
958          print("Generated utest.sh.")          print("Generated utest.sh.")
959      except IOError:      except IOError:
960          print("Error attempting to write unittests file.")          print("Error attempting to write unittests file.")

Legend:
Removed from v.3814  
changed lines
  Added in v.3896

  ViewVC Help
Powered by ViewVC 1.1.26