|
1 | 1 | # http://www.pgroup.com |
2 | 2 | from __future__ import division, absolute_import, print_function |
3 | 3 |
|
4 | | -from numpy.distutils.fcompiler import FCompiler |
| 4 | +import sys |
| 5 | +import os |
| 6 | + |
| 7 | +from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file |
5 | 8 | from sys import platform |
| 9 | +from os.path import join, dirname, normpath |
| 10 | + |
| 11 | +compilers = ['PGroupFCompiler', 'PGroupFlangCompiler'] |
6 | 12 |
|
7 | | -compilers = ['PGroupFCompiler'] |
8 | 13 |
|
9 | 14 | class PGroupFCompiler(FCompiler): |
10 | 15 |
|
11 | 16 | compiler_type = 'pg' |
12 | 17 | description = 'Portland Group Fortran Compiler' |
13 | | - version_pattern = r'\s*pg(f77|f90|hpf|fortran) (?P<version>[\d.-]+).*' |
| 18 | + version_pattern = r'\s*pg(f77|f90|hpf|fortran) (?P<version>[\d.-]+).*' |
14 | 19 |
|
15 | 20 | if platform == 'darwin': |
16 | 21 | executables = { |
17 | | - 'version_cmd' : ["<F77>", "-V"], |
18 | | - 'compiler_f77' : ["pgfortran", "-dynamiclib"], |
19 | | - 'compiler_fix' : ["pgfortran", "-Mfixed", "-dynamiclib"], |
20 | | - 'compiler_f90' : ["pgfortran", "-dynamiclib"], |
21 | | - 'linker_so' : ["libtool"], |
22 | | - 'archiver' : ["ar", "-cr"], |
23 | | - 'ranlib' : ["ranlib"] |
| 22 | + 'version_cmd': ["<F77>", "-V"], |
| 23 | + 'compiler_f77': ["pgfortran", "-dynamiclib"], |
| 24 | + 'compiler_fix': ["pgfortran", "-Mfixed", "-dynamiclib"], |
| 25 | + 'compiler_f90': ["pgfortran", "-dynamiclib"], |
| 26 | + 'linker_so': ["libtool"], |
| 27 | + 'archiver': ["ar", "-cr"], |
| 28 | + 'ranlib': ["ranlib"] |
24 | 29 | } |
25 | 30 | pic_flags = [''] |
26 | 31 | else: |
27 | 32 | executables = { |
28 | | - 'version_cmd' : ["<F77>", "-V"], |
29 | | - 'compiler_f77' : ["pgfortran"], |
30 | | - 'compiler_fix' : ["pgfortran", "-Mfixed"], |
31 | | - 'compiler_f90' : ["pgfortran"], |
32 | | - 'linker_so' : ["pgfortran", "-shared", "-fpic"], |
33 | | - 'archiver' : ["ar", "-cr"], |
34 | | - 'ranlib' : ["ranlib"] |
| 33 | + 'version_cmd': ["<F77>", "-V"], |
| 34 | + 'compiler_f77': ["pgfortran"], |
| 35 | + 'compiler_fix': ["pgfortran", "-Mfixed"], |
| 36 | + 'compiler_f90': ["pgfortran"], |
| 37 | + 'linker_so': ["pgfortran", "-shared", "-fpic"], |
| 38 | + 'archiver': ["ar", "-cr"], |
| 39 | + 'ranlib': ["ranlib"] |
35 | 40 | } |
36 | 41 | pic_flags = ['-fpic'] |
37 | 42 |
|
38 | | - |
39 | 43 | module_dir_switch = '-module ' |
40 | 44 | module_include_switch = '-I' |
41 | 45 |
|
42 | 46 | def get_flags(self): |
43 | 47 | opt = ['-Minform=inform', '-Mnosecond_underscore'] |
44 | 48 | return self.pic_flags + opt |
| 49 | + |
45 | 50 | def get_flags_opt(self): |
46 | 51 | return ['-fast'] |
| 52 | + |
47 | 53 | def get_flags_debug(self): |
48 | 54 | return ['-g'] |
49 | 55 |
|
@@ -54,8 +60,82 @@ def get_flags_linker_so(self): |
54 | 60 | def runtime_library_dir_option(self, dir): |
55 | 61 | return '-R"%s"' % dir |
56 | 62 |
|
| 63 | + |
| 64 | +if sys.version_info >= (3, 5): |
| 65 | + import subprocess |
| 66 | + import shlex |
| 67 | + import functools |
| 68 | + |
| 69 | + class PGroupFlangCompiler(FCompiler): |
| 70 | + compiler_type = 'flang' |
| 71 | + description = 'Portland Group Fortran LLVM Compiler' |
| 72 | + version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*' |
| 73 | + |
| 74 | + ar_exe = 'lib.exe' |
| 75 | + possible_executables = ['flang'] |
| 76 | + |
| 77 | + executables = { |
| 78 | + 'version_cmd': ["<F77>", "--version"], |
| 79 | + 'compiler_f77': ["flang"], |
| 80 | + 'compiler_fix': ["flang"], |
| 81 | + 'compiler_f90': ["flang"], |
| 82 | + 'linker_so': [None], |
| 83 | + 'archiver': [ar_exe, "/verbose", "/OUT:"], |
| 84 | + 'ranlib': None |
| 85 | + } |
| 86 | + |
| 87 | + library_switch = '/OUT:' # No space after /OUT:! |
| 88 | + module_dir_switch = '-module ' # Don't remove ending space! |
| 89 | + |
| 90 | + def get_libraries(self): |
| 91 | + opt = FCompiler.get_libraries(self) |
| 92 | + opt.extend(['flang', 'flangrti', 'ompstub']) |
| 93 | + return opt |
| 94 | + |
| 95 | + @functools.lru_cache(maxsize=128) |
| 96 | + def get_library_dirs(self): |
| 97 | + """List of compiler library directories.""" |
| 98 | + opt = FCompiler.get_library_dirs(self) |
| 99 | + flang_dir = dirname(self.executables['compiler_f77'][0]) |
| 100 | + opt.append(normpath(join(flang_dir, '..', 'lib'))) |
| 101 | + |
| 102 | + return opt |
| 103 | + |
| 104 | + def get_flags(self): |
| 105 | + return [] |
| 106 | + |
| 107 | + def get_flags_free(self): |
| 108 | + return [] |
| 109 | + |
| 110 | + def get_flags_debug(self): |
| 111 | + return ['-g'] |
| 112 | + |
| 113 | + def get_flags_opt(self): |
| 114 | + return ['-O3'] |
| 115 | + |
| 116 | + def get_flags_arch(self): |
| 117 | + return [] |
| 118 | + |
| 119 | + def runtime_library_dir_option(self, dir): |
| 120 | + raise NotImplementedError |
| 121 | + |
| 122 | +else: |
| 123 | + from numpy.distutils.fcompiler import CompilerNotFound |
| 124 | + |
| 125 | + # No point in supporting on older Pythons because not ABI compatible |
| 126 | + class PGroupFlangCompiler(FCompiler): |
| 127 | + compiler_type = 'flang' |
| 128 | + description = 'Portland Group Fortran LLVM Compiler' |
| 129 | + |
| 130 | + def get_version(self): |
| 131 | + raise CompilerNotFound('Flang unsupported on Python < 3.5') |
| 132 | + |
| 133 | + |
57 | 134 | if __name__ == '__main__': |
58 | 135 | from distutils import log |
59 | 136 | log.set_verbosity(2) |
60 | 137 | from numpy.distutils import customized_fcompiler |
61 | | - print(customized_fcompiler(compiler='pg').get_version()) |
| 138 | + if 'flang' in sys.argv: |
| 139 | + print(customized_fcompiler(compiler='flang').get_version()) |
| 140 | + else: |
| 141 | + print(customized_fcompiler(compiler='pg').get_version()) |