OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # This provides the yasm_assemble() template which uses YASM to assemble |
| 6 # assembly files. |
| 7 # |
| 8 # Files to be assembled with YASM should have an extension of .asm. |
| 9 # |
| 10 # There are three variables with this template: |
| 11 # yasm_flags : Pass additional flags into YASM. |
| 12 # yasm_output_path : Output directory for the compiled object files. |
| 13 # yasm_includes : Includes used by .asm code. Changes to which should force |
| 14 # recompilation. |
| 15 # |
| 16 # Sample usage: |
| 17 # yasm_assemble("my_yasm_target") { |
| 18 # sources = [ "ultra_optimized_awesome.asm" ] |
| 19 # yasm_flags = [ "-I", "assembly_include", ], |
| 20 # yasm_output_path = "$target_gen_dir/project" |
| 21 # yasm_includes = [ "ultra_optimized_awesome.inc" ] |
| 22 # } |
| 23 |
| 24 import("//build/gn_helper_scripts.gni") |
| 25 |
| 26 if (is_mac || is_ios) { |
| 27 if (cpu_arch == "x86") { |
| 28 _yasm_flags = [ |
| 29 "-fmacho32", |
| 30 "-m", "x86", |
| 31 ] |
| 32 } else if (cpu_arch == "x64") { |
| 33 _yasm_flags = [ |
| 34 "-fmacho64", |
| 35 "-m", "amd64", |
| 36 ] |
| 37 } |
| 38 } else if (is_posix) { |
| 39 if (cpu_arch == "x86") { |
| 40 _yasm_flags = [ |
| 41 "-felf32", |
| 42 "-m", "x86", |
| 43 ] |
| 44 } else if (cpu_arch == "x64") { |
| 45 _yasm_flags = [ |
| 46 "-DPIC", |
| 47 "-felf64", |
| 48 "-m", "amd64", |
| 49 ] |
| 50 } |
| 51 } else if (is_win) { |
| 52 if (cpu_arch == "x86") { |
| 53 _yasm_flags = [ |
| 54 "-DPREFIX", |
| 55 "-fwin32", |
| 56 "-m", "x86", |
| 57 ] |
| 58 } else if (cpu_arch == "x64") { |
| 59 _yasm_flags = [ |
| 60 "-fwin64", |
| 61 "-m", "amd64", |
| 62 ] |
| 63 } |
| 64 } |
| 65 |
| 66 if (is_win) { |
| 67 asm_obj_extension = "obj" |
| 68 } else { |
| 69 asm_obj_extension = "o" |
| 70 } |
| 71 |
| 72 template("yasm_assemble") { |
| 73 # TODO(ajwong): Support use_system_yasm. |
| 74 |
| 75 assert(defined(invoker.yasm_output_path)) |
| 76 yasm_output_path = invoker.yasm_output_path |
| 77 |
| 78 source_set(target_name) { |
| 79 sources = process_file_template( |
| 80 invoker.sources, |
| 81 "$yasm_output_path/{{source_name_part}}.o") |
| 82 deps = [ ":${target_name}_yasm" ] |
| 83 } |
| 84 |
| 85 run_executable_foreach("${target_name}_yasm") { |
| 86 sources = invoker.sources |
| 87 binary_name = "yasm" |
| 88 outputs = [ "$yasm_output_path/{{source_name_part}}.$asm_obj_extension" ] |
| 89 args = _yasm_flags |
| 90 if (defined(invoker.yasm_flags)) { |
| 91 args += invoker.yasm_flags |
| 92 } |
| 93 args += [ |
| 94 "-o", rebase_path(outputs[0], root_build_dir), |
| 95 "{{source}}" |
| 96 ] |
| 97 |
| 98 if (defined(invoker.yasm_includes)) { |
| 99 source_prereqs = rebase_path(invoker.yasm_includes, root_build_dir) |
| 100 } |
| 101 |
| 102 # Only depend on YASM on x86 systems. Force compilation of .asm files for |
| 103 # ARM to fail. |
| 104 assert(cpu_arch == "x86" || cpu_arch == "x64") |
| 105 deps = [ "//third_party/yasm($host_toolchain)" ] |
| 106 } |
| 107 } |
OLD | NEW |