mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-23 00:04:02 -04:00
waf: toolchain: support Clang in toolchain for cross-compilation
Define function to help find the toolchain path
This commit is contained in:
parent
a8aae048c2
commit
02af9b6ab1
@ -12,11 +12,11 @@ Example::
|
|||||||
cfg.load('cxx_compiler')
|
cfg.load('cxx_compiler')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from waflib import Utils
|
from waflib import Utils, Context
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
suffixes = dict(
|
suffixes = dict(
|
||||||
CXX='g++',
|
|
||||||
CC='gcc',
|
|
||||||
AS='gcc',
|
AS='gcc',
|
||||||
AR='ar',
|
AR='ar',
|
||||||
LD='g++',
|
LD='g++',
|
||||||
@ -24,14 +24,70 @@ suffixes = dict(
|
|||||||
OBJCOPY='objcopy',
|
OBJCOPY='objcopy',
|
||||||
)
|
)
|
||||||
|
|
||||||
def configure(cfg):
|
def find_realexec_path(cfg, filename, path_list=[]):
|
||||||
if not cfg.env.TOOLCHAIN:
|
if not filename:
|
||||||
cfg.env.TOOLCHAIN = 'native'
|
return ''
|
||||||
prefix = ''
|
|
||||||
else:
|
|
||||||
cfg.env.TOOLCHAIN = Utils.to_list(cfg.env.TOOLCHAIN)[0]
|
|
||||||
cfg.msg('Using toolchain prefix', cfg.env.TOOLCHAIN)
|
|
||||||
prefix = cfg.env.TOOLCHAIN + '-'
|
|
||||||
|
|
||||||
for k in suffixes:
|
if not path_list:
|
||||||
cfg.env.append_value(k, prefix + suffixes[k])
|
path_list = cfg.environ.get('PATH','').split(os.pathsep)
|
||||||
|
|
||||||
|
for dir in path_list:
|
||||||
|
path = os.path.abspath(os.path.expanduser(os.path.join(dir, filename)))
|
||||||
|
|
||||||
|
if os.path.isfile(path):
|
||||||
|
if os.path.islink(path):
|
||||||
|
realpath = os.path.realpath(path)
|
||||||
|
|
||||||
|
if filename not in os.path.basename(realpath):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return os.path.dirname(realpath)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return os.path.dirname(path)
|
||||||
|
|
||||||
|
cfg.fatal('Could not find real exec path to %s in path_list %s:' % (filename, path_list))
|
||||||
|
|
||||||
|
def configure(cfg):
|
||||||
|
toolchain = cfg.env.TOOLCHAIN
|
||||||
|
|
||||||
|
if toolchain != 'native':
|
||||||
|
cfg.msg('Using toolchain prefix', toolchain)
|
||||||
|
prefix = toolchain + '-'
|
||||||
|
|
||||||
|
c_compiler = cfg.options.check_c_compiler or 'gcc'
|
||||||
|
cxx_compiler = cfg.options.check_cxx_compiler or 'g++'
|
||||||
|
|
||||||
|
if 'gcc' == c_compiler or 'g++' == cxx_compiler or 'clang' == c_compiler or 'clang++' == cxx_compiler:
|
||||||
|
toolchain_path = os.path.abspath(os.path.join(find_realexec_path(cfg, prefix + suffixes['AR']), '..'))
|
||||||
|
cfg.msg('Using toolchain path', toolchain_path)
|
||||||
|
|
||||||
|
if 'gcc' == c_compiler or 'g++' == cxx_compiler:
|
||||||
|
for k in suffixes:
|
||||||
|
cfg.env[k] = [prefix + suffixes[k]]
|
||||||
|
|
||||||
|
if 'clang' == c_compiler or 'clang++' == cxx_compiler:
|
||||||
|
sysroot = cfg.cmd_and_log([prefix + 'gcc', '--print-sysroot'], quiet=Context.BOTH)[:-1]
|
||||||
|
clang_flags = [
|
||||||
|
'--target=' + toolchain,
|
||||||
|
'--gcc-toolchain=' + toolchain_path,
|
||||||
|
'--sysroot=' + sysroot,
|
||||||
|
'-B' + os.path.join(toolchain_path, 'bin')
|
||||||
|
]
|
||||||
|
cfg.env.LINKFLAGS += clang_flags
|
||||||
|
|
||||||
|
if 'gcc' == c_compiler:
|
||||||
|
cfg.env['CC'] = [prefix + 'gcc']
|
||||||
|
|
||||||
|
elif 'clang' == c_compiler:
|
||||||
|
cfg.env['CC'] = [c_compiler]
|
||||||
|
cfg.env['AR'] = [prefix + suffixes['AR']]
|
||||||
|
cfg.env.CFLAGS += clang_flags
|
||||||
|
|
||||||
|
if 'g++' == cxx_compiler:
|
||||||
|
cfg.env['CXX'] = [prefix + 'g++']
|
||||||
|
|
||||||
|
elif 'clang++' == cxx_compiler:
|
||||||
|
cfg.env['CXX'] = [cxx_compiler]
|
||||||
|
cfg.env['AR'] = [prefix + suffixes['AR']]
|
||||||
|
cfg.env.CXXFLAGS += clang_flags
|
Loading…
Reference in New Issue
Block a user