annotate DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/distutils/fcompiler/ibm.py @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2a2c65a20a8b
children
rev   line source
Chris@87 1 from __future__ import division, absolute_import, print_function
Chris@87 2
Chris@87 3 import os
Chris@87 4 import re
Chris@87 5 import sys
Chris@87 6
Chris@87 7 from numpy.distutils.fcompiler import FCompiler
Chris@87 8 from numpy.distutils.exec_command import exec_command, find_executable
Chris@87 9 from numpy.distutils.misc_util import make_temp_file
Chris@87 10 from distutils import log
Chris@87 11
Chris@87 12 compilers = ['IBMFCompiler']
Chris@87 13
Chris@87 14 class IBMFCompiler(FCompiler):
Chris@87 15 compiler_type = 'ibm'
Chris@87 16 description = 'IBM XL Fortran Compiler'
Chris@87 17 version_pattern = r'(xlf\(1\)\s*|)IBM XL Fortran ((Advanced Edition |)Version |Enterprise Edition V|for AIX, V)(?P<version>[^\s*]*)'
Chris@87 18 #IBM XL Fortran Enterprise Edition V10.1 for AIX \nVersion: 10.01.0000.0004
Chris@87 19
Chris@87 20 executables = {
Chris@87 21 'version_cmd' : ["<F77>", "-qversion"],
Chris@87 22 'compiler_f77' : ["xlf"],
Chris@87 23 'compiler_fix' : ["xlf90", "-qfixed"],
Chris@87 24 'compiler_f90' : ["xlf90"],
Chris@87 25 'linker_so' : ["xlf95"],
Chris@87 26 'archiver' : ["ar", "-cr"],
Chris@87 27 'ranlib' : ["ranlib"]
Chris@87 28 }
Chris@87 29
Chris@87 30 def get_version(self,*args,**kwds):
Chris@87 31 version = FCompiler.get_version(self,*args,**kwds)
Chris@87 32
Chris@87 33 if version is None and sys.platform.startswith('aix'):
Chris@87 34 # use lslpp to find out xlf version
Chris@87 35 lslpp = find_executable('lslpp')
Chris@87 36 xlf = find_executable('xlf')
Chris@87 37 if os.path.exists(xlf) and os.path.exists(lslpp):
Chris@87 38 s, o = exec_command(lslpp + ' -Lc xlfcmp')
Chris@87 39 m = re.search('xlfcmp:(?P<version>\d+([.]\d+)+)', o)
Chris@87 40 if m: version = m.group('version')
Chris@87 41
Chris@87 42 xlf_dir = '/etc/opt/ibmcmp/xlf'
Chris@87 43 if version is None and os.path.isdir(xlf_dir):
Chris@87 44 # linux:
Chris@87 45 # If the output of xlf does not contain version info
Chris@87 46 # (that's the case with xlf 8.1, for instance) then
Chris@87 47 # let's try another method:
Chris@87 48 l = sorted(os.listdir(xlf_dir))
Chris@87 49 l.reverse()
Chris@87 50 l = [d for d in l if os.path.isfile(os.path.join(xlf_dir, d, 'xlf.cfg'))]
Chris@87 51 if l:
Chris@87 52 from distutils.version import LooseVersion
Chris@87 53 self.version = version = LooseVersion(l[0])
Chris@87 54 return version
Chris@87 55
Chris@87 56 def get_flags(self):
Chris@87 57 return ['-qextname']
Chris@87 58
Chris@87 59 def get_flags_debug(self):
Chris@87 60 return ['-g']
Chris@87 61
Chris@87 62 def get_flags_linker_so(self):
Chris@87 63 opt = []
Chris@87 64 if sys.platform=='darwin':
Chris@87 65 opt.append('-Wl,-bundle,-flat_namespace,-undefined,suppress')
Chris@87 66 else:
Chris@87 67 opt.append('-bshared')
Chris@87 68 version = self.get_version(ok_status=[0, 40])
Chris@87 69 if version is not None:
Chris@87 70 if sys.platform.startswith('aix'):
Chris@87 71 xlf_cfg = '/etc/xlf.cfg'
Chris@87 72 else:
Chris@87 73 xlf_cfg = '/etc/opt/ibmcmp/xlf/%s/xlf.cfg' % version
Chris@87 74 fo, new_cfg = make_temp_file(suffix='_xlf.cfg')
Chris@87 75 log.info('Creating '+new_cfg)
Chris@87 76 fi = open(xlf_cfg, 'r')
Chris@87 77 crt1_match = re.compile(r'\s*crt\s*[=]\s*(?P<path>.*)/crt1.o').match
Chris@87 78 for line in fi:
Chris@87 79 m = crt1_match(line)
Chris@87 80 if m:
Chris@87 81 fo.write('crt = %s/bundle1.o\n' % (m.group('path')))
Chris@87 82 else:
Chris@87 83 fo.write(line)
Chris@87 84 fi.close()
Chris@87 85 fo.close()
Chris@87 86 opt.append('-F'+new_cfg)
Chris@87 87 return opt
Chris@87 88
Chris@87 89 def get_flags_opt(self):
Chris@87 90 return ['-O3']
Chris@87 91
Chris@87 92 if __name__ == '__main__':
Chris@87 93 log.set_verbosity(2)
Chris@87 94 compiler = IBMFCompiler()
Chris@87 95 compiler.customize()
Chris@87 96 print(compiler.get_version())