absoft.py 5.4 KB

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