xref: /petsc/config/configure.py (revision 59e9bfd61764f1fc317def6f8c1a30240ede691c)
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
17*59e9bfd6SSatish Balaydef check_petsc_arch(opts):
18*59e9bfd6SSatish Balay  # Check for PETSC_ARCH in the following order:
19*59e9bfd6SSatish Balay  # 1. command-line (first occurance)
20*59e9bfd6SSatish Balay  # 2. specified in configure_options(in script)
21*59e9bfd6SSatish Balay  # 3. script name (if not configure.py)
22*59e9bfd6SSatish Balay
23*59e9bfd6SSatish Balay  useName = ''
24*59e9bfd6SSatish Balay  for name in opts:
25*59e9bfd6SSatish Balay    if name.startswith('-PETSC_ARCH'):
26*59e9bfd6SSatish Balay      useName = name
27*59e9bfd6SSatish Balay      break
28*59e9bfd6SSatish Balay  # look for duplicates - and remove them
29*59e9bfd6SSatish Balay  dupnames = []
30*59e9bfd6SSatish Balay  if useName:
31*59e9bfd6SSatish Balay    for name in opts:
32*59e9bfd6SSatish Balay      if name.startswith('-PETSC_ARCH') and name != useName:
33*59e9bfd6SSatish Balay        opts.remove(name)
34*59e9bfd6SSatish Balay        dupnames.append(name)
35*59e9bfd6SSatish Balay  # print warning for duplicates
36*59e9bfd6SSatish Balay  if dupnames:
37*59e9bfd6SSatish Balay    print '*********************************************************************************'
38*59e9bfd6SSatish Balay    print 'Warning: The following duplicate PETSC_ARCH options are removed:', dupnames
39*59e9bfd6SSatish Balay    print 'Warning: Using the option:', useName
40*59e9bfd6SSatish Balay    print '*********************************************************************************'
41*59e9bfd6SSatish Balay  # If not yet specified - use the filename of script
42*59e9bfd6SSatish Balay  if not useName:
43*59e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
44*59e9bfd6SSatish Balay      if not filename.startswith('configure'):
45*59e9bfd6SSatish Balay        useName = '-PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
46*59e9bfd6SSatish Balay        opts.append(useName)
47*59e9bfd6SSatish 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):
75*59e9bfd6SSatish Balay  print '================================================================================='
76*59e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                         '
77*59e9bfd6SSatish Balay  print '================================================================================='
78*59e9bfd6SSatish Balay
79*59e9bfd6SSatish Balay  sys.argv += configure_options
80*59e9bfd6SSatish Balay  # check PETSC_ARCH
81*59e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
825fb2c094SBarry Smith
83c22cdea9SBarry Smith  # support a few standard configure option types
84c22cdea9SBarry Smith  for l in range(0,len(sys.argv)-1):
85c22cdea9SBarry Smith    name = sys.argv[l]
86c22cdea9SBarry Smith    if name.startswith('--enable'):
87c22cdea9SBarry Smith      sys.argv[l] = name.replace('--enable','--with')
88c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=1'
89c22cdea9SBarry Smith    if name.startswith('--disable'):
90c22cdea9SBarry Smith      sys.argv[l] = name.replace('--disable','--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    if name.startswith('--without'):
94c22cdea9SBarry Smith      sys.argv[l] = name.replace('--without','--with')
95c22cdea9SBarry Smith      if name.find('=') == -1: sys.argv[l] += '=0'
96c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
97c22cdea9SBarry Smith
98836c2c52SSatish Balay  # Disable threads on RHL9
99836c2c52SSatish Balay  if rhl9():
100f1365dfbSSatish Balay    sys.argv.append('--useThreads=0')
101836c2c52SSatish Balay    print ' *** RHL9 detected. Disabling threads in configure *****'
102836c2c52SSatish Balay
1039dabcff0SSatish Balay  # Check for broken cygwin
1049dabcff0SSatish Balay  if chkcygwin():
1059dabcff0SSatish Balay    print ' *** cygwin-1.5.11-1 detected. configure fails with this version   ***'
1061e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
1071e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
1089dabcff0SSatish Balay    sys.exit(3)
1099dabcff0SSatish Balay
11087282423SMatthew Knepley  # Should be run from the toplevel
1115d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
11287282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
11387282423SMatthew Knepley  if not os.path.isdir(pythonDir):
1145d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
11587282423SMatthew Knepley  if not os.path.isdir(bsDir):
116d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
117d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
1184f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
1197d7624c9SBarry Smith    if status:
1207d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
121d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
122d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
123d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
1247d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
125d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
126d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
1277d7624c9SBarry Smith      else:
128d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
1297d7624c9SBarry Smith      print output
13087282423SMatthew Knepley      sys.exit(3)
1314f8a5b45SBarry Smith
13287282423SMatthew Knepley  sys.path.insert(0, bsDir)
1335d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
1345d5a5a7bSMatthew Knepley  import config.framework
135f56be888SMatthew Knepley  import cPickle
1364f8a5b45SBarry Smith
137*59e9bfd6SSatish Balay  framework = config.framework.Framework(sys.argv[1:]+['-configModules=PETSc.Configure'], loadArgDB = 0)
13870ae1cd5SMatthew Knepley  try:
139f24f64feSBarry Smith    framework.configure(out = sys.stdout)
140358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
141f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
142dd50d019SBarry Smith    return 0
143e9f3bb17SBarry Smith  except RuntimeError, e:
14466b9a547SSatish Balay    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
145d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
146e9f3bb17SBarry Smith    se = ''
1471a02243aSBarry Smith  except TypeError, e:
14866b9a547SSatish Balay    msg = '***** Error in command line argument to configure.py *****\n' \
149d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
1501a02243aSBarry Smith    se = ''
15196dc2fe8SMatthew Knepley  except ImportError, e:
15296dc2fe8SMatthew Knepley    msg = '******* Unable to find module for configure.py *******\n' \
15396dc2fe8SMatthew Knepley    +str(e)+'\n******************************************************\n'
15496dc2fe8SMatthew Knepley    se = ''
155d7d3c4beSMatthew Knepley  except SystemExit, e:
156d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
157d7d3c4beSMatthew Knepley      return
158d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
159d7d3c4beSMatthew Knepley    se  = str(e)
160e9f3bb17SBarry Smith  except Exception, e:
161d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
162e9f3bb17SBarry Smith    se  = str(e)
163e9f3bb17SBarry Smith
164e9f3bb17SBarry Smith  print msg
165e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
166f6614063SBarry Smith    import traceback
167f24f64feSBarry Smith    framework.log.write(msg+se)
168f24f64feSBarry Smith    traceback.print_tb(sys.exc_info()[2], file = framework.log)
169e9f3bb17SBarry Smith    sys.exit(1)
1705d5a5a7bSMatthew Knepley
1715d5a5a7bSMatthew Knepleyif __name__ == '__main__':
172a030c540SBarry Smith  petsc_configure([])
173759acf64SBarry Smith
174