xref: /petsc/config/configure.py (revision c43ea0feca7f07d3dc696280b228dcc556c189e9)
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:
8495ffa62SBarry Smith  print '**** You must have Python version 2.2 or higher to run config/configure.py ******'
9495ffa62SBarry Smith  print '*           Python is easy to install for end users or sys-admin.               *'
1032077d6dSBarry Smith  print '*                   http://www.python.org/download/                             *'
1132077d6dSBarry Smith  print '*                                                                               *'
12495ffa62SBarry Smith  print '*            You CANNOT configure PETSc without Python                          *'
13495ffa62SBarry Smith  print '*    http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html      *'
1432077d6dSBarry Smith  print '*********************************************************************************'
15b26a8723SBarry Smith  sys.exit(4)
162fb34ac0SMatthew Knepley
1759e9bfd6SSatish Balaydef check_petsc_arch(opts):
18*c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
19*c43ea0feSSatish Balay  found = 0
2059e9bfd6SSatish Balay  for name in opts:
21*c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
22*c43ea0feSSatish Balay      found = 1
2359e9bfd6SSatish Balay      break
2459e9bfd6SSatish Balay  # If not yet specified - use the filename of script
25*c43ea0feSSatish Balay  if not found:
2659e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
2759e9bfd6SSatish Balay      if not filename.startswith('configure'):
2859e9bfd6SSatish Balay        useName = '-PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
2959e9bfd6SSatish Balay        opts.append(useName)
3059e9bfd6SSatish Balay  return
314b8aa89bSBarry Smith
329dabcff0SSatish Balaydef chkcygwin():
339dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
349dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
359dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
369dabcff0SSatish Balay      return 1
379dabcff0SSatish Balay    else:
389dabcff0SSatish Balay      return 0
399dabcff0SSatish Balay  return 0
409dabcff0SSatish Balay
41836c2c52SSatish Balaydef rhl9():
42836c2c52SSatish Balay  try:
43594eb360SSatish Balay    file = open('/etc/redhat-release','r')
44836c2c52SSatish Balay  except:
45836c2c52SSatish Balay    return 0
46836c2c52SSatish Balay  try:
47836c2c52SSatish Balay    buf = file.read()
48836c2c52SSatish Balay    file.close()
49836c2c52SSatish Balay  except:
50836c2c52SSatish Balay    # can't read file - assume dangerous RHL9
51836c2c52SSatish Balay    return 1
52836c2c52SSatish Balay  if buf.find('Shrike') > -1:
53836c2c52SSatish Balay    return 1
54836c2c52SSatish Balay  else:
55836c2c52SSatish Balay    return 0
56836c2c52SSatish Balay
575d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
5859e9bfd6SSatish Balay  print '================================================================================='
5959e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                         '
6059e9bfd6SSatish Balay  print '================================================================================='
6159e9bfd6SSatish Balay
62*c43ea0feSSatish Balay  # Command line arguments take precedence (but don't destroy argv[0])
63*c43ea0feSSatish Balay  sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
6459e9bfd6SSatish Balay  # check PETSC_ARCH
6559e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
665fb2c094SBarry Smith
67c22cdea9SBarry Smith  # support a few standard configure option types
68ed6a7445SBarry Smith  for l in range(0,len(sys.argv)):
69c22cdea9SBarry Smith    name = sys.argv[l]
70*c43ea0feSSatish Balay    if name.find('-download-') >= 0:
71ed6a7445SBarry Smith      sys.argv[l] = name.lower()
72*c43ea0feSSatish Balay    if name.find('-enable-') >= 0:
73*c43ea0feSSatish Balay      sys.argv[l] = name.replace('-enable-','-with-')
74c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=1'
75*c43ea0feSSatish Balay    if name.find('-disable-') >= 0:
76*c43ea0feSSatish Balay      sys.argv[l] = name.replace('-disable-','-with-')
77c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
78c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
79*c43ea0feSSatish Balay    if name.find('-without-') >= 0:
80*c43ea0feSSatish Balay      sys.argv[l] = name.replace('-without-','-with-')
81c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
82c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
83c22cdea9SBarry Smith
84836c2c52SSatish Balay  # Disable threads on RHL9
85836c2c52SSatish Balay  if rhl9():
86f1365dfbSSatish Balay    sys.argv.append('--useThreads=0')
87ec1ee742SBarry Smith    print '================================================================================='
887d670a3cSBarry Smith    print ' *** RHL9 detected. Threads do not work correctly with this distribution ***'
897d670a3cSBarry Smith    print ' ******** Disabling thread usage for this run of config/configure.py *****'
90ec1ee742SBarry Smith    print '================================================================================='
91836c2c52SSatish Balay
929dabcff0SSatish Balay  # Check for broken cygwin
939dabcff0SSatish Balay  if chkcygwin():
94ec1ee742SBarry Smith    print '================================================================================='
957d670a3cSBarry Smith    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
961e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
971e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
98ec1ee742SBarry Smith    print '================================================================================='
999dabcff0SSatish Balay    sys.exit(3)
1009dabcff0SSatish Balay
10187282423SMatthew Knepley  # Should be run from the toplevel
1025d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
10387282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
10487282423SMatthew Knepley  if not os.path.isdir(pythonDir):
1055d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
10687282423SMatthew Knepley  if not os.path.isdir(bsDir):
107ec1ee742SBarry Smith    print '================================================================================='
1089c4310d5SMatthew Knepley    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
1099c4310d5SMatthew Knepley    print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
110ec1ee742SBarry Smith    print '================================================================================='
1119c4310d5SMatthew Knepley    (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem')
1127d7624c9SBarry Smith    if status:
1137d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
114ec1ee742SBarry Smith        print '================================================================================='
115d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
116d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
117d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
118ec1ee742SBarry Smith        print '================================================================================='
1197d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
120ec1ee742SBarry Smith        print '================================================================================='
121d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
122d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
123ec1ee742SBarry Smith        print '================================================================================='
1247d7624c9SBarry Smith      else:
125ec1ee742SBarry Smith        print '================================================================================='
126d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
127ec1ee742SBarry Smith        print '================================================================================='
1287d7624c9SBarry Smith      print output
12987282423SMatthew Knepley      sys.exit(3)
1304f8a5b45SBarry Smith
13187282423SMatthew Knepley  sys.path.insert(0, bsDir)
1325d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1335d5a5a7bSMatthew Knepley  import config.framework
134f56be888SMatthew Knepley  import cPickle
1354f8a5b45SBarry Smith
1362e22a60eSMatthew Knepley  # Disable shared libraries by default
1372e22a60eSMatthew Knepley  import nargs
1382e22a60eSMatthew Knepley  if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None:
1392e22a60eSMatthew Knepley    sys.argv.append('--with-shared=0')
1402e22a60eSMatthew Knepley
14159e9bfd6SSatish Balay  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure'], loadArgDB = 0)
14270ae1cd5SMatthew Knepley  try:
143f24f64feSBarry Smith    framework.configure(out = sys.stdout)
144358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
145f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
1467cfd0b05SBarry Smith    import PETSc.packages
1477cfd0b05SBarry Smith    for i in framework.packages:
1487cfd0b05SBarry Smith      if hasattr(i,'postProcess'):
1497cfd0b05SBarry Smith        i.postProcess()
1507cfd0b05SBarry Smith    framework.logClear()
151dd50d019SBarry Smith    return 0
152e9f3bb17SBarry Smith  except RuntimeError, e:
1537d670a3cSBarry Smith    emsg = str(e)
1547d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
155fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
156fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
157fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1587d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
159e9f3bb17SBarry Smith    se = ''
1601a02243aSBarry Smith  except TypeError, e:
1617d670a3cSBarry Smith    emsg = str(e)
1627d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
163fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
164fe09c992SBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
165fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1667d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
1671a02243aSBarry Smith    se = ''
16896dc2fe8SMatthew Knepley  except ImportError, e :
1697d670a3cSBarry Smith    emsg = str(e)
1707d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
171fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
172fe09c992SBarry Smith    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
173fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1747d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
17596dc2fe8SMatthew Knepley    se = ''
176d7d3c4beSMatthew Knepley  except SystemExit, e:
177d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
178d7d3c4beSMatthew Knepley      return
179fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
180fe09c992SBarry Smith    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
181fe09c992SBarry Smith    +'*********************************************************************************\n'
182d7d3c4beSMatthew Knepley    se  = str(e)
183e9f3bb17SBarry Smith  except Exception, e:
184fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
185fe09c992SBarry Smith    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
186fe09c992SBarry Smith    +'*********************************************************************************\n'
187e9f3bb17SBarry Smith    se  = str(e)
188e9f3bb17SBarry Smith
1897d670a3cSBarry Smith  framework.logClear()
190e9f3bb17SBarry Smith  print msg
191e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
192f6614063SBarry Smith    import traceback
193f24f64feSBarry Smith    framework.log.write(msg+se)
194f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
1952418bae5SMatthew Knepley    if os.path.isfile(framework.logName+'.bkp'):
1962418bae5SMatthew Knepley      framework.logPrintDivider()
1972418bae5SMatthew Knepley      framework.logPrintBox('Previous configure logs below', debugSection = None)
1982418bae5SMatthew Knepley      f = file(framework.logName+'.bkp')
1992418bae5SMatthew Knepley      framework.log.write(f.read())
2002418bae5SMatthew Knepley      f.close()
201e9f3bb17SBarry Smith    sys.exit(1)
2025d5a5a7bSMatthew Knepley
2035d5a5a7bSMatthew Knepleyif __name__ == '__main__':
204a030c540SBarry Smith  petsc_configure([])
205759acf64SBarry Smith
206