diff options
author | alanNz <alangrimmer@gmail.com> | 2020-03-21 09:13:42 +1300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-03-21 00:47:24 +0200 |
commit | 74602928100394f6129e064f8e0bfe6c9e08c9d2 (patch) | |
tree | e3ae62b782a91ade9d68210a52cea35f18211d8e /mesonbuild | |
parent | 24227a95531b21a04bf2514a5b8f61ae29d47043 (diff) | |
download | meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.zip meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.tar.gz meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.tar.bz2 |
-Add xc16 and c2000 C,Cpp toolchain support
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/build.py | 5 | ||||
-rw-r--r-- | mesonbuild/compilers/__init__.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/c.py | 91 | ||||
-rw-r--r-- | mesonbuild/compilers/cpp.py | 33 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/c2000.py | 120 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/xc16.py | 123 | ||||
-rw-r--r-- | mesonbuild/envconfig.py | 3 | ||||
-rw-r--r-- | mesonbuild/environment.py | 36 | ||||
-rw-r--r-- | mesonbuild/linkers.py | 111 |
9 files changed, 527 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 60bcf81..616a183 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1489,6 +1489,11 @@ class Executable(BuildTarget): elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('ccrx') or 'cpp' in self.compilers and self.compilers['cpp'].get_id().startswith('ccrx')): self.suffix = 'abs' + elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('xc16')): + self.suffix = 'elf' + elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('c2000') or + 'cpp' in self.compilers and self.compilers['cpp'].get_id().startswith('c2000')): + self.suffix = 'out' else: self.suffix = environment.machines[for_machine].get_exe_suffix() self.filename = self.name diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index a4e3943..05c75dd 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -91,6 +91,9 @@ __all__ = [ 'RustCompiler', 'CcrxCCompiler', 'CcrxCPPCompiler', + 'Xc16CCompiler', + 'C2000CCompiler', + 'C2000CPPCompiler', 'SunFortranCompiler', 'SwiftCompiler', 'ValaCompiler', @@ -135,6 +138,8 @@ from .c import ( IntelClCCompiler, PGICCompiler, CcrxCCompiler, + Xc16CCompiler, + C2000CCompiler, VisualStudioCCompiler, ) from .cpp import ( @@ -151,6 +156,7 @@ from .cpp import ( IntelClCPPCompiler, PGICPPCompiler, CcrxCPPCompiler, + C2000CPPCompiler, VisualStudioCPPCompiler, ) from .cs import MonoCompiler, VisualStudioCsCompiler diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index f98316b..82640be 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -20,6 +20,8 @@ from ..mesonlib import MachineChoice, MesonException, mlog, version_compare from .c_function_attributes import C_FUNC_ATTRIBUTES from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler +from .mixins.xc16 import Xc16Compiler +from .mixins.c2000 import C2000Compiler from .mixins.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -424,3 +426,92 @@ class CcrxCCompiler(CcrxCompiler, CCompiler): if path == '': path = '.' return ['-include=' + path] + + +class Xc16CCompiler(Xc16Compiler, CCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + Xc16Compiler.__init__(self) + + def get_options(self): + opts = CCompiler.get_options(self) + opts.update({'c_std': coredata.UserComboOption('C language standard to use', + ['none', 'c89', 'c99', 'gnu89', 'gnu99'], + 'none')}) + return opts + + def get_no_stdinc_args(self): + return [] + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value != 'none': + args.append('-ansi') + args.append('-std=' + std.value) + return args + + def get_compile_only_args(self): + return [] + + def get_no_optimization_args(self): + return ['-O0'] + + def get_output_args(self, target): + return ['-o%s' % target] + + def get_werror_args(self): + return ['-change_message=error'] + + def get_include_args(self, path, is_system): + if path == '': + path = '.' + return ['-I' + path] + + +class C2000CCompiler(C2000Compiler, CCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + C2000Compiler.__init__(self) + + # Override CCompiler.get_always_args + def get_always_args(self): + return [] + + def get_options(self): + opts = CCompiler.get_options(self) + opts.update({'c_std': coredata.UserComboOption('C language standard to use', + ['none', 'c89', 'c99', 'c11'], + 'none')}) + return opts + + def get_no_stdinc_args(self): + return [] + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value != 'none': + args.append('--' + std.value) + return args + + def get_compile_only_args(self): + return [] + + def get_no_optimization_args(self): + return ['-Ooff'] + + def get_output_args(self, target): + return ['--output_file=%s' % target] + + def get_werror_args(self): + return ['-change_message=error'] + + def get_include_args(self, path, is_system): + if path == '': + path = '.' + return ['--include_path=' + path] diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 2470bd5..ac0500a 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -29,6 +29,7 @@ from .compilers import ( from .c_function_attributes import CXX_FUNC_ATTRIBUTES, C_FUNC_ATTRIBUTES from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler +from .mixins.c2000 import C2000Compiler from .mixins.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -633,3 +634,35 @@ class CcrxCPPCompiler(CcrxCompiler, CPPCompiler): def get_compiler_check_args(self): return [] + +class C2000CPPCompiler(C2000Compiler, CPPCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) + C2000Compiler.__init__(self) + + def get_options(self): + opts = CPPCompiler.get_options(self) + opts.update({'cpp_std': coredata.UserComboOption('C++ language standard to use', + ['none', 'c++03'], + 'none')}) + return opts + + def get_always_args(self): + return ['-nologo', '-lang=cpp'] + + def get_option_compile_args(self, options): + return [] + + def get_compile_only_args(self): + return [] + + def get_output_args(self, target): + return ['-output=obj=%s' % target] + + def get_option_link_args(self, options): + return [] + + def get_compiler_check_args(self): + return [] diff --git a/mesonbuild/compilers/mixins/c2000.py b/mesonbuild/compilers/mixins/c2000.py new file mode 100644 index 0000000..65a2cea --- /dev/null +++ b/mesonbuild/compilers/mixins/c2000.py @@ -0,0 +1,120 @@ +# 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. + +"""Representations specific to the Texas Instruments C2000 compiler family.""" + +import os +import typing as T + +from ...mesonlib import EnvironmentException + +if T.TYPE_CHECKING: + from ...environment import Environment + +c2000_buildtype_args = { + 'plain': [], + 'debug': [], + 'debugoptimized': [], + 'release': [], + 'minsize': [], + 'custom': [], +} # type: T.Dict[str, T.List[str]] + +c2000_optimization_args = { + '0': ['-O0'], + 'g': ['-Ooff'], + '1': ['-O1'], + '2': ['-O2'], + '3': ['-O3'], + 's': ['-04'] +} # type: T.Dict[str, T.List[str]] + +c2000_debug_args = { + False: [], + True: [] +} # type: T.Dict[bool, T.List[str]] + + +class C2000Compiler: + def __init__(self): + if not self.is_cross: + raise EnvironmentException('c2000 supports only cross-compilation.') + self.id = 'c2000' + # Assembly + self.can_compile_suffixes.add('asm') + default_warn_args = [] # type: T.List[str] + self.warn_args = {'0': [], + '1': default_warn_args, + '2': default_warn_args + [], + '3': default_warn_args + []} + + def get_pic_args(self) -> T.List[str]: + # PIC support is not enabled by default for c2000, + # if users want to use it, they need to add the required arguments explicitly + return [] + + def get_buildtype_args(self, buildtype: str) -> T.List[str]: + return c2000_buildtype_args[buildtype] + + def get_pch_suffix(self) -> str: + return 'pch' + + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: + return [] + + # Override CCompiler.get_dependency_gen_args + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + return [] + + def thread_flags(self, env: 'Environment') -> T.List[str]: + return [] + + def get_coverage_args(self) -> T.List[str]: + return [] + + def get_no_stdinc_args(self) -> T.List[str]: + return [] + + def get_no_stdlib_link_args(self) -> T.List[str]: + return [] + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + return c2000_optimization_args[optimization_level] + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return c2000_debug_args[is_debug] + + @classmethod + def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: + result = [] + for i in args: + if i.startswith('-D'): + i = '-define=' + i[2:] + if i.startswith('-I'): + i = '-include=' + 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[:9] == '-include=': + parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) + + return parameter_list diff --git a/mesonbuild/compilers/mixins/xc16.py b/mesonbuild/compilers/mixins/xc16.py new file mode 100644 index 0000000..f12cccc --- /dev/null +++ b/mesonbuild/compilers/mixins/xc16.py @@ -0,0 +1,123 @@ +# 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. + +"""Representations specific to the Microchip XC16 C compiler family.""" + +import os +import typing as T + +from ...mesonlib import EnvironmentException + +if T.TYPE_CHECKING: + from ...environment import Environment + +xc16_buildtype_args = { + 'plain': [], + 'debug': [], + 'debugoptimized': [], + 'release': [], + 'minsize': [], + 'custom': [], +} # type: T.Dict[str, T.List[str]] + +xc16_optimization_args = { + '0': ['-O0'], + 'g': ['-O0'], + '1': ['-O1'], + '2': ['-O2'], + '3': ['-O3'], + 's': ['-Os'] +} # type: T.Dict[str, T.List[str]] + +xc16_debug_args = { + False: [], + True: [] +} # type: T.Dict[bool, T.List[str]] + + +class Xc16Compiler: + def __init__(self): + if not self.is_cross: + raise EnvironmentException('xc16 supports only cross-compilation.') + self.id = 'xc16' + # Assembly + self.can_compile_suffixes.add('s') + default_warn_args = [] # type: T.List[str] + self.warn_args = {'0': [], + '1': default_warn_args, + '2': default_warn_args + [], + '3': default_warn_args + []} + + def get_always_args(self) -> T.List[str]: + return [] + + def get_pic_args(self) -> T.List[str]: + # PIC support is not enabled by default for xc16, + # if users want to use it, they need to add the required arguments explicitly + return [] + + def get_buildtype_args(self, buildtype: str) -> T.List[str]: + return xc16_buildtype_args[buildtype] + + def get_pch_suffix(self) -> str: + return 'pch' + + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: + return [] + + # Override CCompiler.get_dependency_gen_args + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + return [] + + def thread_flags(self, env: 'Environment') -> T.List[str]: + return [] + + def get_coverage_args(self) -> T.List[str]: + return [] + + 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 xc16_optimization_args[optimization_level] + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return xc16_debug_args[is_debug] + + @classmethod + def unix_args_to_native(cls, args: T.List[str]) -> 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[:9] == '-I': + parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) + + return parameter_list diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 8587842..0ae1e6d 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -40,6 +40,7 @@ known_cpu_families = ( 'alpha', 'arc', 'arm', + 'c2000', 'e2k', 'ia64', 'm68k', @@ -57,6 +58,8 @@ known_cpu_families = ( 's390x', 'sparc', 'sparc64', + 'pic24', + 'dspic', 'wasm32', 'wasm64', 'x86', diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 31510ff..323180b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -18,7 +18,7 @@ import shlex import typing as T from . import coredata -from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker, IntelVisualStudioLinker +from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker, Xc16Linker, C2000Linker, IntelVisualStudioLinker from . import mesonlib from .mesonlib import ( MesonException, EnvironmentException, MachineChoice, Popen_safe, @@ -45,6 +45,8 @@ from .linkers import ( ArmClangDynamicLinker, ArmDynamicLinker, CcrxDynamicLinker, + Xc16DynamicLinker, + C2000DynamicLinker, ClangClDynamicLinker, DynamicLinker, GnuBFDDynamicLinker, @@ -105,6 +107,9 @@ from .compilers import ( RustCompiler, CcrxCCompiler, CcrxCPPCompiler, + Xc16CCompiler, + C2000CCompiler, + C2000CPPCompiler, SunFortranCompiler, ValaCompiler, VisualStudioCCompiler, @@ -922,6 +927,10 @@ class Environment: arg = '--vsn' elif 'ccrx' in compiler_name: arg = '-v' + elif 'xc16' in compiler_name: + arg = '--version' + elif 'cl2000' in compiler_name: + arg = '-version' elif compiler_name in {'icl', 'icl.exe'}: # if you pass anything to icl you get stuck in a pager arg = '' @@ -945,6 +954,9 @@ class Environment: guess_gcc_or_lcc = 'gcc' if 'e2k' in out and 'lcc' in out: guess_gcc_or_lcc = 'lcc' + if 'Microchip Technology' in out: + # this output has "Free Software Foundation" in its version + guess_gcc_or_lcc = False if guess_gcc_or_lcc: defines = self.get_gnu_compiler_defines(compiler) @@ -1107,6 +1119,22 @@ class Environment: ccache + compiler, version, for_machine, is_cross, info, exe_wrap, full_version=full_version, linker=linker) + if 'Microchip Technology' in out: + cls = Xc16CCompiler if lang == 'c' else Xc16CCompiler + self.coredata.add_lang_args(cls.language, cls, for_machine, self) + linker = Xc16DynamicLinker(for_machine, version=version) + return cls( + ccache + compiler, version, for_machine, is_cross, info, + exe_wrap, full_version=full_version, linker=linker) + + if 'TMS320C2000 C/C++' in out: + cls = C2000CCompiler if lang == 'c' else C2000CPPCompiler + self.coredata.add_lang_args(cls.language, cls, for_machine, self) + linker = C2000DynamicLinker(for_machine, version=version) + return cls( + ccache + compiler, version, for_machine, is_cross, info, + exe_wrap, full_version=full_version, linker=linker) + self._handle_exceptions(popen_exceptions, compilers) def detect_c_compiler(self, for_machine): @@ -1663,6 +1691,8 @@ class Environment: for linker in linkers: if not {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'}.isdisjoint(linker): arg = '/?' + elif not {'ar2000', 'ar2000.exe'}.isdisjoint(linker): + arg = '?' else: arg = '--version' try: @@ -1686,6 +1716,10 @@ class Environment: return DLinker(linker, compiler.arch) if err.startswith('Renesas') and ('rlink' in linker or 'rlink.exe' in linker): return CcrxLinker(linker) + if out.startswith('GNU ar') and ('xc16-ar' in linker or 'xc16-ar.exe' in linker): + return Xc16Linker(linker) + if out.startswith('TMS320C2000') and ('ar2000' in linker or 'ar2000.exe' in linker): + return C2000Linker(linker) if p.returncode == 0: return ArLinker(linker) if p.returncode == 1 and err.startswith('usage'): # OSX diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index e4fffe3..dc5b144 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -206,6 +206,38 @@ class CcrxLinker(StaticLinker): return ['-nologo', '-form=library'] +class Xc16Linker(StaticLinker): + + def __init__(self, exelist: T.List[str]): + super().__init__(exelist) + self.id = 'xc16-ar' + + def can_linker_accept_rsp(self) -> bool: + return False + + def get_output_args(self, target: str) -> T.List[str]: + return ['%s' % target] + + def get_linker_always_args(self) -> T.List[str]: + return ['rcs'] + + +class C2000Linker(StaticLinker): + + def __init__(self, exelist: T.List[str]): + super().__init__(exelist) + self.id = 'ar2000' + + def can_linker_accept_rsp(self) -> bool: + return False + + def get_output_args(self, target: str) -> T.List[str]: + return ['%s' % target] + + def get_linker_always_args(self) -> T.List[str]: + return ['-r'] + + def prepare_rpaths(raw_rpaths: str, build_dir: str, from_dir: str) -> T.List[str]: # The rpaths we write must be relative if they point to the build dir, # because otherwise they have different length depending on the build @@ -755,6 +787,85 @@ class CcrxDynamicLinker(DynamicLinker): return [] +class Xc16DynamicLinker(DynamicLinker): + + """Linker for Microchip XC16 compiler.""" + + def __init__(self, for_machine: mesonlib.MachineChoice, + *, version: str = 'unknown version'): + super().__init__('xc16-gcc', ['xc16-gcc.exe'], for_machine, '', [], + version=version) + + def get_link_whole_for(self, args: T.List[str]) -> T.List[str]: + if not args: + return args + return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group') + + def get_accepts_rsp(self) -> bool: + return False + + def get_lib_prefix(self) -> str: + return '' + + def get_std_shared_lib_args(self) -> T.List[str]: + return [] + + def get_output_args(self, outputname: str) -> T.List[str]: + return ['-o%s' % outputname] + + def get_search_args(self, dirname: str) -> 'T.NoReturn': + raise EnvironmentError('xc16-gcc.exe does not have a search dir argument') + + def get_allow_undefined_args(self) -> T.List[str]: + return [] + + def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str, + suffix: str, soversion: str, darwin_versions: T.Tuple[str, str], + is_shared_module: bool) -> T.List[str]: + return [] + + def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str, + rpath_paths: str, build_rpath: str, + install_rpath: str) -> T.List[str]: + return [] + + +class C2000DynamicLinker(DynamicLinker): + + """Linker for Texas Instruments C2000 compiler.""" + + def __init__(self, for_machine: mesonlib.MachineChoice, + *, version: str = 'unknown version'): + super().__init__('cl2000', ['cl2000.exe'], for_machine, '', [], + version=version) + + def get_link_whole_for(self, args: T.List[str]) -> T.List[str]: + if not args: + return args + return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group') + + def get_accepts_rsp(self) -> bool: + return False + + def get_lib_prefix(self) -> str: + return '-l=' + + def get_std_shared_lib_args(self) -> T.List[str]: + return [] + + def get_output_args(self, outputname: str) -> T.List[str]: + return ['-z', '--output_file=%s' % outputname] + + def get_search_args(self, dirname: str) -> 'T.NoReturn': + raise EnvironmentError('cl2000.exe does not have a search dir argument') + + def get_allow_undefined_args(self) -> T.List[str]: + return [] + + def get_always_args(self) -> T.List[str]: + return [] + + class ArmDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker): """Linker for the ARM compiler.""" |