From e7312a1f81c7ad11c7c6d70f718938dba99de83c Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Mon, 30 Nov 2015 19:13:20 -0200 Subject: [PATCH] waf: add toolchain tool for cross-compiling --- Tools/ardupilotwaf/toolchain.py | 37 +++++++++++++++++++++++++++++++++ wscript | 1 + 2 files changed, 38 insertions(+) create mode 100644 Tools/ardupilotwaf/toolchain.py diff --git a/Tools/ardupilotwaf/toolchain.py b/Tools/ardupilotwaf/toolchain.py new file mode 100644 index 0000000000..1501637ce4 --- /dev/null +++ b/Tools/ardupilotwaf/toolchain.py @@ -0,0 +1,37 @@ +""" +WAF Tool to select the correct toolchain based on the target archtecture. + +This tool must be loaded before compiler tools. Use the environment variable +TOOLCHAIN to define the toolchain prefix. + +Example:: + + def configure(cfg): + cfg.env.TOOLCHAIN = 'arm-linux-gnueabihf' + cfg.load('toolchain') + cfg.load('cxx_compiler') +""" + +from waflib import Utils + +suffixes = dict( + CXX='g++', + CC='gcc', + AS='gcc', + AR='ar', + LD='g++', + GDB='gdb', + OBJCOPY='objcopy', +) + +def configure(cfg): + if not cfg.env.TOOLCHAIN: + cfg.env.TOOLCHAIN = 'native' + 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: + cfg.env.append_value(k, prefix + suffixes[k]) diff --git a/wscript b/wscript index 784d9e171b..0450b72fe1 100644 --- a/wscript +++ b/wscript @@ -74,6 +74,7 @@ def configure(cfg): else: cfg.env.prepend_value(k, val) + cfg.load('toolchain') cfg.load('compiler_cxx compiler_c') cfg.load('clang_compilation_database') cfg.load('waf_unit_test')