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 | 12 |
13 # This template defines a toolchain for something that works like gcc | 13 # This template defines a toolchain for something that works like gcc |
14 # (including clang). | 14 # (including clang). |
15 # | 15 # |
16 # It requires the following variables specifying the executables to run: | 16 # It requires the following variables specifying the executables to run: |
17 # - ar | 17 # - ar |
18 # - cc | 18 # - cc |
19 # - cxx | 19 # - cxx |
20 # - ld | 20 # - ld |
21 # | 21 # |
22 # Optional parameters that control the tools: | 22 # Optional parameters that control the tools: |
23 # | 23 # |
24 # - extra_cflags | |
25 # Extra flags to be appended when compiling C files (but not C++ files). | |
26 # - extra_cppflags | |
27 # Extra flags to be appended when compiling both C and C++ files. "CPP" | |
28 # stands for "C PreProcessor" in this context, although it can be | |
29 # used for non-preprocessor flags as well. Not to be confused with | |
30 # "CXX" (which follows). | |
31 # - extra_cxxflags | |
32 # Extra flags to be appended when compiling C++ files (but not C files). | |
33 # - extra_ldflags | |
34 # Extra flags to be appended when linking | |
35 # | |
36 # - libs_section_prefix | 24 # - libs_section_prefix |
37 # - libs_section_postfix | 25 # - libs_section_postfix |
38 # The contents of these strings, if specified, will be placed around | 26 # The contents of these strings, if specified, will be placed around |
39 # the libs section of the linker line. It allows one to inject libraries | 27 # the libs section of the linker line. It allows one to inject libraries |
40 # at the beginning and end for all targets in a toolchain. | 28 # at the beginning and end for all targets in a toolchain. |
41 # - solink_libs_section_prefix | 29 # - solink_libs_section_prefix |
42 # - solink_libs_section_postfix | 30 # - solink_libs_section_postfix |
43 # Same as libs_section_{pre,post}fix except used for solink instead of link
. | 31 # Same as libs_section_{pre,post}fix except used for solink instead of link
. |
44 # - link_outputs | 32 # - link_outputs |
45 # The content of this array, if specified, will be added to the list of | 33 # The content of this array, if specified, will be added to the list of |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } else { | 169 } else { |
182 solink_libs_section_prefix = "" | 170 solink_libs_section_prefix = "" |
183 } | 171 } |
184 | 172 |
185 if (defined(invoker.solink_libs_section_postfix)) { | 173 if (defined(invoker.solink_libs_section_postfix)) { |
186 solink_libs_section_postfix = invoker.solink_libs_section_postfix | 174 solink_libs_section_postfix = invoker.solink_libs_section_postfix |
187 } else { | 175 } else { |
188 solink_libs_section_postfix = "" | 176 solink_libs_section_postfix = "" |
189 } | 177 } |
190 | 178 |
191 if (defined(invoker.extra_cflags) && invoker.extra_cflags != "") { | |
192 extra_cflags = " " + invoker.extra_cflags | |
193 } else { | |
194 extra_cflags = "" | |
195 } | |
196 | |
197 if (defined(invoker.extra_cppflags) && invoker.extra_cppflags != "") { | |
198 extra_cppflags = " " + invoker.extra_cppflags | |
199 } else { | |
200 extra_cppflags = "" | |
201 } | |
202 | |
203 if (defined(invoker.extra_cxxflags) && invoker.extra_cxxflags != "") { | |
204 extra_cxxflags = " " + invoker.extra_cxxflags | |
205 } else { | |
206 extra_cxxflags = "" | |
207 } | |
208 | |
209 if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") { | |
210 extra_ldflags = " " + invoker.extra_ldflags | |
211 } else { | |
212 extra_ldflags = "" | |
213 } | |
214 | |
215 # These library switches can apply to all tools below. | 179 # These library switches can apply to all tools below. |
216 lib_switch = "-l" | 180 lib_switch = "-l" |
217 lib_dir_switch = "-L" | 181 lib_dir_switch = "-L" |
218 | 182 |
219 # Object files go in this directory. | 183 # Object files go in this directory. |
220 object_subdir = "{{target_out_dir}}/{{label_name}}" | 184 object_subdir = "{{target_out_dir}}/{{label_name}}" |
221 | 185 |
222 tool("cc") { | 186 tool("cc") { |
223 depfile = "{{output}}.d" | 187 depfile = "{{output}}.d" |
224 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{
output}}" | 188 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
225 depsformat = "gcc" | 189 depsformat = "gcc" |
226 description = "CC {{output}}" | 190 description = "CC {{output}}" |
227 outputs = [ | 191 outputs = [ |
228 "$object_subdir/{{source_name_part}}.o", | 192 "$object_subdir/{{source_name_part}}.o", |
229 ] | 193 ] |
230 } | 194 } |
231 | 195 |
232 tool("cxx") { | 196 tool("cxx") { |
233 depfile = "{{output}}.d" | 197 depfile = "{{output}}.d" |
234 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -
o {{output}}" | 198 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
235 depsformat = "gcc" | 199 depsformat = "gcc" |
236 description = "CXX {{output}}" | 200 description = "CXX {{output}}" |
237 outputs = [ | 201 outputs = [ |
238 "$object_subdir/{{source_name_part}}.o", | 202 "$object_subdir/{{source_name_part}}.o", |
239 ] | 203 ] |
240 } | 204 } |
241 | 205 |
242 tool("asm") { | 206 tool("asm") { |
243 # For GCC we can just use the C compiler to compile assembly. | 207 # For GCC we can just use the C compiler to compile assembly. |
244 depfile = "{{output}}.d" | 208 depfile = "{{output}}.d" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } else { | 247 } else { |
284 unstripped_sofile = sofile | 248 unstripped_sofile = sofile |
285 } | 249 } |
286 | 250 |
287 # These variables are not built into GN but are helpers that | 251 # These variables are not built into GN but are helpers that |
288 # implement (1) linking to produce a .so, (2) extracting the symbols | 252 # implement (1) linking to produce a .so, (2) extracting the symbols |
289 # from that file (3) if the extracted list differs from the existing | 253 # from that file (3) if the extracted list differs from the existing |
290 # .TOC file, overwrite it, otherwise, don't change it. | 254 # .TOC file, overwrite it, otherwise, don't change it. |
291 tocfile = sofile + ".TOC" | 255 tocfile = sofile + ".TOC" |
292 | 256 |
293 link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_s
ofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" | 257 link_command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-son
ame=\"$soname\" @\"$rspfile\"" |
294 | 258 |
295 assert(defined(readelf), "to solink you must have a readelf") | 259 assert(defined(readelf), "to solink you must have a readelf") |
296 assert(defined(nm), "to solink you must have an nm") | 260 assert(defined(nm), "to solink you must have an nm") |
297 strip_switch = "" | 261 strip_switch = "" |
298 if (defined(invoker.strip)) { | 262 if (defined(invoker.strip)) { |
299 strip_switch = "--strip=${invoker.strip}" | 263 strip_switch = "--strip=${invoker.strip}" |
300 } | 264 } |
301 | 265 |
302 # This needs a Python script to avoid using a complex shell command | 266 # This needs a Python script to avoid using a complex shell command |
303 # requiring sh control structures, pipelines, and POSIX utilities. | 267 # requiring sh control structures, pipelines, and POSIX utilities. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 sofile = "{{output_dir}}/$soname" | 308 sofile = "{{output_dir}}/$soname" |
345 rspfile = sofile + ".rsp" | 309 rspfile = sofile + ".rsp" |
346 pool = "//build/toolchain:link_pool($default_toolchain)" | 310 pool = "//build/toolchain:link_pool($default_toolchain)" |
347 | 311 |
348 if (defined(invoker.strip)) { | 312 if (defined(invoker.strip)) { |
349 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" | 313 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" |
350 } else { | 314 } else { |
351 unstripped_sofile = sofile | 315 unstripped_sofile = sofile |
352 } | 316 } |
353 | 317 |
354 command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile
\" -Wl,-soname=\"$soname\" @\"$rspfile\"" | 318 command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-soname=\
"$soname\" @\"$rspfile\"" |
355 | 319 |
356 if (defined(invoker.strip)) { | 320 if (defined(invoker.strip)) { |
357 strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$uns
tripped_sofile\"" | 321 strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$uns
tripped_sofile\"" |
358 command += " && " + strip_command | 322 command += " && " + strip_command |
359 } | 323 } |
360 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" | 324 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
361 | 325 |
362 description = "SOLINK_MODULE $sofile" | 326 description = "SOLINK_MODULE $sofile" |
363 | 327 |
364 # Use this for {{output_extension}} expansions unless a target manually | 328 # Use this for {{output_extension}} expansions unless a target manually |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 forward_variables_from(invoker, [ "strip" ]) | 429 forward_variables_from(invoker, [ "strip" ]) |
466 | 430 |
467 toolchain_args = { | 431 toolchain_args = { |
468 if (defined(invoker.toolchain_args)) { | 432 if (defined(invoker.toolchain_args)) { |
469 forward_variables_from(invoker.toolchain_args, "*") | 433 forward_variables_from(invoker.toolchain_args, "*") |
470 } | 434 } |
471 is_clang = true | 435 is_clang = true |
472 } | 436 } |
473 } | 437 } |
474 } | 438 } |
OLD | NEW |