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.
5 # This provides the yasm_assemble() template which uses YASM to assemble
8 # Files to be assembled with YASM should have an extension of .asm.
12 # yasm_flags (optional)
13 # [list of strings] Pass additional flags into YASM. These are appended
14 # to the command line. Note that the target machine type and system is
15 # already set up based on the current toolchain so you don't need to
16 # specify these things (see below).
18 # Example: yasm_flags = [ "--force-strict" ]
20 # include_dirs (optional)
21 # [list of dir names] List of additional include dirs. Note that the
22 # source root and the root generated file dir is always added, just like
23 # our C++ build sets up.
25 # Example: include_dirs = [ "//some/other/path", target_gen_dir ]
28 # [list of strings] List of defines, as with the native code defines.
30 # Example: defines = [ "FOO", "BAR=1" ]
32 # inputs, deps, visibility (optional)
33 # These have the same meaning as in an action.
37 # yasm_assemble("my_yasm_target") {
39 # "ultra_optimized_awesome.asm",
41 # include_dirs = [ "assembly_include" ]
44 if (is_mac || is_ios) {
45 if (cpu_arch == "x86") {
50 } else if (cpu_arch == "x64") {
56 } else if (is_posix) {
57 if (cpu_arch == "x86") {
62 } else if (cpu_arch == "x64") {
70 if (cpu_arch == "x86") {
76 } else if (cpu_arch == "x64") {
85 asm_obj_extension = "obj"
87 asm_obj_extension = "o"
90 template("yasm_assemble") {
91 # TODO(ajwong): Support use_system_yasm.
92 assert(defined(invoker.sources), "Need sources defined for $target_name")
94 # Only depend on YASM on x86 systems. Force compilation of .asm files for
96 assert(cpu_arch == "x86" || cpu_arch == "x64")
98 action_name = "${target_name}_action"
99 source_set_name = target_name
101 action_foreach(action_name) {
102 # Only the source set can depend on this.
103 visibility = [ ":$source_set_name" ]
105 script = "//third_party/yasm/run_yasm.py"
106 sources = invoker.sources
108 if (defined(invoker.inputs)) {
109 inputs = invoker.inputs
112 # Executable (first in the args). The binary might be in the root build dir
113 # (no cross-compiling) or in a toolchain-specific subdirectory of that
114 # (when cross-compiling).
115 yasm_label = "//third_party/yasm($host_toolchain)"
116 args = [ "./" + # Force current dir.
117 rebase_path(get_label_info(yasm_label, "root_out_dir") + "/yasm",
122 deps = [ yasm_label ]
123 if (defined(invoker.deps)) {
129 if (defined(invoker.yasm_flags)) {
130 args += invoker.yasm_flags
133 # User defined include dirs go first.
134 if (defined(invoker.include_dirs)) {
135 foreach(include, invoker.include_dirs) {
136 args += [ "-I" + rebase_path(include, root_build_dir) ]
140 # Default yasm include dirs. Make it match the native build (source root and
141 # root generated code directory).
142 # This goes to the end of include list.
145 # Using "//." will produce a relative path "../.." which looks better than
146 # "../../" which will result from using "//" as the base (although both
147 # work). This is because rebase_path will terminate the result in a
148 # slash if the input ends in a slash.
149 "-I" + rebase_path("//.", root_build_dir),
150 "-I" + rebase_path(root_gen_dir, root_build_dir),
155 if (defined(invoker.defines)) {
156 foreach(def, invoker.defines) {
163 # TODO(brettw) it might be nice if there was a source expansion for the
164 # path of the source file relative to the source root. Then we could
165 # exactly duplicate the naming and location of object files from the
166 # native build, which would be:
167 # "$root_out_dir/${target_name}.{{source_dir_part}}.$asm_obj_extension"
168 outputs = [ "$target_out_dir/{{source_name_part}}.o" ]
170 "-o", rebase_path(outputs[0], root_build_dir),
174 # The wrapper script run_yasm will write the depfile to the same name as
175 # the output but with .d appended (like gcc will).
176 depfile = outputs[0] + ".d"
179 # Gather the .o files into a linkable thing. This doesn't actually link
180 # anything (a source set just compiles files to link later), but will pass
181 # the object files generated by the action up the dependency chain.
182 source_set(source_set_name) {
183 if (defined(invoker.visibility)) {
184 visibility = invoker.visibility
187 sources = get_target_outputs(":$action_name")
189 deps = [ ":$action_name" ]