fc_xlf.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # harald at klimachs.de
  4. import re
  5. from waflib import Utils,Errors
  6. from waflib.Tools import fc,fc_config,fc_scan
  7. from waflib.Configure import conf
  8. from waflib.Tools.compiler_fc import fc_compiler
  9. fc_compiler['aix'].insert(0, 'fc_xlf')
  10. @conf
  11. def find_xlf(conf):
  12. """Find the xlf program (will look in the environment variable 'FC')"""
  13. fc = conf.find_program(['xlf2003_r', 'xlf2003', 'xlf95_r', 'xlf95', 'xlf90_r', 'xlf90', 'xlf_r', 'xlf'], var='FC')
  14. conf.get_xlf_version(fc)
  15. conf.env.FC_NAME='XLF'
  16. @conf
  17. def xlf_flags(conf):
  18. v = conf.env
  19. v['FCDEFINES_ST'] = '-WF,-D%s'
  20. v['FCFLAGS_fcshlib'] = ['-qpic=small']
  21. v['FCFLAGS_DEBUG'] = ['-qhalt=w']
  22. v['LINKFLAGS_fcshlib'] = ['-Wl,-shared']
  23. @conf
  24. def xlf_modifier_platform(conf):
  25. dest_os = conf.env['DEST_OS'] or Utils.unversioned_sys_platform()
  26. xlf_modifier_func = getattr(conf, 'xlf_modifier_' + dest_os, None)
  27. if xlf_modifier_func:
  28. xlf_modifier_func()
  29. @conf
  30. def get_xlf_version(conf, fc):
  31. """Get the compiler version"""
  32. cmd = fc + ['-qversion']
  33. try:
  34. out, err = conf.cmd_and_log(cmd, output=0)
  35. except Errors.WafError:
  36. conf.fatal('Could not find xlf %r' % cmd)
  37. for v in (r"IBM XL Fortran.* V(?P<major>\d*)\.(?P<minor>\d*)",):
  38. version_re = re.compile(v, re.I).search
  39. match = version_re(out or err)
  40. if match:
  41. k = match.groupdict()
  42. conf.env['FC_VERSION'] = (k['major'], k['minor'])
  43. break
  44. else:
  45. conf.fatal('Could not determine the XLF version.')
  46. def configure(conf):
  47. conf.find_xlf()
  48. conf.find_ar()
  49. conf.fc_flags()
  50. conf.fc_add_flags()
  51. conf.xlf_flags()
  52. conf.xlf_modifier_platform()