292 linhas
9.0 KiB
Plaintext
292 linhas
9.0 KiB
Plaintext
# Copyright 2016 The Fuchsia Authors
|
|
#
|
|
# Use of this source code is governed by a MIT-style
|
|
# license that can be found in the LICENSE file or at
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
import("//gnbuild/config.gni")
|
|
|
|
# Defines a toolchain which looks and behaves like gcc.
|
|
#
|
|
# Parameters
|
|
#
|
|
# cc
|
|
# cxx
|
|
# ar
|
|
# ld
|
|
#
|
|
# toolchain_cpu
|
|
# What "current_cpu" should be set to when invoking a build
|
|
# using this toolchain.
|
|
#
|
|
# toolchain_os
|
|
# What "current_os" should be set to when invoking a
|
|
# build using this toolchain.
|
|
#
|
|
# strip
|
|
# Whether to run strip on all shared libraries and executables as
|
|
# they're built.
|
|
#
|
|
# is_clang
|
|
# Whether to use clang instead of gcc.
|
|
#
|
|
# use_gold
|
|
# Whether the toolchain uses gold instead of ld.
|
|
template("gcc_toolchain") {
|
|
toolchain(target_name) {
|
|
assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
|
|
assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
|
|
assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
|
|
assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
|
|
assert(defined(invoker.toolchain_cpu),
|
|
"gcc_toolchain() must specify a \"toolchain_cpu\"")
|
|
assert(defined(invoker.toolchain_os),
|
|
"gcc_toolchain() must specify a \"toolchain_os\"")
|
|
|
|
forward_variables_from(invoker,
|
|
[
|
|
"cc",
|
|
"cxx",
|
|
"ar",
|
|
"ld",
|
|
])
|
|
|
|
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("asm") {
|
|
depfile = "{{output}}.d"
|
|
command = "$cc {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
|
|
description = "ASM {{output}}"
|
|
outputs = [
|
|
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
|
|
]
|
|
}
|
|
|
|
tool("alink") {
|
|
rspfile = "{{output}}.rsp"
|
|
command =
|
|
"rm -f {{output}} && $ar {{arflags}} rcsD {{output}} @\"$rspfile\""
|
|
description = "AR {{output}}"
|
|
rspfile_content = "{{inputs}}"
|
|
outputs = [
|
|
"{{output_dir}}/{{target_output_name}}{{output_extension}}",
|
|
]
|
|
default_output_dir = "{{target_out_dir}}"
|
|
default_output_extension = ".a"
|
|
output_prefix = "lib"
|
|
}
|
|
|
|
tool("solink") {
|
|
outname = "{{target_output_name}}{{output_extension}}"
|
|
outfile = "{{output_dir}}/$outname"
|
|
rspfile = "$outfile.rsp"
|
|
unstripped_outfile = outfile
|
|
if (defined(invoker.strip)) {
|
|
unstripped_outfile = "{{root_out_dir}}/lib.unstripped/{{target_output_name}}{{output_extension}}"
|
|
}
|
|
if (invoker.toolchain_os == "mac") {
|
|
command = "$ld -shared {{ldflags}} -o \"$unstripped_outfile\" -Wl,-filelist,\"$rspfile\" {{libs}} {{solibs}}"
|
|
rspfile_content = "{{inputs_newline}}"
|
|
default_output_extension = ".dylib"
|
|
} else {
|
|
command = "$ld -shared {{ldflags}} -o \"$unstripped_outfile\" -Wl,-soname=\"$outname\" @\"$rspfile\""
|
|
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
|
|
default_output_extension = ".so"
|
|
}
|
|
if (defined(invoker.strip)) {
|
|
command +=
|
|
" && ${invoker.strip} -S -o \"$outfile\" \"$unstripped_outfile\""
|
|
}
|
|
description = "SOLINK $outfile"
|
|
default_output_dir = "{{root_out_dir}}"
|
|
output_prefix = "lib"
|
|
outputs = [
|
|
outfile,
|
|
]
|
|
if (outfile != unstripped_outfile) {
|
|
outputs += [ unstripped_outfile ]
|
|
}
|
|
}
|
|
|
|
tool("solink_module") {
|
|
outname = "{{target_output_name}}{{output_extension}}"
|
|
outfile = "{{output_dir}}/$outname"
|
|
rspfile = "$outfile.rsp"
|
|
if (defined(invoker.strip)) {
|
|
unstripped_outfile = "{{root_out_dir}}/lib.unstripped/{{target_output_name}}{{output_extension}}"
|
|
} else {
|
|
unstripped_outfile = outfile
|
|
}
|
|
if (invoker.toolchain_os == "mac") {
|
|
command = "$ld -shared {{ldflags}} -o \"$unstripped_outfile\" -Wl,-filelist,\"$rspfile\" {{libs}} {{solibs}}"
|
|
rspfile_content = "{{inputs_newline}}"
|
|
default_output_extension = ".dylib"
|
|
} else {
|
|
command = "$ld -shared {{ldflags}} -o \"$unstripped_outfile\" -Wl,-soname=\"$outname\" @\"$rspfile\""
|
|
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
|
|
default_output_extension = ".so"
|
|
}
|
|
if (defined(invoker.strip)) {
|
|
command +=
|
|
" && ${invoker.strip} -S -o \"$outfile\" \"$unstripped_outfile\""
|
|
}
|
|
description = "SOLINK $outfile"
|
|
default_output_dir = "{{root_out_dir}}"
|
|
output_prefix = "lib"
|
|
outputs = [
|
|
outfile,
|
|
]
|
|
if (outfile != unstripped_outfile) {
|
|
outputs += [ unstripped_outfile ]
|
|
}
|
|
}
|
|
|
|
tool("link") {
|
|
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
|
|
rspfile = "$outfile.rsp"
|
|
unstripped_outfile = outfile
|
|
if (defined(invoker.strip)) {
|
|
unstripped_outfile = "{{root_out_dir}}/exe.unstripped/{{target_output_name}}{{output_extension}}"
|
|
}
|
|
if (invoker.toolchain_os == "mac") {
|
|
command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,-filelist,\"$rspfile\" {{solibs}} {{libs}}"
|
|
} else {
|
|
command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group {{libs}}"
|
|
}
|
|
if (defined(invoker.strip)) {
|
|
command +=
|
|
" && ${invoker.strip} -S -o \"$outfile\" \"$unstripped_outfile\""
|
|
}
|
|
description = "LINK $outfile"
|
|
rspfile_content = "{{inputs}}"
|
|
default_output_dir = "{{root_out_dir}}"
|
|
outputs = [
|
|
outfile,
|
|
]
|
|
if (outfile != unstripped_outfile) {
|
|
outputs += [ unstripped_outfile ]
|
|
}
|
|
}
|
|
|
|
tool("stamp") {
|
|
command = "touch {{output}}"
|
|
description = "STAMP {{output}}"
|
|
}
|
|
|
|
tool("copy") {
|
|
command = "cp -af {{source}} {{output}}"
|
|
description = "COPY {{source}} {{output}}"
|
|
}
|
|
|
|
# When invoking this toolchain not as the default one, these args will be
|
|
# passed to the build. They are ignored when this is the default toolchain.
|
|
toolchain_args() {
|
|
current_cpu = invoker.toolchain_cpu
|
|
current_os = invoker.toolchain_os
|
|
|
|
# These values need to be passed through unchanged.
|
|
target_toolchain = target_toolchain
|
|
target_os = target_os
|
|
target_cpu = target_cpu
|
|
|
|
if (defined(invoker.is_clang)) {
|
|
is_clang = invoker.is_clang
|
|
}
|
|
if (defined(invoker.use_gold)) {
|
|
use_gold = invoker.use_gold
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
template("clang_toolchain") {
|
|
assert(defined(invoker.cc), "clang_toolchain() must specify a \"cc\" value")
|
|
assert(defined(invoker.cxx), "clang_toolchain() must specify a \"cxx\" value")
|
|
assert(defined(invoker.ar), "clang_toolchain() must specify a \"ar\" value")
|
|
assert(defined(invoker.ld), "clang_toolchain() must specify a \"ld\" value")
|
|
assert(defined(invoker.toolchain_cpu),
|
|
"clang_toolchain() must specify a \"toolchain_cpu\"")
|
|
assert(defined(invoker.toolchain_os),
|
|
"clang_toolchain() must specify a \"toolchain_os\"")
|
|
|
|
gcc_toolchain(target_name) {
|
|
is_clang = true
|
|
|
|
forward_variables_from(invoker,
|
|
[
|
|
"cc",
|
|
"cxx",
|
|
"ld",
|
|
"ar",
|
|
"strip",
|
|
"toolchain_cpu",
|
|
"toolchain_os",
|
|
"use_gold",
|
|
])
|
|
}
|
|
}
|
|
|
|
gcc_toolchain("target") {
|
|
cc = "${toolprefix}gcc"
|
|
cxx = "${toolprefix}g++"
|
|
ar = "${toolprefix}ar"
|
|
ld = cxx
|
|
strip = "${toolprefix}strip"
|
|
|
|
toolchain_cpu = target_cpu
|
|
toolchain_os = target_os
|
|
is_clang = false
|
|
}
|
|
|
|
clang_toolchain("clang_target") {
|
|
cc = "${toolprefix}clang"
|
|
cxx = "${toolprefix}clang++"
|
|
ld = cxx
|
|
ar = "${toolprefix}ar"
|
|
strip = "${toolprefix}strip"
|
|
|
|
toolchain_cpu = target_cpu
|
|
toolchain_os = target_os
|
|
}
|
|
|
|
gcc_toolchain("gcc_host") {
|
|
cc = "gcc"
|
|
cxx = "g++"
|
|
ar = "ar"
|
|
ld = cxx
|
|
strip = "strip"
|
|
|
|
toolchain_cpu = host_cpu
|
|
toolchain_os = host_os
|
|
is_clang = false
|
|
}
|
|
|
|
clang_toolchain("clang_host") {
|
|
cc = "clang"
|
|
cxx = "clang++"
|
|
ld = cxx
|
|
ar = "ar"
|
|
strip = "strip"
|
|
|
|
toolchain_cpu = host_cpu
|
|
toolchain_os = host_os
|
|
}
|