xref: /petsc/config/configure.py (revision fd0ecfce1f1f7352fc1de7f539dc9da29179a274)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
5a1eda5bfSSatish Balay# to load ~/.pythonrc.py before inserting correct BuildSystem to path
6a1eda5bfSSatish Balayimport user
75d5a5a7bSMatthew Knepley
84b8aa89bSBarry Smith
9378f148eSBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2 or not sys.version_info[0] >= 2:
10495ffa62SBarry Smith  print '**** You must have Python version 2.2 or higher to run config/configure.py ******'
11495ffa62SBarry Smith  print '*           Python is easy to install for end users or sys-admin.               *'
1232077d6dSBarry Smith  print '*                   http://www.python.org/download/                             *'
1332077d6dSBarry Smith  print '*                                                                               *'
14495ffa62SBarry Smith  print '*            You CANNOT configure PETSc without Python                          *'
15495ffa62SBarry Smith  print '*    http://www.mcs.anl.gov/petsc/petsc-as/documentation/installation.html      *'
1632077d6dSBarry Smith  print '*********************************************************************************'
17b26a8723SBarry Smith  sys.exit(4)
182fb34ac0SMatthew Knepley
1959e9bfd6SSatish Balaydef check_petsc_arch(opts):
20c43ea0feSSatish Balay  # If PETSC_ARCH not specified - use script name (if not configure.py)
21c43ea0feSSatish Balay  found = 0
2259e9bfd6SSatish Balay  for name in opts:
23c43ea0feSSatish Balay    if name.find('PETSC_ARCH=') >= 0:
24c43ea0feSSatish Balay      found = 1
2559e9bfd6SSatish Balay      break
2659e9bfd6SSatish Balay  # If not yet specified - use the filename of script
27c43ea0feSSatish Balay  if not found:
2859e9bfd6SSatish Balay      filename = os.path.basename(sys.argv[0])
297eed1879SBarry Smith      if not filename.startswith('configure') and not filename.startswith('reconfigure'):
30637cc2ebSSatish Balay        useName = 'PETSC_ARCH='+os.path.splitext(os.path.basename(sys.argv[0]))[0]
3159e9bfd6SSatish Balay        opts.append(useName)
3259e9bfd6SSatish Balay  return
334b8aa89bSBarry Smith
3485ef4d1eSSatish Balaydef chkbrokencygwin():
359dabcff0SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
369dabcff0SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
379dabcff0SSatish Balay    if buf.find('1.5.11-1') > -1:
389dabcff0SSatish Balay      return 1
399dabcff0SSatish Balay    else:
409dabcff0SSatish Balay      return 0
419dabcff0SSatish Balay  return 0
429dabcff0SSatish Balay
4385ef4d1eSSatish Balaydef chkusingwindowspython():
4485ef4d1eSSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
4585ef4d1eSSatish Balay    if sys.platform != 'cygwin':
4685ef4d1eSSatish Balay      return 1
4785ef4d1eSSatish Balay  return 0
4885ef4d1eSSatish Balay
4985ef4d1eSSatish Balaydef chkcygwinpythonver():
5071384062SSatish Balay  if os.path.exists('/usr/bin/cygcheck.exe'):
5171384062SSatish Balay    buf = os.popen('/usr/bin/cygcheck.exe -c python').read()
52c4b7e894SSatish Balay    if (buf.find('2.4') > -1) or (buf.find('2.5') > -1) or (buf.find('2.6') > -1):
5371384062SSatish Balay      return 1
5471384062SSatish Balay    else:
5571384062SSatish Balay      return 0
5671384062SSatish Balay  return 0
5771384062SSatish 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
74*fd0ecfceSSatish Balaydef chkBrokenF8Diff():
75*fd0ecfceSSatish Balay  if os.path.exists('/bin/rpm'):
76*fd0ecfceSSatish Balay    buf = os.popen('/bin/rpm -q diffutils').read()
77*fd0ecfceSSatish Balay  if buf.find('diffutils-2.8.1-17.fc8') > -1:
78*fd0ecfceSSatish Balay    return 1
79*fd0ecfceSSatish Balay  else:
80*fd0ecfceSSatish Balay    return 0
81*fd0ecfceSSatish Balay
82*fd0ecfceSSatish Balay
835d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
8459e9bfd6SSatish Balay  print '================================================================================='
8559e9bfd6SSatish Balay  print '             Configuring PETSc to compile on your system                         '
8659e9bfd6SSatish Balay  print '================================================================================='
8759e9bfd6SSatish Balay
88c43ea0feSSatish Balay  # Command line arguments take precedence (but don't destroy argv[0])
89c43ea0feSSatish Balay  sys.argv = sys.argv[:1] + configure_options + sys.argv[1:]
9059e9bfd6SSatish Balay  # check PETSC_ARCH
9159e9bfd6SSatish Balay  check_petsc_arch(sys.argv)
92d65f3bddSMatthew Knepley  extraLogs = []
935fb2c094SBarry Smith
94c22cdea9SBarry Smith  # support a few standard configure option types
95ed6a7445SBarry Smith  for l in range(0,len(sys.argv)):
96c22cdea9SBarry Smith    name = sys.argv[l]
97637cc2ebSSatish Balay    if name.find('enable-') >= 0:
98637cc2ebSSatish Balay      sys.argv[l] = name.replace('enable-','with-')
9942351d26SSatish Balay      if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=1'
100637cc2ebSSatish Balay    if name.find('disable-') >= 0:
101637cc2ebSSatish Balay      sys.argv[l] = name.replace('disable-','with-')
10242351d26SSatish Balay      if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0'
103c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
104637cc2ebSSatish Balay    if name.find('without-') >= 0:
105637cc2ebSSatish Balay      sys.argv[l] = name.replace('without-','with-')
10642351d26SSatish Balay      if name.find('=') == -1: sys.argv[l] = sys.argv[l]+'=0'
107c22cdea9SBarry Smith      elif name.endswith('=1'): sys.argv[l].replace('=1','=0')
108c22cdea9SBarry Smith
109adc3e427SMatthew Knepley  # Check for sudo
110adc3e427SMatthew Knepley  if os.getuid() == 0:
111adc3e427SMatthew Knepley    print '================================================================================='
112adc3e427SMatthew Knepley    print '             *** Do not run configure as root, or using sudo. ***'
11367e28bfeSBarry Smith    print '             *** Use the --with-sudo=sudo option to have      ***'
11467e28bfeSBarry Smith    print '             *** installs of external packages done with sudo ***'
11567e28bfeSBarry Smith    print '             *** use only with --prefix= when installing in   ***'
11667e28bfeSBarry Smith    print '             *** system directories                           ***'
117adc3e427SMatthew Knepley    print '================================================================================='
118adc3e427SMatthew Knepley    sys.exit(3)
119adc3e427SMatthew Knepley
1209dabcff0SSatish Balay  # Check for broken cygwin
12185ef4d1eSSatish Balay  if chkbrokencygwin():
122ec1ee742SBarry Smith    print '================================================================================='
1237d670a3cSBarry Smith    print ' *** cygwin-1.5.11-1 detected. config/configure.py fails with this version   ***'
1241e42869aSSatish Balay    print ' *** Please upgrade to cygwin-1.5.12-1 or newer version. This can  ***'
1251e42869aSSatish Balay    print ' *** be done by running cygwin-setup, selecting "next" all the way.***'
126ec1ee742SBarry Smith    print '================================================================================='
1279dabcff0SSatish Balay    sys.exit(3)
128d65f3bddSMatthew Knepley
129d65f3bddSMatthew Knepley  # Disable threads on RHL9
130d65f3bddSMatthew Knepley  if rhl9():
131d65f3bddSMatthew Knepley    sys.argv.append('--useThreads=0')
132d65f3bddSMatthew Knepley    extraLogs.append('''\
133d65f3bddSMatthew Knepley================================================================================
134d65f3bddSMatthew Knepley   *** RHL9 detected. Threads do not work correctly with this distribution ***
135d65f3bddSMatthew Knepley    ****** Disabling thread usage for this run of config/configure.py *******
136d65f3bddSMatthew Knepley================================================================================''')
137*fd0ecfceSSatish Balay
138*fd0ecfceSSatish Balay  # Check for broken diff on Fedora8
139*fd0ecfceSSatish Balay  if chkBrokenF8Diff():
140*fd0ecfceSSatish Balay    print '================================================================================='
141*fd0ecfceSSatish Balay    print ' *** Fedora 8 Linux with broken diffutils-2.8.1-17.fc8 detected. ****************'
142*fd0ecfceSSatish Balay    print ' *** Please run "sudo yum update diffutils" to get the latest bugfixed version.**'
143*fd0ecfceSSatish Balay    print '================================================================================='
144*fd0ecfceSSatish Balay    sys.exit(3)
145*fd0ecfceSSatish Balay
14685ef4d1eSSatish Balay  # Make sure cygwin-python is used on windows
14785ef4d1eSSatish Balay  if chkusingwindowspython():
14885ef4d1eSSatish Balay    print '================================================================================='
14985ef4d1eSSatish Balay    print ' *** Non-cygwin python detected. Please rerun config/configure.py with cygwin-python ***'
15085ef4d1eSSatish Balay    print '================================================================================='
15185ef4d1eSSatish Balay    sys.exit(3)
152d65f3bddSMatthew Knepley
15385ef4d1eSSatish Balay  # Threads don't work for cygwin & python-2.4, 2.5 etc..
15485ef4d1eSSatish Balay  if chkcygwinpythonver():
15571384062SSatish Balay    sys.argv.append('--useThreads=0')
156d65f3bddSMatthew Knepley    extraLogs.append('''\
157d65f3bddSMatthew Knepley================================================================================
15885ef4d1eSSatish Balay** Cygwin-python-2.4/2.5 detected. Threads do not work correctly with this version *
159d65f3bddSMatthew Knepley ********* Disabling thread usage for this run of config/configure.py **********
160d65f3bddSMatthew Knepley================================================================================''')
1619dabcff0SSatish Balay
16287282423SMatthew Knepley  # Should be run from the toplevel
1635d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
16487282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
16587282423SMatthew Knepley  if not os.path.isdir(pythonDir):
1665d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
16787282423SMatthew Knepley  if not os.path.isdir(bsDir):
168ec1ee742SBarry Smith    print '================================================================================='
1699c4310d5SMatthew Knepley    print '''++ Could not locate BuildSystem in %s/python.''' % os.getcwd()
170ec1ef0a0SSatish Balay    print '''++ Downloading it using "hg clone http://hg.mcs.anl.gov/petsc/BuildSystem %s/python/BuildSystem"''' % os.getcwd()
171ec1ee742SBarry Smith    print '================================================================================='
172ec1ef0a0SSatish Balay    (status,output) = commands.getstatusoutput('hg clone http://hg.mcs.anl.gov/petsc/BuildSystem python/BuildSystem')
1737d7624c9SBarry Smith    if status:
1747d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
175ec1ee742SBarry Smith        print '================================================================================='
17659dc5438SMatthew Knepley        print '''** Unable to locate hg (Mercurial) to download BuildSystem; make sure hg is in your path'''
177d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
17859dc5438SMatthew Knepley        print '''** you do have hg installed and can clone BuildSystem. '''
179ec1ee742SBarry Smith        print '================================================================================='
1807d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
181ec1ee742SBarry Smith        print '================================================================================='
182d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
183d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
184ec1ee742SBarry Smith        print '================================================================================='
1857d7624c9SBarry Smith      else:
186ec1ee742SBarry Smith        print '================================================================================='
187d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
188ec1ee742SBarry Smith        print '================================================================================='
1897d7624c9SBarry Smith      print output
19087282423SMatthew Knepley      sys.exit(3)
1914f8a5b45SBarry Smith
19287282423SMatthew Knepley  sys.path.insert(0, bsDir)
1935d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
194e69ef9dfSMatthew Knepley  import config.base
1955d5a5a7bSMatthew Knepley  import config.framework
196f56be888SMatthew Knepley  import cPickle
1974f8a5b45SBarry Smith
1982e22a60eSMatthew Knepley  # Disable shared libraries by default
1992e22a60eSMatthew Knepley  import nargs
2002e22a60eSMatthew Knepley  if nargs.Arg.findArgument('with-shared', sys.argv[1:]) is None:
2012e22a60eSMatthew Knepley    sys.argv.append('--with-shared=0')
2022e22a60eSMatthew Knepley
2039dd2fdb1SMatthew Knepley  framework = None
2049dd2fdb1SMatthew Knepley  try:
205637cc2ebSSatish Balay    framework = config.framework.Framework(sys.argv[1:]+['--configModules=PETSc.Configure','--optionsModule=PETSc.compilerOptions'], loadArgDB = 0)
206d65f3bddSMatthew Knepley    framework.setup()
207d65f3bddSMatthew Knepley    framework.logPrint('\n'.join(extraLogs))
208f24f64feSBarry Smith    framework.configure(out = sys.stdout)
209358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
210f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
2117cfd0b05SBarry Smith    import PETSc.packages
2127cfd0b05SBarry Smith    for i in framework.packages:
2137cfd0b05SBarry Smith      if hasattr(i,'postProcess'):
2147cfd0b05SBarry Smith        i.postProcess()
2157cfd0b05SBarry Smith    framework.logClear()
216dd50d019SBarry Smith    return 0
217e69ef9dfSMatthew Knepley  except (RuntimeError, config.base.ConfigureSetupError), e:
2187d670a3cSBarry Smith    emsg = str(e)
21942351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
220fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
221fe09c992SBarry Smith    +'         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):\n' \
222fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
2237d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
224e9f3bb17SBarry Smith    se = ''
2259dd2fdb1SMatthew Knepley  except (TypeError, ValueError), e:
2267d670a3cSBarry Smith    emsg = str(e)
22742351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
228fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
229fe09c992SBarry Smith    +'                ERROR in COMMAND LINE ARGUMENT to config/configure.py \n' \
230fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
2317d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
2321a02243aSBarry Smith    se = ''
23396dc2fe8SMatthew Knepley  except ImportError, e :
2347d670a3cSBarry Smith    emsg = str(e)
23542351d26SSatish Balay    if not emsg.endswith('\n'): emsg = emsg+'\n'
236fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
237fe09c992SBarry Smith    +'                     UNABLE to FIND MODULE for config/configure.py \n' \
238fe09c992SBarry Smith    +'---------------------------------------------------------------------------------------\n'  \
2397d670a3cSBarry Smith    +emsg+'*********************************************************************************\n'
24096dc2fe8SMatthew Knepley    se = ''
24101def6f0SMatthew Knepley  except OSError, e :
24201def6f0SMatthew Knepley    emsg = str(e)
24301def6f0SMatthew Knepley    if not emsg.endswith('\n'): emsg = emsg+'\n'
24401def6f0SMatthew Knepley    msg ='*********************************************************************************\n'\
24501def6f0SMatthew Knepley    +'                    UNABLE to EXECUTE BINARIES for config/configure.py \n' \
24601def6f0SMatthew Knepley    +'---------------------------------------------------------------------------------------\n'  \
24701def6f0SMatthew Knepley    +emsg+'*********************************************************************************\n'
24801def6f0SMatthew Knepley    se = ''
249d7d3c4beSMatthew Knepley  except SystemExit, e:
250d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
251d7d3c4beSMatthew Knepley      return
252fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
253fe09c992SBarry Smith    +'           CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
254fe09c992SBarry Smith    +'*********************************************************************************\n'
255d7d3c4beSMatthew Knepley    se  = str(e)
256e9f3bb17SBarry Smith  except Exception, e:
257fe09c992SBarry Smith    msg ='*********************************************************************************\n'\
258fe09c992SBarry Smith    +'          CONFIGURATION CRASH  (Please send configure.log to petsc-maint@mcs.anl.gov)\n' \
259fe09c992SBarry Smith    +'*********************************************************************************\n'
260e9f3bb17SBarry Smith    se  = str(e)
261e9f3bb17SBarry Smith
262e9f3bb17SBarry Smith  print msg
2639dd2fdb1SMatthew Knepley  if not framework is None:
2649dd2fdb1SMatthew Knepley    framework.logClear()
265e9f3bb17SBarry Smith    if hasattr(framework, 'log'):
266f6614063SBarry Smith      import traceback
267f24f64feSBarry Smith      framework.log.write(msg+se)
268f24f64feSBarry Smith      traceback.print_tb(sys.exc_info()[2], file = framework.log)
2692418bae5SMatthew Knepley      if os.path.isfile(framework.logName+'.bkp'):
2705a74f024SMatthew Knepley        if framework.debugIndent is None:
2715a74f024SMatthew Knepley          framework.debugIndent = '  '
2722418bae5SMatthew Knepley        framework.logPrintDivider()
2732418bae5SMatthew Knepley        framework.logPrintBox('Previous configure logs below', debugSection = None)
2742418bae5SMatthew Knepley        f = file(framework.logName+'.bkp')
2752418bae5SMatthew Knepley        framework.log.write(f.read())
2762418bae5SMatthew Knepley        f.close()
277e9f3bb17SBarry Smith      sys.exit(1)
2785a74f024SMatthew Knepley  else:
2795a74f024SMatthew Knepley    print se
2805a74f024SMatthew Knepley    import traceback
2815a74f024SMatthew Knepley    traceback.print_tb(sys.exc_info()[2])
2825d5a5a7bSMatthew Knepley
2835d5a5a7bSMatthew Knepleyif __name__ == '__main__':
284a030c540SBarry Smith  petsc_configure([])
285759acf64SBarry Smith
286