xref: /petsc/config/configure.py (revision f24f64fefd1e9c553700f694dc527db92ef3c14d)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
55d5a5a7bSMatthew Knepley
64b8aa89bSBarry Smith
7b26a8723SBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2:
832077d6dSBarry Smith  print '********* You must have Python version 2.2 or higher to run configure ***********'
932077d6dSBarry Smith  print '* Python is easy to install for end users or sys-admin. We urge you to upgrade  *'
1032077d6dSBarry Smith  print '*                   http://www.python.org/download/                             *'
1132077d6dSBarry Smith  print '*                                                                               *'
1232077d6dSBarry Smith  print '* You can configure PETSc manually BUT please, please consider upgrading python *'
1332077d6dSBarry Smith  print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual   *'
1432077d6dSBarry Smith  print '*********************************************************************************'
15b26a8723SBarry Smith  sys.exit(4)
162fb34ac0SMatthew Knepley
174b8aa89bSBarry Smithdef getarch():
1864382af2SBarry Smith  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
19b88bae4cSBarry Smith  else: return os.path.basename(sys.argv[0])[:-3]
204b8aa89bSBarry Smith
215d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
225fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
235fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
245fb2c094SBarry Smith
2587282423SMatthew Knepley  # Should be run from the toplevel
265d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
2787282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
2887282423SMatthew Knepley  if not os.path.isdir(pythonDir):
295d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
3087282423SMatthew Knepley  if not os.path.isdir(bsDir):
31d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
32d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
334f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
347d7624c9SBarry Smith    if status:
357d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
36d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
37d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
38d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
397d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
40d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
41d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
427d7624c9SBarry Smith      else:
43d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
447d7624c9SBarry Smith      print output
4587282423SMatthew Knepley      sys.exit(3)
464f8a5b45SBarry Smith
4787282423SMatthew Knepley  sys.path.insert(0, bsDir)
485d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
495d5a5a7bSMatthew Knepley  import config.framework
50f56be888SMatthew Knepley  import cPickle
514f8a5b45SBarry Smith
52*f24f64feSBarry Smith  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
5370ae1cd5SMatthew Knepley  try:
54*f24f64feSBarry Smith    framework.configure(out = sys.stdout)
55358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
56f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
57dd50d019SBarry Smith    return 0
58e9f3bb17SBarry Smith  except RuntimeError, e:
5966b9a547SSatish Balay    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
60d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
61e9f3bb17SBarry Smith    se = ''
621a02243aSBarry Smith  except TypeError, e:
6366b9a547SSatish Balay    msg = '***** Error in command line argument to configure.py *****\n' \
64d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
651a02243aSBarry Smith    se = ''
6696dc2fe8SMatthew Knepley  except ImportError, e:
6796dc2fe8SMatthew Knepley    msg = '******* Unable to find module for configure.py *******\n' \
6896dc2fe8SMatthew Knepley    +str(e)+'\n******************************************************\n'
6996dc2fe8SMatthew Knepley    se = ''
70d7d3c4beSMatthew Knepley  except SystemExit, e:
71d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
72d7d3c4beSMatthew Knepley      return
73d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
74d7d3c4beSMatthew Knepley    se  = str(e)
75e9f3bb17SBarry Smith  except Exception, e:
76d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
77e9f3bb17SBarry Smith    se  = str(e)
78e9f3bb17SBarry Smith
79e9f3bb17SBarry Smith  print msg
80e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
81f6614063SBarry Smith    import traceback
82*f24f64feSBarry Smith    framework.log.write(msg+se)
83*f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
84e9f3bb17SBarry Smith    sys.exit(1)
855d5a5a7bSMatthew Knepley
865d5a5a7bSMatthew Knepleyif __name__ == '__main__':
87a030c540SBarry Smith  petsc_configure([])
88759acf64SBarry Smith
89