PYTHON   11

configure.py

Guest on 26th May 2021 07:44:38 PM

  1. #!/usr/bin/env python
  2. #
  3. #  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4. #  SLEPc - Scalable Library for Eigenvalue Problem Computations
  5. #  Copyright (c) 2002-2021, Universitat Politecnica de Valencia, Spain
  6. #
  7. #  This file is part of SLEPc.
  8. #  SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  9. #  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  10. #
  11.  
  12. from __future__ import print_function
  13. import os, sys, time, shutil
  14.  
  15. def WriteModulesFile(modules,version,sdir):
  16.   ''' Write the contents of the Modules file '''
  17.   modules.write('#%Module\n\n')
  18.   modules.write('proc ModulesHelp { } {\n')
  19.   modules.write('    puts stderr "This module sets the path and environment variables for slepc-%s"\n' % version)
  20.   modules.write('    puts stderr "     see https://slepc.upv.es/ for more information"\n')
  21.   modules.write('    puts stderr ""\n}\n')
  22.   modules.write('module-whatis "SLEPc - Scalable Library for Eigenvalue Problem Computations"\n\n')
  23.   modules.write('module load petsc\n')
  24.   modules.write('set slepc_dir "%s"\n' % sdir)
  25.   modules.write('setenv SLEPC_DIR "$slepc_dir"\n')
  26.  
  27. def WritePkgconfigFile(pkgconfig,version,pversion,sdir,isinstall,prefixdir,singlelib):
  28.   ''' Write the contents of the pkg-config file '''
  29.   pkgconfig.write('prefix=%s\n' % prefixdir)
  30.   pkgconfig.write('exec_prefix=${prefix}\n')
  31.   pkgconfig.write('includedir=${prefix}/include\n')
  32.   pkgconfig.write('libdir=${prefix}/lib\n\n')
  33.   pkgconfig.write('Name: SLEPc\n')
  34.   pkgconfig.write('Description: the Scalable Library for Eigenvalue Problem Computations\n')
  35.   pkgconfig.write('Version: %s\n' % version)
  36.   pkgconfig.write('Requires: PETSc >= %s\n' % pversion)
  37.   pkgconfig.write('Cflags: -I${includedir}')
  38.   if not isinstall:
  39.     pkgconfig.write(' -I'+os.path.join(sdir,'include'))
  40.   pkgconfig.write('\nLibs:')
  41.   if singlelib:
  42.     pkgconfig.write(' -L${libdir} -lslepc\n')
  43.   else:
  44.     pkgconfig.write(' -L${libdir} -lslepcnep -lslepcpep -lslepcsvd -lslepceps -lslepcmfn -lslepclme -lslepcsys\n')
  45.  
  46. def WriteReconfigScript(reconfig,slepcdir,usedargs):
  47.   ''' Write the contents of the reconfigure script '''
  48.   reconfig.write('#!/usr/bin/env python\n\n')
  49.   reconfig.write('import os, sys\n')
  50.   if usedargs:
  51.     reconfig.write('sys.argv.extend(\''+usedargs+'\'.split())\n')
  52.   reconfig.write('execfile(os.path.join(\''+slepcdir+'\',\'config\',\'configure.py\'))\n')
  53.  
  54. # Use en_US as language so that compiler messages are in English
  55. def fixLang(lang):
  56.   if lang in os.environ and os.environ[lang] != '':
  57.     lv = os.environ[lang]
  58.     enc = ''
  59.     try: lv,enc = lv.split('.')
  60.     except: pass
  61.     if lv not in ['en_US','C']: lv = 'en_US'
  62.     if enc: lv = lv+'.'+enc
  63.     os.environ[lang] = lv
  64.  
  65. fixLang('LC_LOCAL')
  66. fixLang('LANG')
  67.  
  68. # Set python path
  69. configdir = os.path.abspath('config')
  70. if not os.path.isdir(configdir):
  71.   sys.exit('ERROR: Run configure from $SLEPC_DIR, not '+os.path.abspath('.'))
  72. sys.path.insert(0,configdir)
  73. sys.path.insert(0,os.path.join(configdir,'packages'))
  74.  
  75. # Load auxiliary classes
  76. import argdb, log
  77. argdb = argdb.ArgDB(sys.argv)
  78. log   = log.Log()
  79.  
  80. showhelp = argdb.PopHelp()
  81.  
  82. # Load main classes, process the corresponding command-line options
  83. import slepc, petsc
  84. slepc = slepc.SLEPc(argdb,log)
  85. petsc = petsc.PETSc(argdb,log)
  86.  
  87. # Check enviroment and PETSc version
  88. if not showhelp:
  89.   log.Print('Checking environment...')
  90.   petsc.InitDir(slepc.prefixdir)
  91.   petsc.LoadVersion()
  92. slepc.InitDir()
  93. slepc.LoadVersion()
  94.  
  95. # Load PETSc configuration
  96. if not showhelp:
  97.   petsc.LoadConf()
  98.   packagesinpetsc = petsc.packages
  99. else:
  100.   packagesinpetsc = ''
  101.  
  102. # Load classes for packages and process their command-line options
  103. import arpack, blopex, blzpack, elemental, elpa, evsl, feast, hpddm, primme, scalapack, slepc4py, slicot, trlan, sowing, lapack
  104. arpack    = arpack.Arpack(argdb,log)
  105. blopex    = blopex.Blopex(argdb,log)
  106. blzpack   = blzpack.Blzpack(argdb,log)
  107. elemental = elemental.Elemental(argdb,log,packagesinpetsc)
  108. elpa      = elpa.Elpa(argdb,log)
  109. evsl      = evsl.Evsl(argdb,log)
  110. feast     = feast.Feast(argdb,log,packagesinpetsc)
  111. primme    = primme.Primme(argdb,log)
  112. trlan     = trlan.Trlan(argdb,log)
  113. sowing    = sowing.Sowing(argdb,log)
  114. lapack    = lapack.Lapack(argdb,log)
  115. scalapack = scalapack.Scalapack(argdb,log,packagesinpetsc)
  116. slepc4py  = slepc4py.Slepc4py(argdb,log)
  117. slicot    = slicot.Slicot(argdb,log)
  118. hpddm     = hpddm.HPDDM(argdb,log)
  119.  
  120. externalpackages = [arpack, blopex, blzpack, elpa, evsl, hpddm, primme, slicot, trlan]
  121. petscpackages    = [lapack, elemental, feast, scalapack]
  122. specialpackages  = [slepc, petsc, slepc4py, sowing]
  123. checkpackages    = specialpackages + petscpackages + externalpackages
  124.  
  125. # Print help if requested and check for wrong command-line options
  126. if showhelp:
  127.   print('\nConfiguration script for SLEPc '+slepc.version)
  128.   print('\nUsage: ./configure [OPTION]...\n')
  129.   print('  Brackets indicate an optional part')
  130.   print('  <bool> means a boolean, use either 0 or 1')
  131.   print('  <dir> means a directory')
  132.   print('  <fname> means a file name, can also include the full path or url')
  133.   print('  <libraries> means a comma-separated list of libraries, e.g., --with-arpack-lib=-lparpack,-larpack')
  134.   print('  <flags> means a string of flags, e.g., --download-primme-cflags="-std=c99 -g"')
  135.   for pkg in specialpackages:
  136.     pkg.ShowHelp()
  137.   print('\nOptional packages via PETSc (these are tested by default if present in PETSc\'s configuration):\n')
  138.   for pkg in petscpackages:
  139.     pkg.ShowHelp()
  140.   print('\nOptional packages (external):\n')
  141.   for pkg in externalpackages:
  142.     pkg.ShowHelp()
  143.   print('')
  144.   sys.exit(0)
  145. argdb.ErrorPetscOptions()
  146. argdb.ErrorIfNotEmpty()
  147.  
  148. # Check if packages-download directory contains requested packages
  149. if slepc.downloaddir:
  150.   l = list(filter(None, [pkg.MissingTarball(slepc.downloaddir) for pkg in externalpackages + [sowing]]))
  151.   if l:
  152.     log.Println('\n\nDownload the following packages and run the script again:')
  153.     for pkg in l: log.Println(pkg)
  154.     log.Exit('Missing files in packages-download directory')
  155.  
  156. # Create directories for configuration files
  157. archdir, archdirexisted = slepc.CreateDirTest(slepc.dir,petsc.archname)
  158. libdir  = slepc.CreateDir(archdir,'lib')
  159. confdir = slepc.CreateDirTwo(libdir,'slepc','conf')
  160.  
  161. # Open log file
  162. log.Open(slepc.dir,confdir,'configure.log')
  163. log.write('='*80)
  164. log.write('Starting Configure Run at '+time.ctime(time.time()))
  165. log.write('Configure Options: '+' '.join(sys.argv[1:]))
  166. log.write('Working directory: '+os.getcwd())
  167. log.write('Python version:\n'+sys.version)
  168. log.write('make: '+petsc.make)
  169.  
  170. # Some checks related to PETSc configuration
  171. if petsc.nversion < slepc.nversion:
  172.   log.Exit('This SLEPc version is not compatible with PETSc version '+petsc.version)
  173. if not petsc.precision in ['double','single','__float128']:
  174.   log.Exit('This SLEPc version does not work with '+petsc.precision+' precision')
  175.  
  176. # Display versions and paths
  177. log.write('PETSc source directory: '+petsc.dir)
  178. log.write('PETSc install directory: '+petsc.prefixdir)
  179. log.write('PETSc version: '+petsc.lversion)
  180. if not petsc.isinstall:
  181.   log.write('PETSc architecture: '+petsc.arch)
  182. log.write('SLEPc source directory: '+slepc.dir)
  183. if slepc.isinstall:
  184.   log.write('SLEPc install directory: '+slepc.prefixdir)
  185. log.write('SLEPc version: '+slepc.lversion)
  186.  
  187. # Clean previous configuration if needed
  188. if archdirexisted:
  189.   if slepc.isinstall and not slepc.clean:
  190.     log.Exit('You are requesting a prefix install but the arch directory '+archdir+' already exists and may contain files from previous builds; consider adding option --with-clean')
  191.   try:
  192.     os.unlink(os.path.join(confdir,'files'))
  193.   except: pass
  194.   if slepc.clean:
  195.     log.Println('\nCleaning arch dir '+archdir+'...')
  196.     try:
  197.       for root, dirs, files in os.walk(archdir,topdown=False):
  198.         for name in files:
  199.           if name!='configure.log':
  200.             os.remove(os.path.join(root,name))
  201.     except:
  202.       log.Exit('Cannot remove existing files in '+archdir)
  203.     for rdir in ['obj','externalpackages']:
  204.       try:
  205.         shutil.rmtree(os.path.join(archdir,rdir))
  206.       except: pass
  207.  
  208. # Write main configuration files
  209. if not slepc.prefixdir:
  210.   slepc.prefixdir = archdir
  211. includedir = slepc.CreateDir(archdir,'include')
  212. with slepc.CreateFile(confdir,'slepcvariables') as slepcvars, \
  213.      slepc.CreateFile(confdir,'slepcrules') as slepcrules, \
  214.      slepc.CreateFile(includedir,'slepcconf.h') as slepcconf:
  215.   for pkg in checkpackages:
  216.     pkg.Process(slepcconf,slepcvars,slepcrules,slepc,petsc,archdir)
  217.   slepcconf.write('\n#endif\n')
  218.  
  219. log.NewSection('Writing various configuration files...')
  220.  
  221. # Create global configuration file for the case of empty PETSC_ARCH
  222. if petsc.isinstall:
  223.   with slepc.CreateFile(os.path.join(slepc.dir,'lib','slepc','conf'),'slepcvariables') as globconf:
  224.     globconf.write('SLEPC_DIR = '+slepc.dir+'\n')
  225.     globconf.write('PETSC_ARCH = '+petsc.archname+'\n')
  226.  
  227. # Write Modules configuration file
  228. modulesdir = slepc.CreateDirTwo(confdir,'modules','slepc')
  229. log.write('Modules file in '+modulesdir)
  230. with slepc.CreateFile(modulesdir,slepc.lversion) as modules:
  231.   WriteModulesFile(modules,slepc.lversion,slepc.prefixdir if slepc.isinstall else slepc.dir)
  232.  
  233. # Write pkg-config configuration file
  234. pkgconfdir = slepc.CreateDir(libdir,'pkgconfig')
  235. log.write('pkg-config file in '+pkgconfdir)
  236. with slepc.CreateFile(pkgconfdir,'slepc.pc') as pkgconfig:
  237.   WritePkgconfigFile(pkgconfig,slepc.lversion,petsc.version,slepc.dir,slepc.isinstall,slepc.prefixdir,petsc.singlelib)
  238.  
  239. # Write reconfigure file
  240. if not slepc.isinstall:
  241.   log.write('Reconfigure file in '+confdir)
  242.   with slepc.CreateFile(confdir,'reconfigure-'+petsc.archname+'.py') as reconfig:
  243.     WriteReconfigScript(reconfig,slepc.dir,argdb.UsedArgs())
  244.   try:
  245.     os.chmod(os.path.join(confdir,'reconfigure-'+petsc.archname+'.py'),0o775)
  246.   except OSError as e:
  247.     log.Exit('Unable to make reconfigure script executable:\n'+str(e))
  248.  
  249. # Print summary
  250. log.NewSection('')
  251. log.Println('')
  252. log.Println('='*80)
  253. log.Println('SLEPc Configuration')
  254. log.Println('='*80)
  255. for pkg in checkpackages:
  256.   pkg.ShowInfo()
  257. log.write('\nFinishing Configure Run at '+time.ctime(time.time()))
  258. log.write('='*80)
  259. print()
  260. print('xxx'+'='*74+'xxx')
  261. print(' Configure stage complete. Now build the SLEPc library with:')
  262. if petsc.isinstall:
  263.   print('   make SLEPC_DIR='+slepc.dir+' PETSC_DIR='+petsc.dir)
  264. else:
  265.   print('   make SLEPC_DIR='+slepc.dir+' PETSC_DIR='+petsc.dir+' PETSC_ARCH='+petsc.archname)
  266. print('xxx'+'='*74+'xxx')
  267. print()

Raw Paste


Login or Register to edit or fork this paste. It's free.