xref: /petsc/config/configure.py (revision 7d670a3c49d627dc1b4fd2fe2cbdc0a8b12b3cd9)
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
465d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
470f66a136SSatish Balay  # If PETSC_ARCH not already defined, check if the script name is different then configure
480f66a136SSatish Balay  # (if so, use this name). Or else - get a  name of the config/configure_arch.py
490f66a136SSatish Balay  found = 0
500f66a136SSatish Balay  for name in configure_options:
510f66a136SSatish Balay    if name.startswith('-PETSC_ARCH'):
520f66a136SSatish Balay      found = 1
530f66a136SSatish Balay      break
540f66a136SSatish Balay  if not found and getarch(): configure_options.append('-PETSC_ARCH='+getarch())
555fb2c094SBarry Smith
56c22cdea9SBarry Smith  # support a few standard configure option types
57c22cdea9SBarry Smith  for l in range(0,len(sys.argv)-1):
58c22cdea9SBarry Smith    name = sys.argv[l]
59c22cdea9SBarry Smith    if name.startswith('--enable'):
60c22cdea9SBarry Smith      sys.argv[l] = name.replace('--enable','--with')
61c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=1'
62c22cdea9SBarry Smith    if name.startswith('--disable'):
63c22cdea9SBarry Smith      sys.argv[l] = name.replace('--disable','--with')
64c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
65c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
66c22cdea9SBarry Smith    if name.startswith('--without'):
67c22cdea9SBarry Smith      sys.argv[l] = name.replace('--without','--with')
68c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
69c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
70c22cdea9SBarry Smith
71836c2c52SSatish Balay  # Disable threads on RHL9
72836c2c52SSatish Balay  if rhl9():
73f1365dfbSSatish Balay    sys.argv.append('--useThreads=0')
74*7d670a3cSBarry Smith    print ' *** RHL9 detected. Threads do not work correctly with this distribution ***'
75*7d670a3cSBarry Smith    print ' ******** Disabling thread usage for this run of config/configure.py *****'
76836c2c52SSatish Balay
779dabcff0SSatish Balay  # Check for broken cygwin
789dabcff0SSatish Balay  if chkcygwin():
79*7d670a3cSBarry Smith    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
801e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
811e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
829dabcff0SSatish Balay    sys.exit(3)
839dabcff0SSatish Balay
8487282423SMatthew Knepley  # Should be run from the toplevel
855d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
8687282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
8787282423SMatthew Knepley  if not os.path.isdir(pythonDir):
885d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
8987282423SMatthew Knepley  if not os.path.isdir(bsDir):
90d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
91d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
924f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
937d7624c9SBarry Smith    if status:
947d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
95d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
96d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
97d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
987d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
99d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
100d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
1017d7624c9SBarry Smith      else:
102d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
1037d7624c9SBarry Smith      print output
10487282423SMatthew Knepley      sys.exit(3)
1054f8a5b45SBarry Smith
10687282423SMatthew Knepley  sys.path.insert(0, bsDir)
1075d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1085d5a5a7bSMatthew Knepley  import config.framework
109f56be888SMatthew Knepley  import cPickle
1104f8a5b45SBarry Smith
11152e6d16bSBarry Smith  print '================================================================================='
11252e6d16bSBarry Smith  print '             Configuring PETSc to compile on your system                         '
11352e6d16bSBarry Smith  print '================================================================================='
114f24f64feSBarry Smith  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options, loadArgDB = 0)
11570ae1cd5SMatthew Knepley  try:
116f24f64feSBarry Smith    framework.configure(out = sys.stdout)
117358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
118f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
119dd50d019SBarry Smith    return 0
120e9f3bb17SBarry Smith  except RuntimeError, e:
121*7d670a3cSBarry Smith    emsg = str(e)
122*7d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
123*7d670a3cSBarry Smith    msg = '     UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
124*7d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
125e9f3bb17SBarry Smith    se = ''
1261a02243aSBarry Smith  except TypeError, e:
127*7d670a3cSBarry Smith    emsg = str(e)
128*7d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
129*7d670a3cSBarry Smith    msg = '             ERROR  in COMMAND LINE ARGUMENT to config/configure.py *****\n' \
130*7d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
1311a02243aSBarry Smith    se = ''
13296dc2fe8SMatthew Knepley  except ImportError, e :
133*7d670a3cSBarry Smith    emsg = str(e)
134*7d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
135*7d670a3cSBarry Smith    msg = '               UNABLE to FIND MODULE for config/configure.py *******\n' \
136*7d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
13796dc2fe8SMatthew Knepley    se = ''
138d7d3c4beSMatthew Knepley  except SystemExit, e:
139d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
140d7d3c4beSMatthew Knepley      return
141*7d670a3cSBarry Smith    msg = '           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
142*7d670a3cSBarry Smith    +'\n*********************************************************************************\n'
143d7d3c4beSMatthew Knepley    se  = str(e)
144e9f3bb17SBarry Smith  except Exception, e:
145*7d670a3cSBarry Smith    msg = '           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
146*7d670a3cSBarry Smith    +'\n*********************************************************************************\n'
147e9f3bb17SBarry Smith    se  = str(e)
148e9f3bb17SBarry Smith
149*7d670a3cSBarry Smith  framework.logClear()
150e9f3bb17SBarry Smith  print msg
151e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
152f6614063SBarry Smith    import traceback
153f24f64feSBarry Smith    framework.log.write(msg+se)
154f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
155e9f3bb17SBarry Smith    sys.exit(1)
1565d5a5a7bSMatthew Knepley
1575d5a5a7bSMatthew Knepleyif __name__ == '__main__':
158a030c540SBarry Smith  petsc_configure([])
159759acf64SBarry Smith
160