PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hpc_kernel_samples/sparse_linear_algebra/casestudies/pagerank-petsc/petsc-2.3.2-p10/config/configure.py

https://gitlab.com/pheinzlr/CodeVault
Python | 244 lines | 221 code | 12 blank | 11 comment | 37 complexity | 298445ca2bb2e566e2db652f203c66e7 MD5 | raw file
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. import commands
  5. # to load ~/.pythonrc.py before inserting correct BuildSystem to path
  6. import user
  7. if not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2:
  8. print '**** You must have Python version 2.2 or higher to run config/configure.py ******'
  9. print '* Python is easy to install for end users or sys-admin. *'
  10. print '* http://www.python.org/download/ *'
  11. print '* *'
  12. print '* You CANNOT configure PETSc without Python *'
  13. print '* http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html *'
  14. print '*********************************************************************************'
  15. sys.exit(4)
  16. def check_petsc_arch(opts):
  17. # If PETSC_ARCH not specified - use script name (if not configure.py)
  18. found = 0
  19. for name in opts:
  20. if name.find('PETSC_ARCH=') >= 0:
  21. found = 1
  22. break
  23. # If not yet specified - use the filename of script
  24. if not found:
  25. filename = os.path.basename(sys.argv[0])
  26. if not filename.startswith('configure') and not filename.startswith('reconfigure'):
  27. useName = 'PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
  28. opts.append(useName)
  29. return
  30. def chkcygwin():
  31. if os.path.exists('/usr/bin/cygcheck.exe'):
  32. buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
  33. if buf.find('1.5.11-1') > -1:
  34. return 1
  35. else:
  36. return 0
  37. return 0
  38. def chkcygwinpython():
  39. if os.path.exists('/usr/bin/cygcheck.exe'):
  40. buf = os.popen('/usr/bin/cygcheck.exe -c python').read()
  41. if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1):
  42. return 1
  43. else:
  44. return 0
  45. return 0
  46. def rhl9():
  47. try:
  48. file = open('/etc/redhat-release','r')
  49. except:
  50. return 0
  51. try:
  52. buf = file.read()
  53. file.close()
  54. except:
  55. # can't read file - assume dangerous RHL9
  56. return 1
  57. if buf.find('Shrike') > -1:
  58. return 1
  59. else:
  60. return 0
  61. def petsc_configure(configure_options):
  62. print '================================================================================='
  63. print ' Configuring PETSc to compile on your system '
  64. print '================================================================================='
  65. # Command line arguments take precedence (but don't destroy argv[0])
  66. sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
  67. # check PETSC_ARCH
  68. check_petsc_arch(sys.argv)
  69. extraLogs = []
  70. # support a few standard configure option types
  71. for l in range(0,len(sys.argv)):
  72. name = sys.argv[l]
  73. if name.find('enable-') >= 0:
  74. sys.argv[l] = name.replace('enable-','with-')
  75. if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=1'
  76. if name.find('disable-') >= 0:
  77. sys.argv[l] = name.replace('disable-','with-')
  78. if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0'
  79. elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
  80. if name.find('without-') >= 0:
  81. sys.argv[l] = name.replace('without-','with-')
  82. if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0'
  83. elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
  84. # Check for sudo
  85. if os.getuid() == 0:
  86. print '================================================================================='
  87. print ' *** Do not run configure as root, or using sudo. ***'
  88. print ' ***** That should be reserved for installation *****'
  89. print '================================================================================='
  90. sys.exit(3)
  91. # Check for broken cygwin
  92. if chkcygwin():
  93. print '================================================================================='
  94. print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version ***'
  95. print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can ***'
  96. print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
  97. print '================================================================================='
  98. sys.exit(3)
  99. # Disable threads on RHL9
  100. if rhl9():
  101. sys.argv.append('--useThreads=0')
  102. extraLogs.append('''\
  103. ================================================================================
  104. *** RHL9 detected. Threads do not work correctly with this distribution ***
  105. ****** Disabling thread usage for this run of config/configure.py *******
  106. ================================================================================''')
  107. # Threads don't work for cygwin & python-2.4
  108. if chkcygwinpython():
  109. sys.argv.append('--useThreads=0')
  110. extraLogs.append('''\
  111. ================================================================================
  112. ** Cygwin-python-2.4 detected. Threads do not work correctly with this version *
  113. ********* Disabling thread usage for this run of config/configure.py **********
  114. ================================================================================''')
  115. # Should be run from the toplevel
  116. pythonDir = os.path.abspath(os.path.join('python'))
  117. bsDir = os.path.join(pythonDir, 'BuildSystem')
  118. if not os.path.isdir(pythonDir):
  119. raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
  120. if not os.path.isdir(bsDir):
  121. print '================================================================================='
  122. print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
  123. print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
  124. print '================================================================================='
  125. (status,output) = commands.getstatusoutput('hg clone http://hg.mcs.anl.gov/petsc/BuildSystem python/BuildSystem')
  126. if status:
  127. if output.find('ommand not found') >= 0:
  128. print '================================================================================='
  129. print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is in your path'''
  130. print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
  131. print '''** you do have hg installed and can clone BuildSystem. '''
  132. print '================================================================================='
  133. elif output.find('Cannot resolve host') >= 0:
  134. print '================================================================================='
  135. print '''** Unable to download BuildSystem. You must be off the network.'''
  136. print '''** Connect to the internet and run config/configure.py again.'''
  137. print '================================================================================='
  138. else:
  139. print '================================================================================='
  140. print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
  141. print '================================================================================='
  142. print output
  143. sys.exit(3)
  144. sys.path.insert(0, bsDir)
  145. sys.path.insert(0, pythonDir)
  146. import config.base
  147. import config.framework
  148. import cPickle
  149. # Disable shared libraries by default
  150. import nargs
  151. if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None:
  152. sys.argv.append('--with-shared=0')
  153. framework = None
  154. try:
  155. framework = config.framework.Framework(sys.argv[1:]+['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions'], loadArgDB = 0)
  156. framework.setup()
  157. framework.logPrint('\n'.join(extraLogs))
  158. framework.configure(out = sys.stdout)
  159. framework.storeSubstitutions(framework.argDB)
  160. framework.argDB['configureCache'] = cPickle.dumps(framework)
  161. import PETSc.packages
  162. for i in framework.packages:
  163. if hasattr(i,'postProcess'):
  164. i.postProcess()
  165. framework.logClear()
  166. return 0
  167. except (RuntimeError, config.base.ConfigureSetupError), e:
  168. emsg = str(e)
  169. if not emsg.endswith('\n'): emsg = emsg+'\n'
  170. msg ='*********************************************************************************\n'\
  171. +' UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):\n' \
  172. +'---------------------------------------------------------------------------------------\n' \
  173. +emsg+'*********************************************************************************\n'
  174. se = ''
  175. except (TypeError, ValueError), e:
  176. emsg = str(e)
  177. if not emsg.endswith('\n'): emsg = emsg+'\n'
  178. msg ='*********************************************************************************\n'\
  179. +' ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
  180. +'---------------------------------------------------------------------------------------\n' \
  181. +emsg+'*********************************************************************************\n'
  182. se = ''
  183. except ImportError, e :
  184. emsg = str(e)
  185. if not emsg.endswith('\n'): emsg = emsg+'\n'
  186. msg ='*********************************************************************************\n'\
  187. +' UNABLE to FIND MODULE for config/configure.py \n' \
  188. +'---------------------------------------------------------------------------------------\n' \
  189. +emsg+'*********************************************************************************\n'
  190. se = ''
  191. except SystemExit, e:
  192. if e.code is None or e.code == 0:
  193. return
  194. msg ='*********************************************************************************\n'\
  195. +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
  196. +'*********************************************************************************\n'
  197. se = str(e)
  198. except Exception, e:
  199. msg ='*********************************************************************************\n'\
  200. +' CONFIGURATION CRASH (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
  201. +'*********************************************************************************\n'
  202. se = str(e)
  203. print msg
  204. if not framework is None:
  205. framework.logClear()
  206. if hasattr(framework, 'log'):
  207. import traceback
  208. framework.log.write(msg+se)
  209. traceback.print_tb(sys.exc_info()[2], file = framework.log)
  210. if os.path.isfile(framework.logName+'.bkp'):
  211. if framework.debugIndent is None:
  212. framework.debugIndent = ' '
  213. framework.logPrintDivider()
  214. framework.logPrintBox('Previous configure logs below', debugSection = None)
  215. f = file(framework.logName+'.bkp')
  216. framework.log.write(f.read())
  217. f.close()
  218. sys.exit(1)
  219. else:
  220. print se
  221. import traceback
  222. traceback.print_tb(sys.exc_info()[2])
  223. if __name__ == '__main__':
  224. petsc_configure([])