Chromium Code Reviews| Index: third_party/yasm/yasm_assemble.gni |
| diff --git a/third_party/yasm/yasm_assemble.gni b/third_party/yasm/yasm_assemble.gni |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..05f304af64d050130a2314d3d50da5373c779599 |
| --- /dev/null |
| +++ b/third_party/yasm/yasm_assemble.gni |
| @@ -0,0 +1,107 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# This provides the yasm_assemble() template which uses YASM to assemble |
| +# assembly files. |
| +# |
| +# Files to be assembled with YASM should have an extension of .asm. |
| +# |
| +# There are three variables with this template: |
| +# yasm_flags : Pass additional flags into YASM. |
| +# yasm_output_path : Output directory for the compiled object files. |
| +# yasm_includes : Includes used by .asm code. Changes to which should force |
| +# recompilation. |
| +# |
| +# Sample usage: |
| +# yasm_assemble("my_yasm_target") { |
| +# sources = [ "ultra_optimized_awesome.asm" ] |
| +# yasm_flags = [ "-I", "assembly_include", ], |
| +# yasm_output_path = "$target_gen_dir/project" |
| +# yasm_includes = [ "ultra_optimized_awesome.inc" ] |
| +# } |
| + |
| +import("//build/gn_helper_scripts.gni") |
| + |
| +template("yasm_assemble") { |
| + # TODO(ajwong): Support use_system_yasm. |
| + |
| + if (is_mac || is_ios) { |
|
brettw
2014/05/09 20:17:54
Do you think this file will be used a lot? If so,
brettw
2014/05/09 20:56:56
Oh: prefix the names with _ if you do this so they
awong
2014/05/10 08:55:34
Should GN generate a warning or error on a shadow
awong
2014/05/10 08:55:34
It's not super common, but moved it out anyways.
|
| + if (cpu_arch == "x86") { |
| + yasm_flags = [ |
| + "-fmacho32", |
| + "-m", "x86", |
| + ] |
| + } else if (cpu_arch == "x64") { |
| + yasm_flags = [ |
| + "-fmacho64", |
| + "-m", "amd64", |
| + ] |
| + } |
| + } else if (is_posix) { |
| + if (cpu_arch == "x86") { |
| + yasm_flags = [ |
| + "-felf32", |
| + "-m", "x86", |
| + ] |
| + } else if (cpu_arch == "x64") { |
| + yasm_flags = [ |
| + "-DPIC", |
| + "-felf64", |
| + "-m", "amd64", |
| + ] |
| + } |
| + } else if (is_win) { |
| + if (cpu_arch == "x86") { |
| + yasm_flags = [ |
| + "-DPREFIX", |
| + "-fwin32", |
| + "-m", "x86", |
| + ] |
| + } else if (cpu_arch == "x64") { |
| + yasm_flags = [ |
| + "-fwin64", |
| + "-m", "amd64", |
| + ] |
| + } |
| + } |
| + |
| + if (is_win) { |
| + asm_obj_extension = "obj" |
| + } else { |
| + asm_obj_extension = "o" |
| + } |
| + |
| + assert(defined(invoker.yasm_output_path)) |
| + yasm_output_path = invoker.yasm_output_path |
| + |
| + source_set(target_name) { |
| + sources = process_file_template( |
| + invoker.sources, |
| + "$yasm_output_path/{{source_name_part}}.o") |
| + deps = [ ":${target_name}_yasm" ] |
| + } |
| + |
| + run_executable_foreach("${target_name}_yasm") { |
| + sources = invoker.sources |
| + binary_name = "yasm" |
|
brettw
2014/05/09 20:17:54
While this works for the main toolchain, it won't
awong
2014/05/10 08:55:34
I think I finally understand enough to make this w
|
| + outputs = [ "$yasm_output_path/{{source_name_part}}.$asm_obj_extension" ] |
| + args = yasm_flags |
| + if (defined(invoker.yasm_flags)) { |
| + args += invoker.yasm_flags |
| + } |
| + args += [ |
| + "-o", rebase_path(outputs[0], root_build_dir), |
| + "{{source}}" |
| + ] |
| + |
| + if (defined(invoker.yasm_includes)) { |
| + source_prereqs = rebase_path(invoker.yasm_includes, root_build_dir) |
| + } |
| + |
| + # Only depend on YASM on x86 systems. Force compilation of .asm files for |
| + # ARM to fail. |
| + assert(cpu_arch == "x86" || cpu_arch == "x64") |
| + deps = [ "//third_party/yasm($host_toolchain)" ] |
| + } |
| +} |