config_compiler.py 4.3 KB

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