xref: /petsc/config/configure.py (revision d688700ccbe93acf68cccb84762a8d71882b0beb)
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
21da333b47SSatish Balaydef fixWin32Flinker(filename):
22da333b47SSatish Balay    '''Change CXX_FLINKER back to f90 for win32 (from cl)'''
23da333b47SSatish Balay    import fileinput
24da333b47SSatish Balay    import re
25da333b47SSatish Balay
26da333b47SSatish Balay    reglink    = re.compile('CXX_FLINKER ')
27da333b47SSatish Balay    regwin32fe = re.compile('win32fe',re.I)
28da333b47SSatish Balay    regcl      = re.compile('cl',re.I)
29da333b47SSatish Balay
30da333b47SSatish Balay    for line in fileinput.input(filename,inplace=1):
31da333b47SSatish Balay      fl = reglink.search(line)
32da333b47SSatish Balay      fw = regwin32fe.search(line)
33da333b47SSatish Balay      if fl and fw:
34da333b47SSatish Balay        line = regcl.sub('f90',line)
35da333b47SSatish Balay      print line,
36da333b47SSatish Balay    return
37da333b47SSatish Balay
385d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
395fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
405fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
415fb2c094SBarry Smith
4287282423SMatthew Knepley  # Should be run from the toplevel
435d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
4487282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
4587282423SMatthew Knepley  if not os.path.isdir(pythonDir):
465d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
4787282423SMatthew Knepley  if not os.path.isdir(bsDir):
48*d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
49*d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
504f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
517d7624c9SBarry Smith    if status:
527d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
53*d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
54*d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
55*d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
567d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
57*d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
58*d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
597d7624c9SBarry Smith      else:
60*d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
617d7624c9SBarry Smith      print output
6287282423SMatthew Knepley      sys.exit(3)
634f8a5b45SBarry Smith
6487282423SMatthew Knepley  sys.path.insert(0, bsDir)
655d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
665d5a5a7bSMatthew Knepley  import config.framework
67dd50d019SBarry Smith
684f8a5b45SBarry Smith
692c4e8892SMatthew Knepley  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
7070ae1cd5SMatthew Knepley  try:
713e4f49c0SMatthew Knepley    framework.configure(out = sys.stdout)
72358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
73da333b47SSatish Balay    fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables')
74dd50d019SBarry Smith    return 0
75e9f3bb17SBarry Smith  except RuntimeError, e:
76*d688700cSSatish Balay    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n'
77*d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
78e9f3bb17SBarry Smith    se = ''
791a02243aSBarry Smith  except TypeError, e:
80*d688700cSSatish Balay    msg = '***** Error in command line argument to configure.py *****\n'
81*d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
821a02243aSBarry Smith    se = ''
83d7d3c4beSMatthew Knepley  except SystemExit, e:
84d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
85d7d3c4beSMatthew Knepley      return
86*d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
87d7d3c4beSMatthew Knepley    se  = str(e)
88e9f3bb17SBarry Smith  except Exception, e:
89*d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
90e9f3bb17SBarry Smith    se  = str(e)
91e9f3bb17SBarry Smith
92e9f3bb17SBarry Smith  print msg
93e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
94e9f3bb17SBarry Smith    import traceback
95e9f3bb17SBarry Smith    framework.log.write(msg+se)
96e9f3bb17SBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
97e9f3bb17SBarry Smith    sys.exit(1)
985d5a5a7bSMatthew Knepley
995d5a5a7bSMatthew Knepleyif __name__ == '__main__':
100a030c540SBarry Smith  petsc_configure([])
101759acf64SBarry Smith
102