ccrx.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright 2012-2019 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. """Representations specific to the Renesas CC-RX compiler family."""
  12. import os
  13. import typing as T
  14. from ...mesonlib import EnvironmentException
  15. if T.TYPE_CHECKING:
  16. from ...environment import Environment
  17. ccrx_buildtype_args = {
  18. 'plain': [],
  19. 'debug': [],
  20. 'debugoptimized': [],
  21. 'release': [],
  22. 'minsize': [],
  23. 'custom': [],
  24. } # type: T.Dict[str, T.List[str]]
  25. ccrx_optimization_args = {
  26. '0': ['-optimize=0'],
  27. 'g': ['-optimize=0'],
  28. '1': ['-optimize=1'],
  29. '2': ['-optimize=2'],
  30. '3': ['-optimize=max'],
  31. 's': ['-optimize=2', '-size']
  32. } # type: T.Dict[str, T.List[str]]
  33. ccrx_debug_args = {
  34. False: [],
  35. True: ['-debug']
  36. } # type: T.Dict[bool, T.List[str]]
  37. class CcrxCompiler:
  38. def __init__(self):
  39. if not self.is_cross:
  40. raise EnvironmentException('ccrx supports only cross-compilation.')
  41. self.id = 'ccrx'
  42. # Assembly
  43. self.can_compile_suffixes.add('src')
  44. default_warn_args = [] # type: T.List[str]
  45. self.warn_args = {'0': [],
  46. '1': default_warn_args,
  47. '2': default_warn_args + [],
  48. '3': default_warn_args + []}
  49. def get_pic_args(self) -> T.List[str]:
  50. # PIC support is not enabled by default for CCRX,
  51. # if users want to use it, they need to add the required arguments explicitly
  52. return []
  53. def get_buildtype_args(self, buildtype: str) -> T.List[str]:
  54. return ccrx_buildtype_args[buildtype]
  55. def get_pch_suffix(self) -> str:
  56. return 'pch'
  57. def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
  58. return []
  59. # Override CCompiler.get_dependency_gen_args
  60. def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
  61. return []
  62. def thread_flags(self, env: 'Environment') -> T.List[str]:
  63. return []
  64. def get_coverage_args(self) -> T.List[str]:
  65. return []
  66. def get_no_stdinc_args(self) -> T.List[str]:
  67. return []
  68. def get_no_stdlib_link_args(self) -> T.List[str]:
  69. return []
  70. def get_optimization_args(self, optimization_level: str) -> T.List[str]:
  71. return ccrx_optimization_args[optimization_level]
  72. def get_debug_args(self, is_debug: bool) -> T.List[str]:
  73. return ccrx_debug_args[is_debug]
  74. @classmethod
  75. def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
  76. result = []
  77. for i in args:
  78. if i.startswith('-D'):
  79. i = '-define=' + i[2:]
  80. if i.startswith('-I'):
  81. i = '-include=' + i[2:]
  82. if i.startswith('-Wl,-rpath='):
  83. continue
  84. elif i == '--print-search-dirs':
  85. continue
  86. elif i.startswith('-L'):
  87. continue
  88. elif not i.startswith('-lib=') and i.endswith(('.a', '.lib')):
  89. i = '-lib=' + i
  90. result.append(i)
  91. return result
  92. def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
  93. for idx, i in enumerate(parameter_list):
  94. if i[:9] == '-include=':
  95. parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
  96. return parameter_list