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 import("//build/config/clang/clang.gni") | 5 import("//build/config/clang/clang.gni") |
6 import("//build/config/nacl/config.gni") | 6 import("//build/config/nacl/config.gni") |
7 import("//build/config/sanitizers/sanitizers.gni") | 7 import("//build/config/sanitizers/sanitizers.gni") |
8 import("//build/config/v8_target_cpu.gni") | 8 import("//build/config/v8_target_cpu.gni") |
9 import("//build/toolchain/cc_wrapper.gni") | 9 import("//build/toolchain/cc_wrapper.gni") |
10 import("//build/toolchain/goma.gni") | 10 import("//build/toolchain/goma.gni") |
11 import("//build/toolchain/toolchain.gni") | 11 import("//build/toolchain/toolchain.gni") |
12 import("//build/toolchain/concurrent_links.gni") | 12 import("//build/toolchain/concurrent_links.gni") |
13 | 13 |
14 # This template defines a toolchain for something that works like gcc | 14 # This template defines a toolchain for something that works like gcc |
15 # (including clang). | 15 # (including clang). |
16 # | 16 # |
17 # It requires the following variables specifying the executables to run: | 17 # It requires the following variables specifying the executables to run: |
18 # - ar | 18 # - ar |
19 # - cc | 19 # - cc |
20 # - cxx | 20 # - cxx |
21 # - ld | 21 # - ld |
22 # and the following which is used in the toolchain_args | 22 # and the following which is used in the toolchain_args |
23 # - toolchain_cpu (What "current_cpu" should be set to when invoking a | 23 # - toolchain_cpu (What "current_cpu" should be set to when invoking a |
24 # build using this toolchain.) | 24 # build using this toolchain.) |
25 # - toolchain_os (What "current_os" should be set to when invoking a | 25 # - toolchain_os (What "current_os" should be set to when invoking a |
26 # build using this toolchain.) | 26 # build using this toolchain.) |
27 # | 27 # |
28 # Optional parameters that control the tools: | 28 # Optional parameters that control the tools: |
29 # | 29 # |
30 # - extra_cflags | |
31 # Extra flags to be appended when compiling C files (but not C++ files). | |
32 # - extra_cppflags | |
33 # Extra flags to be appended when compiling both C and C++ files. "CPP" | |
34 # stands for "C PreProcessor" in this context, although it can be | |
35 # used for non-preprocessor flags as well. Not to be confused with | |
36 # "CXX" (which follows). | |
37 # - extra_cxxflags | |
38 # Extra flags to be appended when compiling C++ files (but not C files). | |
39 # - extra_ldflags | |
40 # Extra flags to be appended when linking | |
41 # | |
42 # - libs_section_prefix | 30 # - libs_section_prefix |
43 # - libs_section_postfix | 31 # - libs_section_postfix |
44 # The contents of these strings, if specified, will be placed around | 32 # The contents of these strings, if specified, will be placed around |
45 # the libs section of the linker line. It allows one to inject libraries | 33 # the libs section of the linker line. It allows one to inject libraries |
46 # at the beginning and end for all targets in a toolchain. | 34 # at the beginning and end for all targets in a toolchain. |
47 # - solink_libs_section_prefix | 35 # - solink_libs_section_prefix |
48 # - solink_libs_section_postfix | 36 # - solink_libs_section_postfix |
49 # Same as libs_section_{pre,post}fix except used for solink instead of link
. | 37 # Same as libs_section_{pre,post}fix except used for solink instead of link
. |
50 # - link_outputs | 38 # - link_outputs |
51 # The content of this array, if specified, will be added to the list of | 39 # The content of this array, if specified, will be added to the list of |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } else { | 172 } else { |
185 solink_libs_section_prefix = "" | 173 solink_libs_section_prefix = "" |
186 } | 174 } |
187 | 175 |
188 if (defined(invoker.solink_libs_section_postfix)) { | 176 if (defined(invoker.solink_libs_section_postfix)) { |
189 solink_libs_section_postfix = invoker.solink_libs_section_postfix | 177 solink_libs_section_postfix = invoker.solink_libs_section_postfix |
190 } else { | 178 } else { |
191 solink_libs_section_postfix = "" | 179 solink_libs_section_postfix = "" |
192 } | 180 } |
193 | 181 |
194 if (defined(invoker.extra_cflags) && invoker.extra_cflags != "") { | |
195 extra_cflags = " " + invoker.extra_cflags | |
196 } else { | |
197 extra_cflags = "" | |
198 } | |
199 | |
200 if (defined(invoker.extra_cppflags) && invoker.extra_cppflags != "") { | |
201 extra_cppflags = " " + invoker.extra_cppflags | |
202 } else { | |
203 extra_cppflags = "" | |
204 } | |
205 | |
206 if (defined(invoker.extra_cxxflags) && invoker.extra_cxxflags != "") { | |
207 extra_cxxflags = " " + invoker.extra_cxxflags | |
208 } else { | |
209 extra_cxxflags = "" | |
210 } | |
211 | |
212 if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") { | |
213 extra_ldflags = " " + invoker.extra_ldflags | |
214 } else { | |
215 extra_ldflags = "" | |
216 } | |
217 | |
218 # These library switches can apply to all tools below. | 182 # These library switches can apply to all tools below. |
219 lib_switch = "-l" | 183 lib_switch = "-l" |
220 lib_dir_switch = "-L" | 184 lib_dir_switch = "-L" |
221 | 185 |
222 # Object files go in this directory. | 186 # Object files go in this directory. |
223 object_subdir = "{{target_out_dir}}/{{label_name}}" | 187 object_subdir = "{{target_out_dir}}/{{label_name}}" |
224 | 188 |
225 tool("cc") { | 189 tool("cc") { |
226 depfile = "{{output}}.d" | 190 depfile = "{{output}}.d" |
227 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{
output}}" | 191 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
228 depsformat = "gcc" | 192 depsformat = "gcc" |
229 description = "CC {{output}}" | 193 description = "CC {{output}}" |
230 outputs = [ | 194 outputs = [ |
231 "$object_subdir/{{source_name_part}}.o", | 195 "$object_subdir/{{source_name_part}}.o", |
232 ] | 196 ] |
233 } | 197 } |
234 | 198 |
235 tool("cxx") { | 199 tool("cxx") { |
236 depfile = "{{output}}.d" | 200 depfile = "{{output}}.d" |
237 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -
o {{output}}" | 201 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
238 depsformat = "gcc" | 202 depsformat = "gcc" |
239 description = "CXX {{output}}" | 203 description = "CXX {{output}}" |
240 outputs = [ | 204 outputs = [ |
241 "$object_subdir/{{source_name_part}}.o", | 205 "$object_subdir/{{source_name_part}}.o", |
242 ] | 206 ] |
243 } | 207 } |
244 | 208 |
245 tool("asm") { | 209 tool("asm") { |
246 # For GCC we can just use the C compiler to compile assembly. | 210 # For GCC we can just use the C compiler to compile assembly. |
247 depfile = "{{output}}.d" | 211 depfile = "{{output}}.d" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } else { | 249 } else { |
286 unstripped_sofile = sofile | 250 unstripped_sofile = sofile |
287 } | 251 } |
288 | 252 |
289 # These variables are not built into GN but are helpers that | 253 # These variables are not built into GN but are helpers that |
290 # implement (1) linking to produce a .so, (2) extracting the symbols | 254 # implement (1) linking to produce a .so, (2) extracting the symbols |
291 # from that file (3) if the extracted list differs from the existing | 255 # from that file (3) if the extracted list differs from the existing |
292 # .TOC file, overwrite it, otherwise, don't change it. | 256 # .TOC file, overwrite it, otherwise, don't change it. |
293 tocfile = sofile + ".TOC" | 257 tocfile = sofile + ".TOC" |
294 | 258 |
295 link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_s
ofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" | 259 link_command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-son
ame=\"$soname\" @\"$rspfile\"" |
296 | 260 |
297 assert(defined(readelf), "to solink you must have a readelf") | 261 assert(defined(readelf), "to solink you must have a readelf") |
298 assert(defined(nm), "to solink you must have an nm") | 262 assert(defined(nm), "to solink you must have an nm") |
299 strip_switch = "" | 263 strip_switch = "" |
300 if (defined(invoker.strip)) { | 264 if (defined(invoker.strip)) { |
301 strip_switch = "--strip=${invoker.strip}" | 265 strip_switch = "--strip=${invoker.strip}" |
302 } | 266 } |
303 | 267 |
304 # This needs a Python script to avoid using a complex shell command | 268 # This needs a Python script to avoid using a complex shell command |
305 # requiring sh control structures, pipelines, and POSIX utilities. | 269 # requiring sh control structures, pipelines, and POSIX utilities. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". | 309 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
346 sofile = "{{output_dir}}/$soname" | 310 sofile = "{{output_dir}}/$soname" |
347 rspfile = sofile + ".rsp" | 311 rspfile = sofile + ".rsp" |
348 | 312 |
349 if (defined(invoker.strip)) { | 313 if (defined(invoker.strip)) { |
350 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" | 314 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" |
351 } else { | 315 } else { |
352 unstripped_sofile = sofile | 316 unstripped_sofile = sofile |
353 } | 317 } |
354 | 318 |
355 command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile
\" -Wl,-soname=\"$soname\" @\"$rspfile\"" | 319 command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-soname=\
"$soname\" @\"$rspfile\"" |
356 | 320 |
357 if (defined(invoker.strip)) { | 321 if (defined(invoker.strip)) { |
358 strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$uns
tripped_sofile\"" | 322 strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$uns
tripped_sofile\"" |
359 command += " && " + strip_command | 323 command += " && " + strip_command |
360 } | 324 } |
361 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" | 325 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
362 | 326 |
363 description = "SOLINK_MODULE $sofile" | 327 description = "SOLINK_MODULE $sofile" |
364 | 328 |
365 # Use this for {{output_extension}} expansions unless a target manually | 329 # Use this for {{output_extension}} expansions unless a target manually |
(...skipping 30 matching lines...) Expand all Loading... |
396 # overrides it (in which case {{output_extension}} will be what the target | 360 # overrides it (in which case {{output_extension}} will be what the target |
397 # specifies). | 361 # specifies). |
398 default_output_extension = default_executable_extension | 362 default_output_extension = default_executable_extension |
399 | 363 |
400 default_output_dir = "{{root_out_dir}}" | 364 default_output_dir = "{{root_out_dir}}" |
401 | 365 |
402 if (defined(invoker.strip)) { | 366 if (defined(invoker.strip)) { |
403 unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename" | 367 unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename" |
404 } | 368 } |
405 | 369 |
406 command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" -Wl,
--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{li
bs}} $libs_section_postfix" | 370 command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,--start-group @\
"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_secti
on_postfix" |
407 if (defined(invoker.strip)) { | 371 if (defined(invoker.strip)) { |
408 link_wrapper = | 372 link_wrapper = |
409 rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) | 373 rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) |
410 command = "$python_path \"$link_wrapper\" --strip=\"${invoker.strip}\" -
-unstripped-file=\"$unstripped_outfile\" --output=\"$outfile\" -- $command" | 374 command = "$python_path \"$link_wrapper\" --strip=\"${invoker.strip}\" -
-unstripped-file=\"$unstripped_outfile\" --output=\"$outfile\" -- $command" |
411 } | 375 } |
412 description = "LINK $outfile" | 376 description = "LINK $outfile" |
413 rspfile_content = "{{inputs}}" | 377 rspfile_content = "{{inputs}}" |
414 outputs = [ | 378 outputs = [ |
415 outfile, | 379 outfile, |
416 ] | 380 ] |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 "toolchain_os", | 502 "toolchain_os", |
539 "use_gold", | 503 "use_gold", |
540 "v8_toolchain_cpu", | 504 "v8_toolchain_cpu", |
541 ]) | 505 ]) |
542 | 506 |
543 if (defined(invoker.use_debug_fission)) { | 507 if (defined(invoker.use_debug_fission)) { |
544 use_debug_fission = invoker.use_debug_fission | 508 use_debug_fission = invoker.use_debug_fission |
545 } | 509 } |
546 } | 510 } |
547 } | 511 } |
OLD | NEW |