1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # This template defines a toolchain for something that works like gcc
8 # It requires the following variables specifying the executables to run:
13 # and the following which is used in the toolchain_args
14 # - toolchain_cpu_arch (What "cpu_arch" should be set to when invoking a
15 # build using this toolchain.)
16 # - toolchain_os (What "os" should be set to when invoking a build using this
19 # Optional parameters:
20 # - libs_section_prefix
21 # - libs_section_postfix
22 # The contents of these strings, if specified, will be placed around
23 # the libs section of the linker line. It allows one to inject libraries
24 # at the beginning and end for all targets in a toolchain.
25 # - solink_libs_section_prefix
26 # - solink_libs_section_postfix
27 # Same as libs_section_{pre,post}fix except used for solink instead of link.
29 # The content of this string, if specified, will be appended to the solink
32 # Just forwarded to the toolchain definition.
34 template("gcc_toolchain") {
35 toolchain(target_name) {
36 assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
37 assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
38 assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
39 assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
40 assert(defined(invoker.toolchain_cpu_arch),
41 "gcc_toolchain() must specify a \"toolchain_cpu_arch\"")
42 assert(defined(invoker.toolchain_os),
43 "gcc_toolchain() must specify a \"toolchain_os\"")
45 # We can't do string interpolation ($ in strings) on things with dots in
46 # them. To allow us to use $cc below, for example, we create copies of
47 # these values in our scope.
53 # Bring these into our scope for string interpolation with default values.
54 if (defined(invoker.libs_section_prefix)) {
55 libs_section_prefix = invoker.libs_section_prefix
57 libs_section_prefix = ""
60 if (defined(invoker.libs_section_postfix)) {
61 libs_section_postfix = invoker.libs_section_postfix
63 libs_section_postfix = ""
66 if (defined(invoker.solink_libs_section_prefix)) {
67 solink_libs_section_prefix = invoker.solink_libs_section_prefix
69 solink_libs_section_prefix = ""
72 if (defined(invoker.solink_libs_section_postfix)) {
73 solink_libs_section_postfix = invoker.solink_libs_section_postfix
75 solink_libs_section_postfix = ""
78 # Make these apply to all tools below.
84 command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out"
85 description = "CC \$out"
91 command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out"
92 description = "CXX \$out"
97 command = "rm -f \$out && $ar rcs \$out @\$rspfile"
98 description = "AR \$out"
100 rspfile_content = "\$in"
103 rspfile = "\$out.rsp"
104 rspfile_content = "-Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive $solink_libs_section_prefix \$libs $solink_libs_section_postfix"
106 # TODO(cjhopman): There needs to be a way for gn to correctly figure out
107 # the outputs of a solink command.
109 link_command = "$ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname @\$rspfile"
110 toc_command = "{ readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp"
111 replace_command = "if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC; fi"
112 command = "$link_command && $toc_command && $replace_command"
114 if (defined(invoker.postsolink)) {
115 command += " && " + invoker.postsolink
118 description = "SOLINK \$lib"
123 command = "$ld \$ldflags -o \$out -Wl,--start-group @\$rspfile \$solibs -Wl,--end-group $libs_section_prefix \$libs $libs_section_postfix"
124 description = "LINK \$out"
125 rspfile = "\$out.rsp"
126 rspfile_content = "\$in"
130 command = "\${postbuilds}touch \$out"
131 description = "STAMP \$out"
134 command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)"
135 description = "COPY \$in \$out"
138 # When invoking this toolchain not as the default one, these args will be
139 # passed to the build. They are ignored when this is the default toolchain.
141 cpu_arch = invoker.toolchain_cpu_arch
142 os = invoker.toolchain_os
143 if (defined(invoker.is_clang)) {
144 is_clang = invoker.is_clang
148 if (defined(invoker.deps)) {