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..dd7fca2a804a4168e9abe15787396e93c607d37e |
--- /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") |
+ |
+if (is_mac || is_ios) { |
+ 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" |
+} |
+ |
+template("yasm_assemble") { |
+ # TODO(ajwong): Support use_system_yasm. |
+ |
+ 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" |
+ 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)" ] |
+ } |
+} |