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("//tools/grit/grit_rule.gni") | |
13 | 12 |
14 # This template defines a toolchain for something that works like gcc | 13 # This template defines a toolchain for something that works like gcc |
15 # (including clang). | 14 # (including clang). |
16 # | 15 # |
17 # It requires the following variables specifying the executables to run: | 16 # It requires the following variables specifying the executables to run: |
18 # - ar | 17 # - ar |
19 # - cc | 18 # - cc |
20 # - cxx | 19 # - cxx |
21 # - ld | 20 # - ld |
22 # | 21 # |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 213 } |
215 | 214 |
216 # These library switches can apply to all tools below. | 215 # These library switches can apply to all tools below. |
217 lib_switch = "-l" | 216 lib_switch = "-l" |
218 lib_dir_switch = "-L" | 217 lib_dir_switch = "-L" |
219 | 218 |
220 # Object files go in this directory. | 219 # Object files go in this directory. |
221 object_subdir = "{{target_out_dir}}/{{label_name}}" | 220 object_subdir = "{{target_out_dir}}/{{label_name}}" |
222 | 221 |
223 tool("cc") { | 222 tool("cc") { |
224 whitelist_flag = " " | |
225 if (enable_resource_whitelist_generation) { | |
226 whitelist_flag = " --resource-whitelist=\"{{output}}.whitelist\"" | |
227 } | |
228 depfile = "{{output}}.d" | 223 depfile = "{{output}}.d" |
229 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{
output}}" | 224 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{
output}}" |
230 depsformat = "gcc" | 225 depsformat = "gcc" |
231 description = "CC {{output}}" | 226 description = "CC {{output}}" |
232 outputs = [ | 227 outputs = [ |
233 # The whitelist file is also an output, but ninja does not | |
234 # currently support multiple outputs for tool("cc"). | |
235 "$object_subdir/{{source_name_part}}.o", | 228 "$object_subdir/{{source_name_part}}.o", |
236 ] | 229 ] |
237 compile_wrapper = rebase_path("//build/toolchain/gcc_compile_wrapper.py", | |
238 root_build_dir) | |
239 command = "$python_path \"$compile_wrapper\"$whitelist_flag $command" | |
240 } | 230 } |
241 | 231 |
242 tool("cxx") { | 232 tool("cxx") { |
243 whitelist_flag = " " | |
244 if (enable_resource_whitelist_generation) { | |
245 whitelist_flag = " --resource-whitelist=\"{{output}}.whitelist\"" | |
246 } | |
247 depfile = "{{output}}.d" | 233 depfile = "{{output}}.d" |
248 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -
o {{output}}" | 234 command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_d
irs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -
o {{output}}" |
249 depsformat = "gcc" | 235 depsformat = "gcc" |
250 description = "CXX {{output}}" | 236 description = "CXX {{output}}" |
251 outputs = [ | 237 outputs = [ |
252 # The whitelist file is also an output, but ninja does not | |
253 # currently support multiple outputs for tool("cxx"). | |
254 "$object_subdir/{{source_name_part}}.o", | 238 "$object_subdir/{{source_name_part}}.o", |
255 ] | 239 ] |
256 compile_wrapper = rebase_path("//build/toolchain/gcc_compile_wrapper.py", | |
257 root_build_dir) | |
258 command = "$python_path \"$compile_wrapper\"$whitelist_flag $command" | |
259 } | 240 } |
260 | 241 |
261 tool("asm") { | 242 tool("asm") { |
262 # For GCC we can just use the C compiler to compile assembly. | 243 # For GCC we can just use the C compiler to compile assembly. |
263 depfile = "{{output}}.d" | 244 depfile = "{{output}}.d" |
264 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{asmflags}} -c {{source}} -o {{output}}" | 245 command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_di
rs}} {{asmflags}} -c {{source}} -o {{output}}" |
265 depsformat = "gcc" | 246 depsformat = "gcc" |
266 description = "ASM {{output}}" | 247 description = "ASM {{output}}" |
267 outputs = [ | 248 outputs = [ |
268 "$object_subdir/{{source_name_part}}.o", | 249 "$object_subdir/{{source_name_part}}.o", |
269 ] | 250 ] |
270 } | 251 } |
271 | 252 |
272 tool("alink") { | 253 tool("alink") { |
273 rspfile = "{{output}}.rsp" | 254 rspfile = "{{output}}.rsp" |
274 whitelist_flag = " " | |
275 if (enable_resource_whitelist_generation) { | |
276 whitelist_flag = " --resource-whitelist=\"{{output}}.whitelist\"" | |
277 } | |
278 | 255 |
279 # This needs a Python script to avoid using simple sh features in this | 256 # This needs a Python script to avoid using simple sh features in this |
280 # command, in case the host does not use a POSIX shell (e.g. compiling | 257 # command, in case the host does not use a POSIX shell (e.g. compiling |
281 # POSIX-like toolchains such as NaCl on Windows). | 258 # POSIX-like toolchains such as NaCl on Windows). |
282 ar_wrapper = | 259 ar_wrapper = |
283 rebase_path("//build/toolchain/gcc_ar_wrapper.py", root_build_dir) | 260 rebase_path("//build/toolchain/gcc_ar_wrapper.py", root_build_dir) |
284 command = "$python_path \"$ar_wrapper\"$whitelist_flag --output={{output}}
--ar=\"$ar\" {{arflags}} rcsD @\"$rspfile\"" | 261 command = "$python_path \"$ar_wrapper\" --output={{output}} --ar=\"$ar\" {
{arflags}} rcsD @\"$rspfile\"" |
285 description = "AR {{output}}" | 262 description = "AR {{output}}" |
286 rspfile_content = "{{inputs}}" | 263 rspfile_content = "{{inputs}}" |
287 outputs = [ | 264 outputs = [ |
288 "{{output_dir}}/{{target_output_name}}{{output_extension}}", | 265 "{{output_dir}}/{{target_output_name}}{{output_extension}}", |
289 ] | 266 ] |
290 | 267 |
291 # Shared libraries go in the target out directory by default so we can | 268 # Shared libraries go in the target out directory by default so we can |
292 # generate different targets with the same name and not have them collide. | 269 # generate different targets with the same name and not have them collide. |
293 default_output_dir = "{{target_out_dir}}" | 270 default_output_dir = "{{target_out_dir}}" |
294 default_output_extension = ".a" | 271 default_output_extension = ".a" |
295 output_prefix = "lib" | 272 output_prefix = "lib" |
296 } | 273 } |
297 | 274 |
298 tool("solink") { | 275 tool("solink") { |
299 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". | 276 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
300 sofile = "{{output_dir}}/$soname" # Possibly including toolchain dir. | 277 sofile = "{{output_dir}}/$soname" # Possibly including toolchain dir. |
301 rspfile = sofile + ".rsp" | 278 rspfile = sofile + ".rsp" |
302 pool = "//build/toolchain:link_pool($default_toolchain)" | 279 pool = "//build/toolchain:link_pool($default_toolchain)" |
303 whitelist_flag = " " | |
304 if (enable_resource_whitelist_generation) { | |
305 whitelist_file = "$sofile.whitelist" | |
306 whitelist_flag = " --resource-whitelist=\"$whitelist_file\"" | |
307 } | |
308 | 280 |
309 if (defined(invoker.strip)) { | 281 if (defined(invoker.strip)) { |
310 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" | 282 unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" |
311 } else { | 283 } else { |
312 unstripped_sofile = sofile | 284 unstripped_sofile = sofile |
313 } | 285 } |
314 | 286 |
315 # These variables are not built into GN but are helpers that | 287 # These variables are not built into GN but are helpers that |
316 # implement (1) linking to produce a .so, (2) extracting the symbols | 288 # implement (1) linking to produce a .so, (2) extracting the symbols |
317 # from that file (3) if the extracted list differs from the existing | 289 # from that file (3) if the extracted list differs from the existing |
318 # .TOC file, overwrite it, otherwise, don't change it. | 290 # .TOC file, overwrite it, otherwise, don't change it. |
319 tocfile = sofile + ".TOC" | 291 tocfile = sofile + ".TOC" |
320 | 292 |
321 link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_s
ofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" | 293 link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_s
ofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" |
322 | 294 |
323 assert(defined(readelf), "to solink you must have a readelf") | 295 assert(defined(readelf), "to solink you must have a readelf") |
324 assert(defined(nm), "to solink you must have an nm") | 296 assert(defined(nm), "to solink you must have an nm") |
325 strip_switch = "" | 297 strip_switch = "" |
326 if (defined(invoker.strip)) { | 298 if (defined(invoker.strip)) { |
327 strip_switch = "--strip=${invoker.strip}" | 299 strip_switch = "--strip=${invoker.strip}" |
328 } | 300 } |
329 | 301 |
330 # This needs a Python script to avoid using a complex shell command | 302 # This needs a Python script to avoid using a complex shell command |
331 # requiring sh control structures, pipelines, and POSIX utilities. | 303 # requiring sh control structures, pipelines, and POSIX utilities. |
332 # The host might not have a POSIX shell and utilities (e.g. Windows). | 304 # The host might not have a POSIX shell and utilities (e.g. Windows). |
333 solink_wrapper = rebase_path("//build/toolchain/gcc_solink_wrapper.py") | 305 solink_wrapper = rebase_path("//build/toolchain/gcc_solink_wrapper.py") |
334 command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"
$nm\" $strip_switch --sofile=\"$unstripped_sofile\" --tocfile=\"$tocfile\" --out
put=\"$sofile\"$whitelist_flag -- $link_command" | 306 command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"
$nm\" $strip_switch --sofile=\"$unstripped_sofile\" --tocfile=\"$tocfile\" --out
put=\"$sofile\" -- $link_command" |
335 | 307 |
336 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" | 308 rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whol
e-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
337 | 309 |
338 description = "SOLINK $sofile" | 310 description = "SOLINK $sofile" |
339 | 311 |
340 # Use this for {{output_extension}} expansions unless a target manually | 312 # Use this for {{output_extension}} expansions unless a target manually |
341 # overrides it (in which case {{output_extension}} will be what the target | 313 # overrides it (in which case {{output_extension}} will be what the target |
342 # specifies). | 314 # specifies). |
343 default_output_extension = default_shlib_extension | 315 default_output_extension = default_shlib_extension |
344 | 316 |
345 default_output_dir = "{{root_out_dir}}" | 317 default_output_dir = "{{root_out_dir}}" |
346 if (shlib_subdir != ".") { | 318 if (shlib_subdir != ".") { |
347 default_output_dir += "/$shlib_subdir" | 319 default_output_dir += "/$shlib_subdir" |
348 } | 320 } |
349 | 321 |
350 output_prefix = "lib" | 322 output_prefix = "lib" |
351 | 323 |
352 # Since the above commands only updates the .TOC file when it changes, ask | 324 # Since the above commands only updates the .TOC file when it changes, ask |
353 # Ninja to check if the timestamp actually changed to know if downstream | 325 # Ninja to check if the timestamp actually changed to know if downstream |
354 # dependencies should be recompiled. | 326 # dependencies should be recompiled. |
355 restat = true | 327 restat = true |
356 | 328 |
357 # Tell GN about the output files. It will link to the sofile but use the | 329 # Tell GN about the output files. It will link to the sofile but use the |
358 # tocfile for dependency management. | 330 # tocfile for dependency management. |
359 outputs = [ | 331 outputs = [ |
360 sofile, | 332 sofile, |
361 tocfile, | 333 tocfile, |
362 ] | 334 ] |
363 if (enable_resource_whitelist_generation) { | |
364 outputs += [ whitelist_file ] | |
365 } | |
366 if (sofile != unstripped_sofile) { | 335 if (sofile != unstripped_sofile) { |
367 outputs += [ unstripped_sofile ] | 336 outputs += [ unstripped_sofile ] |
368 } | 337 } |
369 link_output = sofile | 338 link_output = sofile |
370 depend_output = tocfile | 339 depend_output = tocfile |
371 } | 340 } |
372 | 341 |
373 tool("solink_module") { | 342 tool("solink_module") { |
374 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". | 343 soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
375 sofile = "{{output_dir}}/$soname" | 344 sofile = "{{output_dir}}/$soname" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 forward_variables_from(invoker, [ "strip" ]) | 465 forward_variables_from(invoker, [ "strip" ]) |
497 | 466 |
498 toolchain_args = { | 467 toolchain_args = { |
499 if (defined(invoker.toolchain_args)) { | 468 if (defined(invoker.toolchain_args)) { |
500 forward_variables_from(invoker.toolchain_args, "*") | 469 forward_variables_from(invoker.toolchain_args, "*") |
501 } | 470 } |
502 is_clang = true | 471 is_clang = true |
503 } | 472 } |
504 } | 473 } |
505 } | 474 } |
OLD | NEW |