pg.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # http://www.pgroup.com
  2. import sys
  3. from numpy.distutils.fcompiler import FCompiler
  4. from sys import platform
  5. from os.path import join, dirname, normpath
  6. compilers = ['PGroupFCompiler', 'PGroupFlangCompiler']
  7. class PGroupFCompiler(FCompiler):
  8. compiler_type = 'pg'
  9. description = 'Portland Group Fortran Compiler'
  10. version_pattern = r'\s*pg(f77|f90|hpf|fortran) (?P<version>[\d.-]+).*'
  11. if platform == 'darwin':
  12. executables = {
  13. 'version_cmd': ["<F77>", "-V"],
  14. 'compiler_f77': ["pgfortran", "-dynamiclib"],
  15. 'compiler_fix': ["pgfortran", "-Mfixed", "-dynamiclib"],
  16. 'compiler_f90': ["pgfortran", "-dynamiclib"],
  17. 'linker_so': ["libtool"],
  18. 'archiver': ["ar", "-cr"],
  19. 'ranlib': ["ranlib"]
  20. }
  21. pic_flags = ['']
  22. else:
  23. executables = {
  24. 'version_cmd': ["<F77>", "-V"],
  25. 'compiler_f77': ["pgfortran"],
  26. 'compiler_fix': ["pgfortran", "-Mfixed"],
  27. 'compiler_f90': ["pgfortran"],
  28. 'linker_so': ["<F90>"],
  29. 'archiver': ["ar", "-cr"],
  30. 'ranlib': ["ranlib"]
  31. }
  32. pic_flags = ['-fpic']
  33. module_dir_switch = '-module '
  34. module_include_switch = '-I'
  35. def get_flags(self):
  36. opt = ['-Minform=inform', '-Mnosecond_underscore']
  37. return self.pic_flags + opt
  38. def get_flags_opt(self):
  39. return ['-fast']
  40. def get_flags_debug(self):
  41. return ['-g']
  42. if platform == 'darwin':
  43. def get_flags_linker_so(self):
  44. return ["-dynamic", '-undefined', 'dynamic_lookup']
  45. else:
  46. def get_flags_linker_so(self):
  47. return ["-shared", '-fpic']
  48. def runtime_library_dir_option(self, dir):
  49. return '-R%s' % dir
  50. import functools
  51. class PGroupFlangCompiler(FCompiler):
  52. compiler_type = 'flang'
  53. description = 'Portland Group Fortran LLVM Compiler'
  54. version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*'
  55. ar_exe = 'lib.exe'
  56. possible_executables = ['flang']
  57. executables = {
  58. 'version_cmd': ["<F77>", "--version"],
  59. 'compiler_f77': ["flang"],
  60. 'compiler_fix': ["flang"],
  61. 'compiler_f90': ["flang"],
  62. 'linker_so': [None],
  63. 'archiver': [ar_exe, "/verbose", "/OUT:"],
  64. 'ranlib': None
  65. }
  66. library_switch = '/OUT:' # No space after /OUT:!
  67. module_dir_switch = '-module ' # Don't remove ending space!
  68. def get_libraries(self):
  69. opt = FCompiler.get_libraries(self)
  70. opt.extend(['flang', 'flangrti', 'ompstub'])
  71. return opt
  72. @functools.lru_cache(maxsize=128)
  73. def get_library_dirs(self):
  74. """List of compiler library directories."""
  75. opt = FCompiler.get_library_dirs(self)
  76. flang_dir = dirname(self.executables['compiler_f77'][0])
  77. opt.append(normpath(join(flang_dir, '..', 'lib')))
  78. return opt
  79. def get_flags(self):
  80. return []
  81. def get_flags_free(self):
  82. return []
  83. def get_flags_debug(self):
  84. return ['-g']
  85. def get_flags_opt(self):
  86. return ['-O3']
  87. def get_flags_arch(self):
  88. return []
  89. def runtime_library_dir_option(self, dir):
  90. raise NotImplementedError
  91. if __name__ == '__main__':
  92. from distutils import log
  93. log.set_verbosity(2)
  94. from numpy.distutils import customized_fcompiler
  95. if 'flang' in sys.argv:
  96. print(customized_fcompiler(compiler='flang').get_version())
  97. else:
  98. print(customized_fcompiler(compiler='pg').get_version())