Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/ardupilotwaf/toolchain.py
Views: 1798
"""1WAF Tool to select the correct toolchain based on the target archtecture.23This tool loads compiler_c and compiler_cxx, so you don't need to load them4(and you must not load them before this tool). Use the environment variable5TOOLCHAIN to define the toolchain.67Example::89def configure(cfg):10cfg.env.TOOLCHAIN = 'arm-linux-gnueabihf'11cfg.load('toolchain')12"""1314from waflib import Errors, Context, Utils15from waflib.Configure import conf16from waflib.Tools import compiler_c, compiler_cxx17from waflib.Tools import clang, clangxx, gcc, gxx18from waflib.Tools import c_config19from waflib import Logs2021import os22import re23import sys2425@conf26def find_gxx(conf):27names = ['g++', 'c++']28if conf.env.TOOLCHAIN != 'native':29names = ['%s-%s' % (conf.env.TOOLCHAIN, n) for n in names]30cxx = conf.find_program(names, var='CXX')31conf.get_cc_version(cxx, gcc=True)32conf.env.CXX_NAME = 'gcc'3334@conf35def find_gcc(conf):36names = ['gcc', 'cc']37if conf.env.TOOLCHAIN != 'native':38names = ['%s-%s' % (conf.env.TOOLCHAIN, n) for n in names]39cc = conf.find_program(names, var='CC')40conf.get_cc_version(cc, gcc=True)41conf.env.CC_NAME = 'gcc'4243def _clang_cross_support(cfg):44if _clang_cross_support.called:45return4647prefix = cfg.env.TOOLCHAIN + '-'4849try:50cfg.find_program(prefix + 'gcc', var='CROSS_GCC')51except Errors.ConfigurationError as e:52cfg.fatal('toolchain: clang: couldn\'t find cross GCC', ex=e)5354environ = dict(os.environ)55if 'TOOLCHAIN_CROSS_AR' in environ:56# avoid OS's environment to mess up toolchain path finding57del environ['TOOLCHAIN_CROSS_AR']58try:59cfg.find_program(60prefix + 'ar',61var='TOOLCHAIN_CROSS_AR',62environ=environ,63)64except Errors.ConfigurationError as e:65cfg.fatal('toolchain: clang: couldn\'t find toolchain path', ex=e)6667toolchain_path = os.path.join(cfg.env.TOOLCHAIN_CROSS_AR[0], '..', '..')68toolchain_path = os.path.abspath(toolchain_path)69cfg.msg('Using toolchain path for clang', toolchain_path)7071sysroot = cfg.cmd_and_log(72[cfg.env.CROSS_GCC[0], '--print-sysroot'],73quiet=Context.BOTH,74).strip()7576cfg.env.CLANG_FLAGS = [77'--target=' + cfg.env.TOOLCHAIN,78'--gcc-toolchain=' + toolchain_path,79'--sysroot=' + sysroot,80'-B' + os.path.join(toolchain_path, 'bin')81]8283_clang_cross_support.called = False8485def _set_clang_crosscompilation_wrapper(tool_module):86original_configure = tool_module.configure87def new_configure(cfg):88if cfg.env.TOOLCHAIN == 'native':89original_configure(cfg)90return9192cfg.env.stash()93try:94_clang_cross_support(cfg)95original_configure(cfg)96except Errors.ConfigurationError as e:97cfg.env.revert()98raise99else:100cfg.env.commit()101tool_module.configure = new_configure102103_set_clang_crosscompilation_wrapper(clang)104_set_clang_crosscompilation_wrapper(clangxx)105106def _filter_supported_c_compilers(*compilers):107for k in compiler_c.c_compiler:108l = compiler_c.c_compiler[k]109compiler_c.c_compiler[k] = [c for c in compilers if c in l]110111def _filter_supported_cxx_compilers(*compilers):112for k in compiler_cxx.cxx_compiler:113l = compiler_cxx.cxx_compiler[k]114compiler_cxx.cxx_compiler[k] = [c for c in compilers if c in l]115116def _set_pkgconfig_crosscompilation_wrapper(cfg):117original_validatecfg = cfg.validate_cfg118119@conf120def new_validate_cfg(kw):121if 'path' not in kw:122if not cfg.env.PKGCONFIG:123cfg.find_program('%s-pkg-config' % cfg.env.TOOLCHAIN, var='PKGCONFIG')124kw['path'] = cfg.env.PKGCONFIG125126original_validatecfg(kw)127128cfg.validate_cfg = new_validate_cfg129130def configure(cfg):131_filter_supported_c_compilers('gcc', 'clang')132_filter_supported_cxx_compilers('g++', 'clang++')133134cfg.msg('Using toolchain', cfg.env.TOOLCHAIN)135if cfg.env.TOOLCHAIN == "custom":136return137138if cfg.env.TOOLCHAIN == 'native':139cfg.load('compiler_cxx compiler_c')140141if not cfg.options.disable_gccdeps:142cfg.load('gccdeps')143144return145146_set_pkgconfig_crosscompilation_wrapper(cfg)147if sys.platform.startswith("cygwin"):148# on cygwin arm-none-eabi-ar doesn't support the @FILE syntax for splitting long lines149cfg.find_program('ar', var='AR', quiet=True)150else:151cfg.find_program('%s-ar' % cfg.env.TOOLCHAIN, var='AR', quiet=True)152cfg.load('compiler_cxx compiler_c')153154if sys.platform.startswith("cygwin"):155cfg.find_program('nm', var='NM')156else:157cfg.find_program('%s-nm' % cfg.env.TOOLCHAIN, var='NM')158159if not cfg.options.disable_gccdeps:160cfg.load('gccdeps')161162if cfg.env.COMPILER_CC == 'clang':163cfg.env.CFLAGS += cfg.env.CLANG_FLAGS164cfg.env.LINKFLAGS_cprogram += cfg.env.CLANG_FLAGS165166if cfg.env.COMPILER_CXX == 'clang++':167cfg.env.CXXFLAGS += cfg.env.CLANG_FLAGS168cfg.env.LINKFLAGS_cxxprogram += cfg.env.CLANG_FLAGS169170171