xref: /petsc/config/configure.py (revision d65f3bdd8fcc9a25994f61986808acfd906172ae)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
55d5a5a7bSMatthew Knepley
64b8aa89bSBarry Smith
7378f148eSBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 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):
18c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
19c43ea0feSSatish Balay  found = 0
2059e9bfd6SSatish Balay  for name in opts:
21c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
22c43ea0feSSatish Balay      found = 1
2359e9bfd6SSatish Balay      break
2459e9bfd6SSatish Balay  # If not yet specified - use the filename of script
25c43ea0feSSatish Balay  if not found:
2659e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
277eed1879SBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure'):
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
4171384062SSatish Balaydef chkcygwinpython():
4271384062SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
4371384062SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c python').read()
4471384062SSatish Balay    if buf.find('2.4') > -1:
4571384062SSatish Balay      return 1
4671384062SSatish Balay    else:
4771384062SSatish Balay      return 0
4871384062SSatish Balay  return 0
4971384062SSatish Balay
50836c2c52SSatish Balaydef rhl9():
51836c2c52SSatish Balay  try:
52594eb360SSatish Balay    file = open('/etc/redhat-release','r')
53836c2c52SSatish Balay  except:
54836c2c52SSatish Balay    return 0
55836c2c52SSatish Balay  try:
56836c2c52SSatish Balay    buf = file.read()
57836c2c52SSatish Balay    file.close()
58836c2c52SSatish Balay  except:
59836c2c52SSatish Balay    # can't read file - assume dangerous RHL9
60836c2c52SSatish Balay    return 1
61836c2c52SSatish Balay  if buf.find('Shrike') > -1:
62836c2c52SSatish Balay    return 1
63836c2c52SSatish Balay  else:
64836c2c52SSatish Balay    return 0
65836c2c52SSatish Balay
665d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
6759e9bfd6SSatish Balay  print '================================================================================='
6859e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                         '
6959e9bfd6SSatish Balay  print '================================================================================='
7059e9bfd6SSatish Balay
71c43ea0feSSatish Balay  # Command line arguments take precedence (but don't destroy argv[0])
72c43ea0feSSatish Balay  sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
7359e9bfd6SSatish Balay  # check PETSC_ARCH
7459e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
75*d65f3bddSMatthew Knepley  extraLogs = []
765fb2c094SBarry Smith
77c22cdea9SBarry Smith  # support a few standard configure option types
78ed6a7445SBarry Smith  for l in range(0,len(sys.argv)):
79c22cdea9SBarry Smith    name = sys.argv[l]
80c43ea0feSSatish Balay    if name.find('-download-') >= 0:
81ed6a7445SBarry Smith      sys.argv[l] = name.lower()
82c43ea0feSSatish Balay    if name.find('-enable-') >= 0:
83c43ea0feSSatish Balay      sys.argv[l] = name.replace('-enable-','-with-')
84c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=1'
85c43ea0feSSatish Balay    if name.find('-disable-') >= 0:
86c43ea0feSSatish Balay      sys.argv[l] = name.replace('-disable-','-with-')
87c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
88c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
89c43ea0feSSatish Balay    if name.find('-without-') >= 0:
90c43ea0feSSatish Balay      sys.argv[l] = name.replace('-without-','-with-')
91c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
92c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
93c22cdea9SBarry Smith
949dabcff0SSatish Balay  # Check for broken cygwin
959dabcff0SSatish Balay  if chkcygwin():
96ec1ee742SBarry Smith    print '================================================================================='
977d670a3cSBarry Smith    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
981e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
991e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
100ec1ee742SBarry Smith    print '================================================================================='
1019dabcff0SSatish Balay    sys.exit(3)
102*d65f3bddSMatthew Knepley
103*d65f3bddSMatthew Knepley  # Disable threads on RHL9
104*d65f3bddSMatthew Knepley  if rhl9():
105*d65f3bddSMatthew Knepley    sys.argv.append('--useThreads=0')
106*d65f3bddSMatthew Knepley    extraLogs.append('''\
107*d65f3bddSMatthew Knepley================================================================================
108*d65f3bddSMatthew Knepley   *** RHL9 detected. Threads do not work correctly with this distribution ***
109*d65f3bddSMatthew Knepley    ****** Disabling thread usage for this run of config/configure.py *******
110*d65f3bddSMatthew Knepley================================================================================''')
111*d65f3bddSMatthew Knepley
11271384062SSatish Balay  # Threads don't work for cygwin & python-2.4
11371384062SSatish Balay  if chkcygwinpython():
11471384062SSatish Balay    sys.argv.append('--useThreads=0')
115*d65f3bddSMatthew Knepley    extraLogs.append('''\
116*d65f3bddSMatthew Knepley================================================================================
117*d65f3bddSMatthew Knepley** Cygwin-python-2.4 detected. Threads do not work correctly with this version *
118*d65f3bddSMatthew Knepley ********* Disabling thread usage for this run of config/configure.py **********
119*d65f3bddSMatthew Knepley================================================================================''')
1209dabcff0SSatish Balay
12187282423SMatthew Knepley  # Should be run from the toplevel
1225d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
12387282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
12487282423SMatthew Knepley  if not os.path.isdir(pythonDir):
1255d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
12687282423SMatthew Knepley  if not os.path.isdir(bsDir):
127ec1ee742SBarry Smith    print '================================================================================='
1289c4310d5SMatthew Knepley    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
1299c4310d5SMatthew Knepley    print '''++ Downloading it using "bk clone http://sidl.bkbits.net/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
130ec1ee742SBarry Smith    print '================================================================================='
1319c4310d5SMatthew Knepley    (status,output) = commands.getstatusoutput('bk clone http://sidl.bkbits.net/BuildSystem python/BuildSystem')
1327d7624c9SBarry Smith    if status:
1337d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
134ec1ee742SBarry Smith        print '================================================================================='
135d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
136d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
137d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
138ec1ee742SBarry Smith        print '================================================================================='
1397d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
140ec1ee742SBarry Smith        print '================================================================================='
141d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
142d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
143ec1ee742SBarry Smith        print '================================================================================='
1447d7624c9SBarry Smith      else:
145ec1ee742SBarry Smith        print '================================================================================='
146d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
147ec1ee742SBarry Smith        print '================================================================================='
1487d7624c9SBarry Smith      print output
14987282423SMatthew Knepley      sys.exit(3)
1504f8a5b45SBarry Smith
15187282423SMatthew Knepley  sys.path.insert(0, bsDir)
1525d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1535d5a5a7bSMatthew Knepley  import config.framework
154f56be888SMatthew Knepley  import cPickle
1554f8a5b45SBarry Smith
1562e22a60eSMatthew Knepley  # Disable shared libraries by default
1572e22a60eSMatthew Knepley  import nargs
1582e22a60eSMatthew Knepley  if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None:
1592e22a60eSMatthew Knepley    sys.argv.append('--with-shared=0')
1602e22a60eSMatthew Knepley
161c08a18f2SMatthew Knepley  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure','-optionsModule=PETSc.compilerOptions'], loadArgDB = 0)
162*d65f3bddSMatthew Knepley  framework.setup()
163*d65f3bddSMatthew Knepley  framework.logPrint('\n'.join(extraLogs))
16470ae1cd5SMatthew Knepley  try:
165f24f64feSBarry Smith    framework.configure(out = sys.stdout)
166358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
167f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
1687cfd0b05SBarry Smith    import PETSc.packages
1697cfd0b05SBarry Smith    for i in framework.packages:
1707cfd0b05SBarry Smith      if hasattr(i,'postProcess'):
1717cfd0b05SBarry Smith        i.postProcess()
1727cfd0b05SBarry Smith    framework.logClear()
173dd50d019SBarry Smith    return 0
174e9f3bb17SBarry Smith  except RuntimeError, e:
1757d670a3cSBarry Smith    emsg = str(e)
1767d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
177fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
178fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
179fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1807d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
181e9f3bb17SBarry Smith    se = ''
1821a02243aSBarry Smith  except TypeError, e:
1837d670a3cSBarry Smith    emsg = str(e)
1847d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
185fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
186fe09c992SBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
187fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1887d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
1891a02243aSBarry Smith    se = ''
19096dc2fe8SMatthew Knepley  except ImportError, e :
1917d670a3cSBarry Smith    emsg = str(e)
1927d670a3cSBarry Smith    if not emsg.endswith('\n'): emsg += '\n'
193fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
194fe09c992SBarry Smith    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
195fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
1967d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
19796dc2fe8SMatthew Knepley    se = ''
198d7d3c4beSMatthew Knepley  except SystemExit, e:
199d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
200d7d3c4beSMatthew Knepley      return
201fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
202fe09c992SBarry Smith    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
203fe09c992SBarry Smith    +'*********************************************************************************\n'
204d7d3c4beSMatthew Knepley    se  = str(e)
205e9f3bb17SBarry Smith  except Exception, e:
206fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
207fe09c992SBarry Smith    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
208fe09c992SBarry Smith    +'*********************************************************************************\n'
209e9f3bb17SBarry Smith    se  = str(e)
210e9f3bb17SBarry Smith
2117d670a3cSBarry Smith  framework.logClear()
212e9f3bb17SBarry Smith  print msg
213e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
214f6614063SBarry Smith    import traceback
215f24f64feSBarry Smith    framework.log.write(msg+se)
216f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
2172418bae5SMatthew Knepley    if os.path.isfile(framework.logName+'.bkp'):
2182418bae5SMatthew Knepley      framework.logPrintDivider()
2192418bae5SMatthew Knepley      framework.logPrintBox('Previous configure logs below', debugSection = None)
2202418bae5SMatthew Knepley      f = file(framework.logName+'.bkp')
2212418bae5SMatthew Knepley      framework.log.write(f.read())
2222418bae5SMatthew Knepley      f.close()
223e9f3bb17SBarry Smith    sys.exit(1)
2245d5a5a7bSMatthew Knepley
2255d5a5a7bSMatthew Knepleyif __name__ == '__main__':
226a030c540SBarry Smith  petsc_configure([])
227759acf64SBarry Smith
228