xref: /petsc/config/configure.py (revision 5fb2c094576d6d7df91b2a8fbf3938a63473b066)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
55d5a5a7bSMatthew Knepley
64b8aa89bSBarry Smith
72fb34ac0SMatthew Knepleyif not hasattr(sys, 'version_info'):
82fb34ac0SMatthew Knepley  raise RuntimeError('You must have Python version 2.2 or higher to run configure')
92fb34ac0SMatthew Knepley
104b8aa89bSBarry Smithdef getarch():
11*5fb2c094SBarry Smith  return os.path.basename(sys.argv[0])[10:-3]
124b8aa89bSBarry Smith
135d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
14*5fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
15*5fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
16*5fb2c094SBarry Smith
175d5a5a7bSMatthew Knepley  # Should be run from the toplevel or from ./config
185d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('..', 'python'))
195d5a5a7bSMatthew Knepley  if not os.path.exists(pythonDir):
205d5a5a7bSMatthew Knepley    pythonDir = os.path.abspath(os.path.join('python'))
215d5a5a7bSMatthew Knepley    if not os.path.exists(pythonDir):
225d5a5a7bSMatthew Knepley      raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
234f8a5b45SBarry Smith
244f8a5b45SBarry Smith  if not os.path.isdir('python/BuildSystem'):
254f8a5b45SBarry Smith    print '''Could not locate BuildSystem in $PETSC_DIR/python.
264f8a5b45SBarry Smith    Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
274f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
284f8a5b45SBarry Smith
295d5a5a7bSMatthew Knepley  sys.path.insert(0, os.path.join(pythonDir, 'BuildSystem'))
305d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
315d5a5a7bSMatthew Knepley  import config.framework
32dd50d019SBarry Smith  import PETSc.packages.update
33dd50d019SBarry Smith
344f8a5b45SBarry Smith
352c4e8892SMatthew Knepley  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
365d5a5a7bSMatthew Knepley  framework.argDB['CPPFLAGS'] = ''
375d5a5a7bSMatthew Knepley  framework.argDB['LIBS'] = ''
3870ae1cd5SMatthew Knepley  try:
393e4f49c0SMatthew Knepley    framework.configure(out = sys.stdout)
40dd50d019SBarry Smith  except PETSc.packages.update.UpdateException, e:
41dd50d019SBarry Smith    return 1
4270ae1cd5SMatthew Knepley  except Exception, e:
4370ae1cd5SMatthew Knepley    import traceback
4470ae1cd5SMatthew Knepley
4543c77886SBarry Smith    msg = 'CONFIGURATION FAILURE (see configure.log for full details):\n'+str(e)+'\n'
4670ae1cd5SMatthew Knepley    print msg
473bd70c20SMatthew Knepley    if hasattr(framework, 'log'):
4870ae1cd5SMatthew Knepley      framework.log.write(msg)
4970ae1cd5SMatthew Knepley      traceback.print_tb(sys.exc_info()[2], file = framework.log)
5070ae1cd5SMatthew Knepley    sys.exit(1)
51358ebc22SMatthew Knepley  framework.storeSubstitutions(framework.argDB)
52234db7c0SBarry Smith
53234db7c0SBarry Smith  # save the jobs that should be run by the PETSc buildtest
54234db7c0SBarry Smith  fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'jobs')),'w')
55234db7c0SBarry Smith  jobs = []
56234db7c0SBarry Smith  if framework.usingMPIUni:
57234db7c0SBarry Smith    jobs.append('4')
58234db7c0SBarry Smith    if 'FC' in framework.argDB:jobs.append('9')
59234db7c0SBarry Smith  else:
60234db7c0SBarry Smith    jobs.append('1')
61234db7c0SBarry Smith    if 'FC' in framework.argDB:jobs.append('3')
62234db7c0SBarry Smith    if framework.foundX11:jobs.append('2')
63234db7c0SBarry Smith  fd.write(' '.join(jobs)+'\n')
64234db7c0SBarry Smith  fd.close()
65234db7c0SBarry Smith  fd = open(os.path.abspath(os.path.join('bmake',framework.argDB['PETSC_ARCH'],'ejobs')),'w')
66234db7c0SBarry Smith  fd.write(' ')
67234db7c0SBarry Smith  fd.close()
68dd50d019SBarry Smith  return 0
695d5a5a7bSMatthew Knepley
705d5a5a7bSMatthew Knepleyif __name__ == '__main__':
7155ca06a9SBarry Smith  for opt in sys.argv[1:]:
7255ca06a9SBarry Smith    if opt.startswith('--prefix') or opt.startswith('-prefix'):
7355ca06a9SBarry Smith      print '=====================================================================\nPETSc does NOT support the --prefix options. All installs are done in-place.\nMove your petsc directory to the location you wish it installed, before running configure\n'
7455ca06a9SBarry Smith      sys.exit(1)
75dd50d019SBarry Smith  if petsc_configure([]):
76b186f651SBarry Smith    print 'Updated the source code, rerunning configure'
775d5a5a7bSMatthew Knepley    petsc_configure([])
78