xref: /petsc/config/configure.py (revision ed6a74456be165ff04b22af22faf4d4d89058abf)
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):
1859e9bfd6SSatish Balay  # Check for PETSC_ARCH in the following order:
1959e9bfd6SSatish Balay  # 1. command-line (first occurance)
2059e9bfd6SSatish Balay  # 2. specified in configure_options(in script)
2159e9bfd6SSatish Balay  # 3. script name (if not configure.py)
2259e9bfd6SSatish Balay
2359e9bfd6SSatish Balay  useName = ''
2459e9bfd6SSatish Balay  for name in opts:
2559e9bfd6SSatish Balay    if name.startswith('-PETSC_ARCH'):
2659e9bfd6SSatish Balay      useName = name
2759e9bfd6SSatish Balay      break
2859e9bfd6SSatish Balay  # look for duplicates - and remove them
2959e9bfd6SSatish Balay  dupnames = []
3059e9bfd6SSatish Balay  if useName:
3159e9bfd6SSatish Balay    for name in opts:
3259e9bfd6SSatish Balay      if name.startswith('-PETSC_ARCH') and name != useName:
3359e9bfd6SSatish Balay        opts.remove(name)
3459e9bfd6SSatish Balay        dupnames.append(name)
3559e9bfd6SSatish Balay  # print warning for duplicates
3659e9bfd6SSatish Balay  if dupnames:
3759e9bfd6SSatish Balay    print '*********************************************************************************'
3859e9bfd6SSatish Balay    print 'Warning: The following duplicate PETSC_ARCH options are removed:', dupnames
3959e9bfd6SSatish Balay    print 'Warning: Using the option:', useName
4059e9bfd6SSatish Balay    print '*********************************************************************************'
4159e9bfd6SSatish Balay  # If not yet specified - use the filename of script
4259e9bfd6SSatish Balay  if not useName:
4359e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
4459e9bfd6SSatish Balay      if not filename.startswith('configure'):
4559e9bfd6SSatish Balay        useName = '-PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
4659e9bfd6SSatish Balay        opts.append(useName)
4759e9bfd6SSatish Balay  return
484b8aa89bSBarry Smith
499dabcff0SSatish Balaydef chkcygwin():
509dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
519dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
529dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
539dabcff0SSatish Balay      return 1
549dabcff0SSatish Balay    else:
559dabcff0SSatish Balay      return 0
569dabcff0SSatish Balay  return 0
579dabcff0SSatish Balay
58836c2c52SSatish Balaydef rhl9():
59836c2c52SSatish Balay  try:
60594eb360SSatish Balay    file = open('/etc/redhat-release','r')
61836c2c52SSatish Balay  except:
62836c2c52SSatish Balay    return 0
63836c2c52SSatish Balay  try:
64836c2c52SSatish Balay    buf = file.read()
65836c2c52SSatish Balay    file.close()
66836c2c52SSatish Balay  except:
67836c2c52SSatish Balay    # can't read file - assume dangerous RHL9
68836c2c52SSatish Balay    return 1
69836c2c52SSatish Balay  if buf.find('Shrike') > -1:
70836c2c52SSatish Balay    return 1
71836c2c52SSatish Balay  else:
72836c2c52SSatish Balay    return 0
73836c2c52SSatish Balay
745d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
7559e9bfd6SSatish Balay  print '================================================================================='
7659e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                         '
7759e9bfd6SSatish Balay  print '================================================================================='
7859e9bfd6SSatish Balay
7959e9bfd6SSatish Balay  sys.argv += configure_options
8059e9bfd6SSatish Balay  # check PETSC_ARCH
8159e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
825fb2c094SBarry Smith
83c22cdea9SBarry Smith  # support a few standard configure option types
84*ed6a7445SBarry Smith  for l in range(0,len(sys.argv)):
85c22cdea9SBarry Smith    name = sys.argv[l]
86*ed6a7445SBarry Smith    if name.startswith('--download'):
87*ed6a7445SBarry Smith      sys.argv[l] = name.lower()
88c22cdea9SBarry Smith    if name.startswith('--enable'):
89c22cdea9SBarry Smith      sys.argv[l] = name.replace('--enable','--with')
90c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=1'
91c22cdea9SBarry Smith    if name.startswith('--disable'):
92c22cdea9SBarry Smith      sys.argv[l] = name.replace('--disable','--with')
93c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
94c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
95c22cdea9SBarry Smith    if name.startswith('--without'):
96c22cdea9SBarry Smith      sys.argv[l] = name.replace('--without','--with')
97c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
98c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
99c22cdea9SBarry Smith
100f35b2c57SBarry Smith  # if language is C then should not be checking C++
101ba7b4f46SBarry Smith  usingcxx = 0
102f35b2c57SBarry Smith  for j in sys.argv:
103b55a8556SMatthew Knepley    if j.replace('++','xx') == '--with-clanguage=cxx' or j == '--with-scalar-type=complex':
104ba7b4f46SBarry Smith      usingcxx = 1
105ba7b4f46SBarry Smith      break
106d23016edSBarry Smith    # horrible, horrible hack; downloading Prometheus needs C++
107d23016edSBarry Smith    if j.find('--download-prometheus') >= 0:
108d23016edSBarry Smith      usingcxx = 1
109d23016edSBarry Smith      break
110ba7b4f46SBarry Smith
111ba7b4f46SBarry Smith  if not usingcxx:
112f35b2c57SBarry Smith    foundcxx = 0
113f35b2c57SBarry Smith    for l in range(0,len(sys.argv)-1):
114f35b2c57SBarry Smith      name = sys.argv[l]
115f35b2c57SBarry Smith      if name.startswith('--with-cxx'):
116f35b2c57SBarry Smith        sys.argv[l] = '--with-cxx=0'
117f35b2c57SBarry Smith        foundcxx = 1
118f35b2c57SBarry Smith        break
119f35b2c57SBarry Smith    if not foundcxx:
120f35b2c57SBarry Smith      sys.argv.append('--with-cxx=0')
121f35b2c57SBarry Smith
122836c2c52SSatish Balay  # Disable threads on RHL9
123836c2c52SSatish Balay  if rhl9():
124f1365dfbSSatish Balay    sys.argv.append('--useThreads=0')
125ec1ee742SBarry Smith    print '================================================================================='
1267d670a3cSBarry Smith    print ' *** RHL9 detected. Threads do not work correctly with this distribution ***'
1277d670a3cSBarry Smith    print ' ******** Disabling thread usage for this run of config/configure.py *****'
128ec1ee742SBarry Smith    print '================================================================================='
129836c2c52SSatish Balay
1309dabcff0SSatish Balay  # Check for broken cygwin
1319dabcff0SSatish Balay  if chkcygwin():
132ec1ee742SBarry Smith    print '================================================================================='
1337d670a3cSBarry Smith    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
1341e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
1351e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
136ec1ee742SBarry Smith    print '================================================================================='
1379dabcff0SSatish Balay    sys.exit(3)
1389dabcff0SSatish Balay
13987282423SMatthew Knepley  # Should be run from the toplevel
1405d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
14187282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
14287282423SMatthew Knepley  if not os.path.isdir(pythonDir):
1435d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
14487282423SMatthew Knepley  if not os.path.isdir(bsDir):
145ec1ee742SBarry Smith    print '================================================================================='
1469c4310d5SMatthew Knepley    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
1479c4310d5SMatthew Knepley    print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
148ec1ee742SBarry Smith    print '================================================================================='
1499c4310d5SMatthew Knepley    (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem')
1507d7624c9SBarry Smith    if status:
1517d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
152ec1ee742SBarry Smith        print '================================================================================='
153d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
154d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
155d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
156ec1ee742SBarry Smith        print '================================================================================='
1577d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
158ec1ee742SBarry Smith        print '================================================================================='
159d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
160d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
161ec1ee742SBarry Smith        print '================================================================================='
1627d7624c9SBarry Smith      else:
163ec1ee742SBarry Smith        print '================================================================================='
164d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
165ec1ee742SBarry Smith        print '================================================================================='
1667d7624c9SBarry Smith      print output
16787282423SMatthew Knepley      sys.exit(3)
1684f8a5b45SBarry Smith
16987282423SMatthew Knepley  sys.path.insert(0, bsDir)
1705d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1715d5a5a7bSMatthew Knepley  import config.framework
172f56be888SMatthew Knepley  import cPickle
1734f8a5b45SBarry Smith
17459e9bfd6SSatish Balay  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure'], loadArgDB = 0)
17570ae1cd5SMatthew Knepley  try:
176f24f64feSBarry Smith    framework.configure(out = sys.stdout)
177358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
178f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
1797cfd0b05SBarry Smith    import PETSc.packages
1807cfd0b05SBarry Smith    for i in framework.packages:
1817cfd0b05SBarry Smith      if hasattr(i,'postProcess'):
1827cfd0b05SBarry Smith        i.postProcess()
1837cfd0b05SBarry Smith    framework.logClear()
184dd50d019SBarry Smith    return 0
185e9f3bb17SBarry Smith  except RuntimeError, e:
1867d670a3cSBarry Smith    emsg = str(e)
1877d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
188fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
189fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
190fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1917d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
192e9f3bb17SBarry Smith    se = ''
1931a02243aSBarry Smith  except TypeError, e:
1947d670a3cSBarry Smith    emsg = str(e)
1957d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
196fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
197fe09c992SBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
198fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1997d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
2001a02243aSBarry Smith    se = ''
20196dc2fe8SMatthew Knepley  except ImportError, e :
2027d670a3cSBarry Smith    emsg = str(e)
2037d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
204fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
205fe09c992SBarry Smith    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
206fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
2077d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
20896dc2fe8SMatthew Knepley    se = ''
209d7d3c4beSMatthew Knepley  except SystemExit, e:
210d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
211d7d3c4beSMatthew Knepley      return
212fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
213fe09c992SBarry Smith    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
214fe09c992SBarry Smith    +'*********************************************************************************\n'
215d7d3c4beSMatthew Knepley    se  = str(e)
216e9f3bb17SBarry Smith  except Exception, e:
217fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
218fe09c992SBarry Smith    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
219fe09c992SBarry Smith    +'*********************************************************************************\n'
220e9f3bb17SBarry Smith    se  = str(e)
221e9f3bb17SBarry Smith
2227d670a3cSBarry Smith  framework.logClear()
223e9f3bb17SBarry Smith  print msg
224e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
225f6614063SBarry Smith    import traceback
226f24f64feSBarry Smith    framework.log.write(msg+se)
227f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
2282418bae5SMatthew Knepley    if os.path.isfile(framework.logName+'.bkp'):
2292418bae5SMatthew Knepley      framework.logPrintDivider()
2302418bae5SMatthew Knepley      framework.logPrintBox('Previous configure logs below', debugSection = None)
2312418bae5SMatthew Knepley      f = file(framework.logName+'.bkp')
2322418bae5SMatthew Knepley      framework.log.write(f.read())
2332418bae5SMatthew Knepley      f.close()
234e9f3bb17SBarry Smith    sys.exit(1)
2355d5a5a7bSMatthew Knepley
2365d5a5a7bSMatthew Knepleyif __name__ == '__main__':
237a030c540SBarry Smith  petsc_configure([])
238759acf64SBarry Smith
239