nag.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import sys
  2. import re
  3. from numpy.distutils.fcompiler import FCompiler
  4. compilers = ['NAGFCompiler', 'NAGFORCompiler']
  5. class BaseNAGFCompiler(FCompiler):
  6. version_pattern = r'NAG.* Release (?P<version>[^(\s]*)'
  7. def version_match(self, version_string):
  8. m = re.search(self.version_pattern, version_string)
  9. if m:
  10. return m.group('version')
  11. else:
  12. return None
  13. def get_flags_linker_so(self):
  14. return ["-Wl,-shared"]
  15. def get_flags_opt(self):
  16. return ['-O4']
  17. def get_flags_arch(self):
  18. return []
  19. class NAGFCompiler(BaseNAGFCompiler):
  20. compiler_type = 'nag'
  21. description = 'NAGWare Fortran 95 Compiler'
  22. executables = {
  23. 'version_cmd' : ["<F90>", "-V"],
  24. 'compiler_f77' : ["f95", "-fixed"],
  25. 'compiler_fix' : ["f95", "-fixed"],
  26. 'compiler_f90' : ["f95"],
  27. 'linker_so' : ["<F90>"],
  28. 'archiver' : ["ar", "-cr"],
  29. 'ranlib' : ["ranlib"]
  30. }
  31. def get_flags_linker_so(self):
  32. if sys.platform == 'darwin':
  33. return ['-unsharedf95', '-Wl,-bundle,-flat_namespace,-undefined,suppress']
  34. return BaseNAGFCompiler.get_flags_linker_so(self)
  35. def get_flags_arch(self):
  36. version = self.get_version()
  37. if version and version < '5.1':
  38. return ['-target=native']
  39. else:
  40. return BaseNAGFCompiler.get_flags_arch(self)
  41. def get_flags_debug(self):
  42. return ['-g', '-gline', '-g90', '-nan', '-C']
  43. class NAGFORCompiler(BaseNAGFCompiler):
  44. compiler_type = 'nagfor'
  45. description = 'NAG Fortran Compiler'
  46. executables = {
  47. 'version_cmd' : ["nagfor", "-V"],
  48. 'compiler_f77' : ["nagfor", "-fixed"],
  49. 'compiler_fix' : ["nagfor", "-fixed"],
  50. 'compiler_f90' : ["nagfor"],
  51. 'linker_so' : ["nagfor"],
  52. 'archiver' : ["ar", "-cr"],
  53. 'ranlib' : ["ranlib"]
  54. }
  55. def get_flags_debug(self):
  56. version = self.get_version()
  57. if version and version > '6.1':
  58. return ['-g', '-u', '-nan', '-C=all', '-thread_safe',
  59. '-kind=unique', '-Warn=allocation', '-Warn=subnormal']
  60. else:
  61. return ['-g', '-nan', '-C=all', '-u', '-thread_safe']
  62. if __name__ == '__main__':
  63. from distutils import log
  64. log.set_verbosity(2)
  65. from numpy.distutils import customized_fcompiler
  66. compiler = customized_fcompiler(compiler='nagfor')
  67. print(compiler.get_version())
  68. print(compiler.get_flags_debug())