OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This value will be inherited in the toolchain below. | 5 # This value will be inherited in the toolchain below. |
6 concurrent_links = exec_script("get_concurrent_links.py", [], "value") | 6 concurrent_links = exec_script("get_concurrent_links.py", [], "value") |
7 | 7 |
8 # This template defines a toolchain for something that works like gcc | 8 # This template defines a toolchain for something that works like gcc |
9 # (including clang). | 9 # (including clang). |
10 # | 10 # |
11 # It requires the following variables specifying the executables to run: | 11 # It requires the following variables specifying the executables to run: |
12 # - cc | 12 # - cc |
13 # - cxx | 13 # - cxx |
14 # - ar | 14 # - ar |
15 # - ld | 15 # - ld |
16 # - readelf | |
17 # - nm | |
18 # and the following which is used in the toolchain_args | 16 # and the following which is used in the toolchain_args |
19 # - toolchain_cpu (What "current_cpu" should be set to when invoking a | 17 # - toolchain_cpu (What "current_cpu" should be set to when invoking a |
20 # build using this toolchain.) | 18 # build using this toolchain.) |
21 # - toolchain_os (What "current_os" should be set to when invoking a | 19 # - toolchain_os (What "current_os" should be set to when invoking a |
22 # build using this toolchain.) | 20 # build using this toolchain.) |
23 # | 21 # |
24 # Optional parameters: | 22 # Optional parameters: |
25 # - libs_section_prefix | 23 # - libs_section_prefix |
26 # - libs_section_postfix | 24 # - libs_section_postfix |
27 # The contents of these strings, if specified, will be placed around | 25 # The contents of these strings, if specified, will be placed around |
28 # the libs section of the linker line. It allows one to inject libraries | 26 # the libs section of the linker line. It allows one to inject libraries |
29 # at the beginning and end for all targets in a toolchain. | 27 # at the beginning and end for all targets in a toolchain. |
30 # - solink_libs_section_prefix | 28 # - solink_libs_section_prefix |
31 # - solink_libs_section_postfix | 29 # - solink_libs_section_postfix |
32 # Same as libs_section_{pre,post}fix except used for solink instead of link
. | 30 # Same as libs_section_{pre,post}fix except used for solink instead of link
. |
33 # - post_solink | 31 # - post_solink |
34 # The content of this string, if specified, will be appended to the solink | 32 # The content of this string, if specified, will be appended to the solink |
35 # command. | 33 # command. |
36 # - deps | 34 # - deps |
37 # Just forwarded to the toolchain definition. | 35 # Just forwarded to the toolchain definition. |
38 # - is_clang | 36 # - is_clang |
39 template("gcc_toolchain") { | 37 template("gcc_toolchain") { |
40 toolchain(target_name) { | 38 toolchain(target_name) { |
41 assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") | 39 assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") |
42 assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") | 40 assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") |
43 assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") | 41 assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") |
44 assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") | 42 assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") |
45 assert(defined(invoker.readelf), | |
46 "gcc_toolchain() must specify a \"readelf\" value") | |
47 assert(defined(invoker.nm), "gcc_toolchain() must specify a \"nm\" value") | |
48 assert(defined(invoker.toolchain_cpu), | 43 assert(defined(invoker.toolchain_cpu), |
49 "gcc_toolchain() must specify a \"toolchain_cpu\"") | 44 "gcc_toolchain() must specify a \"toolchain_cpu\"") |
50 assert(defined(invoker.toolchain_os), | 45 assert(defined(invoker.toolchain_os), |
51 "gcc_toolchain() must specify a \"toolchain_os\"") | 46 "gcc_toolchain() must specify a \"toolchain_os\"") |
52 | 47 |
53 # We can't do string interpolation ($ in strings) on things with dots in | 48 # We can't do string interpolation ($ in strings) on things with dots in |
54 # them. To allow us to use $cc below, for example, we create copies of | 49 # them. To allow us to use $cc below, for example, we create copies of |
55 # these values in our scope. | 50 # these values in our scope. |
56 cc = invoker.cc | 51 cc = invoker.cc |
57 cxx = invoker.cxx | 52 cxx = invoker.cxx |
58 ar = invoker.ar | 53 ar = invoker.ar |
59 ld = invoker.ld | 54 ld = invoker.ld |
60 readelf = invoker.readelf | 55 if (defined(invoker.readelf)) { |
61 nm = invoker.nm | 56 readelf = invoker.readelf |
| 57 } else { |
| 58 readelf = "readelf" |
| 59 } |
| 60 if (defined(invoker.nm)) { |
| 61 nm = invoker.nm |
| 62 } else { |
| 63 nm = "nm" |
| 64 } |
62 | 65 |
63 # Bring these into our scope for string interpolation with default values. | 66 # Bring these into our scope for string interpolation with default values. |
64 if (defined(invoker.libs_section_prefix)) { | 67 if (defined(invoker.libs_section_prefix)) { |
65 libs_section_prefix = invoker.libs_section_prefix | 68 libs_section_prefix = invoker.libs_section_prefix |
66 } else { | 69 } else { |
67 libs_section_prefix = "" | 70 libs_section_prefix = "" |
68 } | 71 } |
69 | 72 |
70 if (defined(invoker.libs_section_postfix)) { | 73 if (defined(invoker.libs_section_postfix)) { |
71 libs_section_postfix = invoker.libs_section_postfix | 74 libs_section_postfix = invoker.libs_section_postfix |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 rspfile = sofile + ".rsp" | 141 rspfile = sofile + ".rsp" |
139 | 142 |
140 # These variables are not built into GN but are helpers that implement | 143 # These variables are not built into GN but are helpers that implement |
141 # (1) linking to produce a .so, (2) extracting the symbols from that file | 144 # (1) linking to produce a .so, (2) extracting the symbols from that file |
142 # to a temporary file, (3) if the temporary file has differences from the | 145 # to a temporary file, (3) if the temporary file has differences from the |
143 # existing .TOC file, overwrite it, otherwise, don't change it. | 146 # existing .TOC file, overwrite it, otherwise, don't change it. |
144 tocfile = sofile + ".TOC" | 147 tocfile = sofile + ".TOC" |
145 temporary_tocname = sofile + ".tmp" | 148 temporary_tocname = sofile + ".tmp" |
146 link_command = | 149 link_command = |
147 "$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" | 150 "$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" |
| 151 assert(defined(readelf), "to solink you must have a readelf") |
| 152 assert(defined(nm), "to solink you must have an nm") |
148 toc_command = "{ $readelf -d $sofile | grep SONAME ; $nm -gD -f p $sofile
| cut -f1-2 -d' '; } > $temporary_tocname" | 153 toc_command = "{ $readelf -d $sofile | grep SONAME ; $nm -gD -f p $sofile
| cut -f1-2 -d' '; } > $temporary_tocname" |
149 replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $tempo
rary_tocname $tocfile; fi" | 154 replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $tempo
rary_tocname $tocfile; fi" |
150 | 155 |
151 command = "$link_command && $toc_command && $replace_command" | 156 command = "$link_command && $toc_command && $replace_command" |
152 if (defined(invoker.postsolink)) { | 157 if (defined(invoker.postsolink)) { |
153 command += " && " + invoker.postsolink | 158 command += " && " + invoker.postsolink |
154 } | 159 } |
155 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" | 160 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
156 | 161 |
157 description = "SOLINK $sofile" | 162 description = "SOLINK $sofile" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (defined(invoker.is_clang)) { | 229 if (defined(invoker.is_clang)) { |
225 is_clang = invoker.is_clang | 230 is_clang = invoker.is_clang |
226 } | 231 } |
227 } | 232 } |
228 | 233 |
229 if (defined(invoker.deps)) { | 234 if (defined(invoker.deps)) { |
230 deps = invoker.deps | 235 deps = invoker.deps |
231 } | 236 } |
232 } | 237 } |
233 } | 238 } |
OLD | NEW |