| # Host toolchain specific build arguments. |
| declare_args() { |
| # Build with a specific compiler version e.g. when building with clang, set |
| # to "3.9" to build with `clang-3.9`. |
| host_cc_version = "" |
| } |
| |
| # Template for host toolchains. |
| template("cc_toolchain") { |
| toolchain(target_name) { |
| assert(defined(invoker.ar), "cc_toolchain() must specify a \"ar\" value") |
| assert(defined(invoker.cc), "cc_toolchain() must specify a \"cc\" value") |
| assert(defined(invoker.cxx), "cc_toolchain() must specify a \"cxx\" value") |
| |
| cc = "${invoker.cc}" |
| cxx = "${invoker.cxx}" |
| if (host_cc_version != "") { |
| cc += "-${host_cc_version}" |
| cxx += "-${host_cc_version}" |
| } |
| if (defined(invoker.cflags)) { |
| cc += " ${invoker.cflags}" |
| cxx += " ${invoker.cflags}" |
| } |
| |
| tool("cc") { |
| depfile = "{{output}}.d" |
| command = "${cc} -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| depsformat = "gcc" |
| description = "CC {{output}}" |
| outputs = [ |
| "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| ] |
| } |
| |
| tool("cxx") { |
| depfile = "{{output}}.d" |
| command = "${cxx} -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
| depsformat = "gcc" |
| description = "CXX {{output}}" |
| outputs = [ |
| "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| ] |
| } |
| |
| tool("alink") { |
| rspfile = "{{output}}.rsp" |
| command = "rm -f {{output}} && ${invoker.ar} rcs {{output}} @$rspfile" |
| description = "AR {{target_output_name}}{{output_extension}}" |
| rspfile_content = "{{inputs}}" |
| outputs = [ |
| "{{target_out_dir}}/{{target_output_name}}{{output_extension}}", |
| ] |
| default_output_extension = ".a" |
| output_prefix = "lib" |
| } |
| |
| tool("solink") { |
| soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
| sofile = "{{output_dir}}/$soname" |
| rspfile = soname + ".rsp" |
| |
| command = |
| "${cxx} -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" |
| rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}" |
| |
| description = "SOLINK $soname" |
| |
| # Use this for {{output_extension}} expansions unless a target manually |
| # overrides it (in which case {{output_extension}} will be what the target |
| # specifies). |
| default_output_extension = ".so" |
| |
| # Use this for {{output_dir}} expansions unless a target manually overrides |
| # it (in which case {{output_dir}} will be what the target specifies). |
| default_output_dir = "{{root_out_dir}}" |
| |
| outputs = [ |
| sofile, |
| ] |
| link_output = sofile |
| depend_output = sofile |
| output_prefix = "lib" |
| } |
| |
| tool("link") { |
| outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
| rspfile = "$outfile.rsp" |
| command = "${cxx} {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group {{libs}}" |
| description = "LINK $outfile" |
| default_output_dir = "{{root_out_dir}}" |
| rspfile_content = "{{inputs}}" |
| outputs = [ |
| outfile, |
| ] |
| } |
| |
| tool("stamp") { |
| command = "touch {{output}}" |
| description = "STAMP {{output}}" |
| } |
| |
| tool("copy") { |
| command = "cp -af {{source}} {{output}}" |
| description = "COPY {{source}} {{output}}" |
| } |
| |
| if (defined(invoker.toolchain_args)) { |
| toolchain_args = { |
| forward_variables_from(invoker.toolchain_args, "*") |
| } |
| } |
| } |
| } |
| |
| # Specialize for clang or gcc |
| cc_toolchain("clang") { |
| ar = "llvm-ar" |
| cc = "clang" |
| cxx = "clang++" |
| cflags = "-fcolor-diagnostics" |
| } |
| |
| cc_toolchain("clang_mock_arch") { |
| ar = "llvm-ar" |
| cc = "clang" |
| cxx = "clang++" |
| cflags = "-fcolor-diagnostics" |
| |
| toolchain_args = { |
| # When building for the host, use the mock architecture to make things |
| # testable. |
| arch = "mock" |
| } |
| } |
| |
| cc_toolchain("gcc") { |
| ar = "ar" |
| cc = "gcc" |
| cxx = "g++" |
| cflags = "-fdiagnostics-color=always" |
| } |
| |
| cc_toolchain("gcc_mock_arch") { |
| ar = "ar" |
| cc = "gcc" |
| cxx = "g++" |
| cflags = "-fdiagnostics-color=always" |
| |
| toolchain_args = { |
| # When building for the host, use the mock architecture to make things |
| # testable. |
| arch = "mock" |
| } |
| } |