diff options
| author | Nomura <nomura.rh@gmail.com> | 2023-03-28 11:25:19 +0200 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-04-24 09:07:37 -0400 |
| commit | 18cfa545f03ddb6cb8378fdadec4f284aa7ea221 (patch) | |
| tree | d75c230d056ad9224087380d213e54a5ace40f87 /mesonbuild/compilers/mixins/metrowerks.py | |
| parent | bda799dff2dc4b5d607f0e822b12ed0e2db38fb7 (diff) | |
| download | meson-18cfa545f03ddb6cb8378fdadec4f284aa7ea221.tar.gz | |
Initial support for Metrowerks C/C++ compiler
Diffstat (limited to 'mesonbuild/compilers/mixins/metrowerks.py')
| -rw-r--r-- | mesonbuild/compilers/mixins/metrowerks.py | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/mesonbuild/compilers/mixins/metrowerks.py b/mesonbuild/compilers/mixins/metrowerks.py new file mode 100644 index 000000000..89c612835 --- /dev/null +++ b/mesonbuild/compilers/mixins/metrowerks.py @@ -0,0 +1,232 @@ +# Copyright 2012-2019 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import annotations + +"""Representations specific to the Metrowerks/Freescale Embedded C/C++ compiler family.""" + +import os +import typing as T + +from ...mesonlib import EnvironmentException, OptionKey + +if T.TYPE_CHECKING: + from ...envconfig import MachineInfo + from ...compilers.compilers import Compiler, CompileCheckMode +else: + # This is a bit clever, for mypy we pretend that these mixins descend from + # Compiler, so we get all of the methods and attributes defined for us, but + # for runtime we make them descend from object (which all classes normally + # do). This gives up DRYer type checking, with no runtime impact + Compiler = object + +mwcc_buildtype_args = { + 'plain': [], + 'debug': ['-g'], + 'debugoptimized': ['-g', '-O4'], + 'release': ['-O4,p'], + 'minsize': ['-Os'], + 'custom': [], +} # type: T.Dict[str, T.List[str]] + +mwccarm_instruction_set_args = { + 'generic': ['-proc', 'generic'], + 'v4': ['-proc', 'v4'], + 'v4t': ['-proc', 'v4t'], + 'v5t': ['-proc', 'v5t'], + 'v5te': ['-proc', 'v5te'], + 'v6': ['-proc', 'v6'], + 'arm7tdmi': ['-proc', 'arm7tdmi'], + 'arm710t': ['-proc', 'arm710t'], + 'arm720t': ['-proc', 'arm720t'], + 'arm740t': ['-proc', 'arm740t'], + 'arm7ej': ['-proc', 'arm7ej'], + 'arm9tdmi': ['-proc', 'arm9tdmi'], + 'arm920t': ['-proc', 'arm920t'], + 'arm922t': ['-proc', 'arm922t'], + 'arm940t': ['-proc', 'arm940t'], + 'arm9ej': ['-proc', 'arm9ej'], + 'arm926ej': ['-proc', 'arm926ej'], + 'arm946e': ['-proc', 'arm946e'], + 'arm966e': ['-proc', 'arm966e'], + 'arm1020e': ['-proc', 'arm1020e'], + 'arm1022e': ['-proc', 'arm1022e'], + 'arm1026ej': ['-proc', 'arm1026ej'], + 'dbmx1': ['-proc', 'dbmx1'], + 'dbmxl': ['-proc', 'dbmxl'], + 'XScale': ['-proc', 'XScale'], + 'pxa255': ['-proc', 'pxa255'], + 'pxa261': ['-proc', 'pxa261'], + 'pxa262': ['-proc', 'pxa262'], + 'pxa263': ['-proc', 'pxa263'] +} # type: T.Dict[str, T.List[str]] + +mwcceppc_instruction_set_args = { + 'generic': ['-proc', 'generic'], + '401': ['-proc', '401'], + '403': ['-proc', '403'], + '505': ['-proc', '505'], + '509': ['-proc', '509'], + '555': ['-proc', '555'], + '601': ['-proc', '601'], + '602': ['-proc', '602'], + '603': ['-proc', '603'], + '603e': ['-proc', '603e'], + '604': ['-proc', '604'], + '604e': ['-proc', '604e'], + '740': ['-proc', '740'], + '750': ['-proc', '750'], + '801': ['-proc', '801'], + '821': ['-proc', '821'], + '823': ['-proc', '823'], + '850': ['-proc', '850'], + '860': ['-proc', '860'], + '7400': ['-proc', '7400'], + '7450': ['-proc', '7450'], + '8240': ['-proc', '8240'], + '8260': ['-proc', '8260'], + 'e500': ['-proc', 'e500'], + 'gekko': ['-proc', 'gekko'], +} # type: T.Dict[str, T.List[str]] + +mwcc_optimization_args = { + 'plain': [], + '0': ['-O0'], + 'g': ['-Op'], + '1': ['-O1'], + '2': ['-O2'], + '3': ['-O3'], + 's': ['-Os'] +} # type: T.Dict[str, T.List[str]] + +mwcc_debug_args = { + False: [], + True: ['-g'] +} # type: T.Dict[bool, T.List[str]] + + +class MetrowerksCompiler(Compiler): + id = 'mwcc' + + # These compilers can actually invoke the linker, but they choke on + # linker-specific flags. So it's best to invoke the linker directly + INVOKES_LINKER = False + + def __init__(self) -> None: + if not self.is_cross: + raise EnvironmentException(f'{id} supports only cross-compilation.') + + self.base_options = { + OptionKey(o) for o in ['b_pch', 'b_ndebug']} + + default_warn_args = [] # type: T.List[str] + self.warn_args = {'0': ['-w', 'off'], + '1': default_warn_args, + '2': default_warn_args + ['-w', 'most'], + '3': default_warn_args + ['-w', 'all'], + 'everything': default_warn_args + ['-w', 'full']} # type: T.Dict[str, T.List[str]] + + def depfile_for_object(self, objfile: str) -> T.Optional[str]: + # Earlier versions of these compilers do not support specifying + # a custom name for a depfile, and can only generate '<input_file>.d' + return os.path.splitext(objfile)[0] + '.' + self.get_depfile_suffix() + + def get_always_args(self) -> T.List[str]: + return ['-gccinc'] + + def get_buildtype_args(self, buildtype: str) -> T.List[str]: + return mwcc_buildtype_args[buildtype] + + def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: + return [] + + def get_compile_only_args(self) -> T.List[str]: + return ['-c'] + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return mwcc_debug_args[is_debug] + + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + # Check comment in depfile_for_object() + return ['-gccdep', '-MD'] + + def get_depfile_suffix(self) -> str: + return 'd' + + def get_include_args(self, path: str, is_system: bool) -> T.List[str]: + if not path: + path = '.' + return ['-I' + path] + + def get_no_optimization_args(self) -> T.List[str]: + return ['-opt', 'off'] + + def get_no_stdinc_args(self) -> T.List[str]: + return ['-nostdinc'] + + def get_no_stdlib_link_args(self) -> T.List[str]: + return ['-nostdlib'] + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + return mwcc_optimization_args[optimization_level] + + def get_output_args(self, target: str) -> T.List[str]: + return ['-o', target] + + def get_pic_args(self) -> T.List[str]: + return ['-pic'] + + def get_preprocess_only_args(self) -> T.List[str]: + return ['-E'] + + def get_preprocess_to_file_args(self) -> T.List[str]: + return ['-P'] + + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: + return ['-prefix', self.get_pch_name(header)] + + def get_pch_name(self, name: str) -> str: + return os.path.basename(name) + '.' + self.get_pch_suffix() + + def get_pch_suffix(self) -> str: + return 'mch' + + def get_warn_args(self, level: str) -> T.List[str]: + return self.warn_args[level] + + def get_werror_args(self) -> T.List[str]: + return ['-w', 'error'] + + @classmethod + def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]: + result = [] + for i in args: + if i.startswith('-D'): + i = '-D' + i[2:] + if i.startswith('-I'): + i = '-I' + i[2:] + if i.startswith('-Wl,-rpath='): + continue + elif i == '--print-search-dirs': + continue + elif i.startswith('-L'): + continue + result.append(i) + return result + + def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: + for idx, i in enumerate(parameter_list): + if i[:2] == '-I': + parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) + + return parameter_list |
