xref: /petsc/config/configure.py (revision c7f9034b40a117fec0c00e26d6e2e10075724bfa)
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
219dabcff0SSatish Balaydef chkcygwin():
229dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
239dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
249dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
259dabcff0SSatish Balay      return 1
269dabcff0SSatish Balay    else:
279dabcff0SSatish Balay      return 0
289dabcff0SSatish Balay  return 0
299dabcff0SSatish Balay
30836c2c52SSatish Balaydef rhl9():
31836c2c52SSatish Balay  try:
32594eb360SSatish Balay    file = open('/etc/redhat-release','r')
33836c2c52SSatish Balay  except:
34836c2c52SSatish Balay    return 0
35836c2c52SSatish Balay  try:
36836c2c52SSatish Balay    buf = file.read()
37836c2c52SSatish Balay    file.close()
38836c2c52SSatish Balay  except:
39836c2c52SSatish Balay    # can't read file - assume dangerous RHL9
40836c2c52SSatish Balay    return 1
41836c2c52SSatish Balay  if buf.find('Shrike') > -1:
42836c2c52SSatish Balay    return 1
43836c2c52SSatish Balay  else:
44836c2c52SSatish Balay    return 0
45836c2c52SSatish Balay
46da333b47SSatish Balaydef fixWin32Flinker(filename):
47*c7f9034bSKris Buschelman    '''Change CXX_FLINKER back to C_FLINKER for win32 (from cl or icl)'''
48da333b47SSatish Balay    import fileinput
49da333b47SSatish Balay    import re
50da333b47SSatish Balay
51da333b47SSatish Balay    reglink    = re.compile('CXX_FLINKER ')
52*c7f9034bSKris Buschelman    regwin32fe = re.compile(r"""\b(win32fe\s+(cl|icl))""",re.I)
53da333b47SSatish Balay
54da333b47SSatish Balay    for line in fileinput.input(filename,inplace=1):
55da333b47SSatish Balay      fl = reglink.search(line)
56da333b47SSatish Balay      fw = regwin32fe.search(line)
57da333b47SSatish Balay      if fl and fw:
58*c7f9034bSKris Buschelman        line = 'CXX_FLINKER        = ${C_FLINKER}\n'
59da333b47SSatish Balay      print line,
60da333b47SSatish Balay    return
61da333b47SSatish Balay
625d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
635fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
645fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
655fb2c094SBarry Smith
66836c2c52SSatish Balay  # Disable threads on RHL9
67836c2c52SSatish Balay  if rhl9():
68f1365dfbSSatish Balay    sys.argv.append('--useThreads=0')
69836c2c52SSatish Balay    print ' *** RHL9 detected. Disabling threads in configure *****'
70836c2c52SSatish Balay
719dabcff0SSatish Balay  # Check for broken cygwin
729dabcff0SSatish Balay  if chkcygwin():
739dabcff0SSatish Balay    print ' *** cygwin-1.5.11-1 detected. configure fails with this version   ***'
749dabcff0SSatish Balay    print ' *** Please downgrade to cygwin-1.5.10-3. This can be done by      ***'
759dabcff0SSatish Balay    print ' *** running cygwin setup, and in "up to date" view - click on the ***'
769dabcff0SSatish Balay    print ' *** "cirular arrow" next to "cygwin" until it changes to 1.5.10-3.***'
779dabcff0SSatish Balay    sys.exit(3)
789dabcff0SSatish Balay
7987282423SMatthew Knepley  # Should be run from the toplevel
805d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
8187282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
8287282423SMatthew Knepley  if not os.path.isdir(pythonDir):
835d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
8487282423SMatthew Knepley  if not os.path.isdir(bsDir):
85d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
86d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
874f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
887d7624c9SBarry Smith    if status:
897d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
90d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
91d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
92d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
937d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
94d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
95d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
967d7624c9SBarry Smith      else:
97d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
987d7624c9SBarry Smith      print output
9987282423SMatthew Knepley      sys.exit(3)
1004f8a5b45SBarry Smith
10187282423SMatthew Knepley  sys.path.insert(0, bsDir)
1025d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1035d5a5a7bSMatthew Knepley  import config.framework
104dd50d019SBarry Smith
1054f8a5b45SBarry Smith
1062c4e8892SMatthew Knepley  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
10770ae1cd5SMatthew Knepley  try:
1083e4f49c0SMatthew Knepley    framework.configure(out = sys.stdout)
109358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
110da333b47SSatish Balay    fixWin32Flinker('bmake/'+framework.argDB['PETSC_ARCH']+'/variables')
111dd50d019SBarry Smith    return 0
112e9f3bb17SBarry Smith  except RuntimeError, e:
11366b9a547SSatish Balay    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
114d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
115e9f3bb17SBarry Smith    se = ''
1161a02243aSBarry Smith  except TypeError, e:
11766b9a547SSatish Balay    msg = '***** Error in command line argument to configure.py *****\n' \
118d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
1191a02243aSBarry Smith    se = ''
120d7d3c4beSMatthew Knepley  except SystemExit, e:
121d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
122d7d3c4beSMatthew Knepley      return
123d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
124d7d3c4beSMatthew Knepley    se  = str(e)
125e9f3bb17SBarry Smith  except Exception, e:
126d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
127e9f3bb17SBarry Smith    se  = str(e)
128e9f3bb17SBarry Smith
129e9f3bb17SBarry Smith  print msg
130e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
131e9f3bb17SBarry Smith    import traceback
132e9f3bb17SBarry Smith    framework.log.write(msg+se)
133e9f3bb17SBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
134e9f3bb17SBarry Smith    sys.exit(1)
1355d5a5a7bSMatthew Knepley
1365d5a5a7bSMatthew Knepleyif __name__ == '__main__':
137a030c540SBarry Smith  petsc_configure([])
138759acf64SBarry Smith
139