absoft.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # http://www.absoft.com/literature/osxuserguide.pdf
  2. # http://www.absoft.com/documentation.html
  3. # Notes:
  4. # - when using -g77 then use -DUNDERSCORE_G77 to compile f2py
  5. # generated extension modules (works for f2py v2.45.241_1936 and up)
  6. from __future__ import division, absolute_import, print_function
  7. import os
  8. from numpy.distutils.cpuinfo import cpu
  9. from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
  10. from numpy.distutils.misc_util import cyg2win32
  11. compilers = ['AbsoftFCompiler']
  12. class AbsoftFCompiler(FCompiler):
  13. compiler_type = 'absoft'
  14. description = 'Absoft Corp Fortran Compiler'
  15. #version_pattern = r'FORTRAN 77 Compiler (?P<version>[^\s*,]*).*?Absoft Corp'
  16. version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Copyright Absoft Corporation.*?Version))'+\
  17. r' (?P<version>[^\s*,]*)(.*?Absoft Corp|)'
  18. # on windows: f90 -V -c dummy.f
  19. # f90: Copyright Absoft Corporation 1994-1998 mV2; Cray Research, Inc. 1994-1996 CF90 (2.x.x.x f36t87) Version 2.3 Wed Apr 19, 2006 13:05:16
  20. # samt5735(8)$ f90 -V -c dummy.f
  21. # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0
  22. # Note that fink installs g77 as f77, so need to use f90 for detection.
  23. executables = {
  24. 'version_cmd' : None, # set by update_executables
  25. 'compiler_f77' : ["f77"],
  26. 'compiler_fix' : ["f90"],
  27. 'compiler_f90' : ["f90"],
  28. 'linker_so' : ["<F90>"],
  29. 'archiver' : ["ar", "-cr"],
  30. 'ranlib' : ["ranlib"]
  31. }
  32. if os.name=='nt':
  33. library_switch = '/out:' #No space after /out:!
  34. module_dir_switch = None
  35. module_include_switch = '-p'
  36. def update_executables(self):
  37. f = cyg2win32(dummy_fortran_file())
  38. self.executables['version_cmd'] = ['<F90>', '-V', '-c',
  39. f+'.f', '-o', f+'.o']
  40. def get_flags_linker_so(self):
  41. if os.name=='nt':
  42. opt = ['/dll']
  43. # The "-K shared" switches are being left in for pre-9.0 versions
  44. # of Absoft though I don't think versions earlier than 9 can
  45. # actually be used to build shared libraries. In fact, version
  46. # 8 of Absoft doesn't recognize "-K shared" and will fail.
  47. elif self.get_version() >= '9.0':
  48. opt = ['-shared']
  49. else:
  50. opt = ["-K", "shared"]
  51. return opt
  52. def library_dir_option(self, dir):
  53. if os.name=='nt':
  54. return ['-link', '/PATH:%s' % (dir)]
  55. return "-L" + dir
  56. def library_option(self, lib):
  57. if os.name=='nt':
  58. return '%s.lib' % (lib)
  59. return "-l" + lib
  60. def get_library_dirs(self):
  61. opt = FCompiler.get_library_dirs(self)
  62. d = os.environ.get('ABSOFT')
  63. if d:
  64. if self.get_version() >= '10.0':
  65. # use shared libraries, the static libraries were not compiled -fPIC
  66. prefix = 'sh'
  67. else:
  68. prefix = ''
  69. if cpu.is_64bit():
  70. suffix = '64'
  71. else:
  72. suffix = ''
  73. opt.append(os.path.join(d, '%slib%s' % (prefix, suffix)))
  74. return opt
  75. def get_libraries(self):
  76. opt = FCompiler.get_libraries(self)
  77. if self.get_version() >= '11.0':
  78. opt.extend(['af90math', 'afio', 'af77math', 'amisc'])
  79. elif self.get_version() >= '10.0':
  80. opt.extend(['af90math', 'afio', 'af77math', 'U77'])
  81. elif self.get_version() >= '8.0':
  82. opt.extend(['f90math', 'fio', 'f77math', 'U77'])
  83. else:
  84. opt.extend(['fio', 'f90math', 'fmath', 'U77'])
  85. if os.name =='nt':
  86. opt.append('COMDLG32')
  87. return opt
  88. def get_flags(self):
  89. opt = FCompiler.get_flags(self)
  90. if os.name != 'nt':
  91. opt.extend(['-s'])
  92. if self.get_version():
  93. if self.get_version()>='8.2':
  94. opt.append('-fpic')
  95. return opt
  96. def get_flags_f77(self):
  97. opt = FCompiler.get_flags_f77(self)
  98. opt.extend(['-N22', '-N90', '-N110'])
  99. v = self.get_version()
  100. if os.name == 'nt':
  101. if v and v>='8.0':
  102. opt.extend(['-f', '-N15'])
  103. else:
  104. opt.append('-f')
  105. if v:
  106. if v<='4.6':
  107. opt.append('-B108')
  108. else:
  109. # Though -N15 is undocumented, it works with
  110. # Absoft 8.0 on Linux
  111. opt.append('-N15')
  112. return opt
  113. def get_flags_f90(self):
  114. opt = FCompiler.get_flags_f90(self)
  115. opt.extend(["-YCFRL=1", "-YCOM_NAMES=LCS", "-YCOM_PFX", "-YEXT_PFX",
  116. "-YCOM_SFX=_", "-YEXT_SFX=_", "-YEXT_NAMES=LCS"])
  117. if self.get_version():
  118. if self.get_version()>'4.6':
  119. opt.extend(["-YDEALLOC=ALL"])
  120. return opt
  121. def get_flags_fix(self):
  122. opt = FCompiler.get_flags_fix(self)
  123. opt.extend(["-YCFRL=1", "-YCOM_NAMES=LCS", "-YCOM_PFX", "-YEXT_PFX",
  124. "-YCOM_SFX=_", "-YEXT_SFX=_", "-YEXT_NAMES=LCS"])
  125. opt.extend(["-f", "fixed"])
  126. return opt
  127. def get_flags_opt(self):
  128. opt = ['-O']
  129. return opt
  130. if __name__ == '__main__':
  131. from distutils import log
  132. log.set_verbosity(2)
  133. from numpy.distutils import customized_fcompiler
  134. print(customized_fcompiler(compiler='absoft').get_version())