config_compiler.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. from __future__ import division, absolute_import, print_function
  2. from distutils.core import Command
  3. from numpy.distutils import log
  4. #XXX: Linker flags
  5. def show_fortran_compilers(_cache=None):
  6. # Using cache to prevent infinite recursion.
  7. if _cache:
  8. return
  9. elif _cache is None:
  10. _cache = []
  11. _cache.append(1)
  12. from numpy.distutils.fcompiler import show_fcompilers
  13. import distutils.core
  14. dist = distutils.core._setup_distribution
  15. show_fcompilers(dist)
  16. class config_fc(Command):
  17. """ Distutils command to hold user specified options
  18. to Fortran compilers.
  19. config_fc command is used by the FCompiler.customize() method.
  20. """
  21. description = "specify Fortran 77/Fortran 90 compiler information"
  22. user_options = [
  23. ('fcompiler=', None, "specify Fortran compiler type"),
  24. ('f77exec=', None, "specify F77 compiler command"),
  25. ('f90exec=', None, "specify F90 compiler command"),
  26. ('f77flags=', None, "specify F77 compiler flags"),
  27. ('f90flags=', None, "specify F90 compiler flags"),
  28. ('opt=', None, "specify optimization flags"),
  29. ('arch=', None, "specify architecture specific optimization flags"),
  30. ('debug', 'g', "compile with debugging information"),
  31. ('noopt', None, "compile without optimization"),
  32. ('noarch', None, "compile without arch-dependent optimization"),
  33. ]
  34. help_options = [
  35. ('help-fcompiler', None, "list available Fortran compilers",
  36. show_fortran_compilers),
  37. ]
  38. boolean_options = ['debug', 'noopt', 'noarch']
  39. def initialize_options(self):
  40. self.fcompiler = None
  41. self.f77exec = None
  42. self.f90exec = None
  43. self.f77flags = None
  44. self.f90flags = None
  45. self.opt = None
  46. self.arch = None
  47. self.debug = None
  48. self.noopt = None
  49. self.noarch = None
  50. def finalize_options(self):
  51. log.info('unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options')
  52. build_clib = self.get_finalized_command('build_clib')
  53. build_ext = self.get_finalized_command('build_ext')
  54. config = self.get_finalized_command('config')
  55. build = self.get_finalized_command('build')
  56. cmd_list = [self, config, build_clib, build_ext, build]
  57. for a in ['fcompiler']:
  58. l = []
  59. for c in cmd_list:
  60. v = getattr(c, a)
  61. if v is not None:
  62. if not isinstance(v, str): v = v.compiler_type
  63. if v not in l: l.append(v)
  64. if not l: v1 = None
  65. else: v1 = l[0]
  66. if len(l)>1:
  67. log.warn(' commands have different --%s options: %s'\
  68. ', using first in list as default' % (a, l))
  69. if v1:
  70. for c in cmd_list:
  71. if getattr(c, a) is None: setattr(c, a, v1)
  72. def run(self):
  73. # Do nothing.
  74. return
  75. class config_cc(Command):
  76. """ Distutils command to hold user specified options
  77. to C/C++ compilers.
  78. """
  79. description = "specify C/C++ compiler information"
  80. user_options = [
  81. ('compiler=', None, "specify C/C++ compiler type"),
  82. ]
  83. def initialize_options(self):
  84. self.compiler = None
  85. def finalize_options(self):
  86. log.info('unifing config_cc, config, build_clib, build_ext, build commands --compiler options')
  87. build_clib = self.get_finalized_command('build_clib')
  88. build_ext = self.get_finalized_command('build_ext')
  89. config = self.get_finalized_command('config')
  90. build = self.get_finalized_command('build')
  91. cmd_list = [self, config, build_clib, build_ext, build]
  92. for a in ['compiler']:
  93. l = []
  94. for c in cmd_list:
  95. v = getattr(c, a)
  96. if v is not None:
  97. if not isinstance(v, str): v = v.compiler_type
  98. if v not in l: l.append(v)
  99. if not l: v1 = None
  100. else: v1 = l[0]
  101. if len(l)>1:
  102. log.warn(' commands have different --%s options: %s'\
  103. ', using first in list as default' % (a, l))
  104. if v1:
  105. for c in cmd_list:
  106. if getattr(c, a) is None: setattr(c, a, v1)
  107. return
  108. def run(self):
  109. # Do nothing.
  110. return