Mojo C++ bindings: better log message for serialization warnings.
[chromium-blink-merge.git] / build / toolchain / gcc_toolchain.gni
blob8f5445b22551f35a51f20437a3d3bbb7b1533be7
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
6 # (including clang).
8 # It requires the following variables specifying the executables to run:
9 #  - cc
10 #  - cxx
11 #  - ar
12 #  - ld
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
17 #                   toolchain.)
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.
28 #  - post_solink
29 #      The content of this string, if specified, will be appended to the solink
30 #      command.
31 #  - deps
32 #      Just forwarded to the toolchain definition.
33 #  - is_clang
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.
48     cc = invoker.cc
49     cxx = invoker.cxx
50     ar = invoker.ar
51     ld = invoker.ld
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
56     } else {
57       libs_section_prefix = ""
58     }
60     if (defined(invoker.libs_section_postfix)) {
61       libs_section_postfix = invoker.libs_section_postfix
62     } else {
63       libs_section_postfix = ""
64     }
66     if (defined(invoker.solink_libs_section_prefix)) {
67       solink_libs_section_prefix = invoker.solink_libs_section_prefix
68     } else {
69       solink_libs_section_prefix = ""
70     }
72     if (defined(invoker.solink_libs_section_postfix)) {
73       solink_libs_section_postfix = invoker.solink_libs_section_postfix
74     } else {
75       solink_libs_section_postfix = ""
76     }
78     # These library switches can apply to all tools below.
79     lib_switch = "-l"
80     lib_dir_switch = "-L"
82     tool("cc") {
83       depfile = "{{output}}.d"
84       command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
85       depsformat = "gcc"
86       description = "CC {{output}}"
87       outputs = [
88         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
89       ]
90     }
92     tool("cxx") {
93       depfile = "{{output}}.d"
94       command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
95       depsformat = "gcc"
96       description = "CXX {{output}}"
97       outputs = [
98         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
99       ]
100     }
102     tool("asm") {
103       # For GCC we can just use the C compiler to compile assembly.
104       depfile = "{{output}}.d"
105       command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
106       depsformat = "gcc"
107       description = "ASM {{output}}"
108       outputs = [
109         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
110       ]
111     }
113     tool("alink") {
114       rspfile = "{{output}}.rsp"
115       command = "rm -f {{output}} && $ar rcs {{output}} @$rspfile"
116       description = "AR {{output}}"
117       rspfile_content = "{{inputs}}"
118       outputs = [
119         "{{target_out_dir}}/{{target_output_name}}{{output_extension}}"
120       ]
121       default_output_extension = ".a"
122       output_prefix = "lib"
123     }
125     tool("solink") {
126       soname = "{{target_output_name}}{{output_extension}}"  # e.g. "libfoo.so".
127       rspfile = soname + ".rsp"
129       # These variables are not built into GN but are helpers that implement
130       # (1) linking to produce a .so, (2) extracting the symbols from that file
131       # to a temporary file, (3) if the temporary file has differences from the
132       # existing .TOC file, overwrite it, otherwise, don't change it.
133       tocname = soname + ".TOC"
134       temporary_tocname = soname + ".tmp"
135       link_command = "$ld -shared {{ldflags}} -o $soname -Wl,-soname=$soname @$rspfile"
136       toc_command = "{ readelf -d $soname | grep SONAME ; nm -gD -f p $soname | cut -f1-2 -d' '; } > $temporary_tocname"
137       replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname; fi"
139       command = "$link_command && $toc_command && $replace_command"
140       if (defined(invoker.postsolink)) {
141         command += " && " + invoker.postsolink
142       }
143       rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix"
145       description = "SOLINK $soname"
147       # Use this for {{output_extension}} expansions unless a target manually
148       # overrides it (in which case {{output_extension}} will be what the target
149       # specifies).
150       default_output_extension = ".so"
152       output_prefix = "lib"
154       # Since the above commands only updates the .TOC file when it changes, ask
155       # Ninja to check if the timestamp actually changed to know if downstream
156       # dependencies should be recompiled.
157       restat = true
159       # Tell GN about the output files. It will link to the soname but use the
160       # tocname for dependency management.
161       outputs = [
162         soname,
163         tocname,
164       ]
165       link_output = soname
166       depend_output = tocname
167     }
169     tool("link") {
170       outfile = "{{target_output_name}}{{output_extension}}"
171       rspfile = "$outfile.rsp"
172       command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
173       description = "LINK $outfile"
174       rspfile_content = "{{inputs}}"
175       outputs = [ outfile ]
176     }
178     tool("stamp") {
179       command = "touch {{output}}"
180       description = "STAMP {{output}}"
181     }
183     tool("copy") {
184       command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
185       description = "COPY {{source}} {{output}}"
186     }
188     # When invoking this toolchain not as the default one, these args will be
189     # passed to the build. They are ignored when this is the default toolchain.
190     toolchain_args() {
191       cpu_arch = invoker.toolchain_cpu_arch
192       os = invoker.toolchain_os
193       if (defined(invoker.is_clang)) {
194         is_clang = invoker.is_clang
195       }
196     }
198     if (defined(invoker.deps)) {
199       deps = invoker.deps
200     }
201   }