nag.py 2.5 KB

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