blob: a244bf02d7adaa0a2e55590c2ad82af185ff4821 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# Copyright 2016 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
5if (current_cpu == "x86") {
6 _yasm_flags = [
7 "-felf32",
8 "-m",
9 "x86",
10 ]
11} else if (current_cpu == "x64") {
12 _yasm_flags = [
13 "-DPIC",
14 "-felf64",
15 "-m",
16 "amd64",
17 ]
18}
19
20template("yasm_assemble") {
21 action_name = "${target_name}_action"
22 source_set_name = target_name
23
24 action_foreach(action_name) {
25 # Only the source set can depend on this.
26 visibility = [ ":$source_set_name" ]
27
28 script = "//third_party/yasm/run_yasm.py"
29 sources = invoker.sources
30
31 if (defined(invoker.inputs)) {
32 inputs = invoker.inputs
33 }
34
35 deps = []
36 if (defined(invoker.deps)) {
37 deps += invoker.deps
38 }
39
40 args = [ "yasm" ] + _yasm_flags
41 if (defined(invoker.yasm_flags)) {
42 args += invoker.yasm_flags
43 }
44
45 # User defined include dirs go first.
46 if (defined(invoker.include_dirs)) {
47 foreach(include, invoker.include_dirs) {
48 args += [ "-I" + rebase_path(include, root_build_dir) ]
49 }
50 }
51
52 # Default yasm include dirs. Make it match the native build (source root and
53 # root generated code directory).
54 # This goes to the end of include list.
55 args += [
56 "-I.",
57
58 # Using "//." will produce a relative path "../.." which looks better than
59 # "../../" which will result from using "//" as the base (although both
60 # work). This is because rebase_path will terminate the result in a
61 # slash if the input ends in a slash.
62 "-I" + rebase_path("//.", root_build_dir),
63 "-I" + rebase_path(root_gen_dir, root_build_dir),
64 ]
65
66 # Extra defines.
67 if (defined(invoker.defines)) {
68 foreach(def, invoker.defines) {
69 args += [ "-D$def" ]
70 }
71 }
72
73 # Output file.
74 outputs = [
75 "$target_out_dir/$source_set_name/{{source_name_part}}.o",
76 ]
77 args += [
78 "-o",
79 rebase_path(outputs[0], root_build_dir),
80 "{{source}}",
81 ]
82
83 # The wrapper script run_yasm will write the depfile to the same name as
84 # the output but with .d appended (like gcc will).
85 depfile = outputs[0] + ".d"
86 }
87
88 # Gather the .o files into a linkable thing. This doesn't actually link
89 # anything (a source set just compiles files to link later), but will pass
90 # the object files generated by the action up the dependency chain.
91 source_set(source_set_name) {
92 if (defined(invoker.visibility)) {
93 visibility = invoker.visibility
94 }
95
96 sources = get_target_outputs(":$action_name")
97
98 deps = [
99 ":$action_name",
100 ]
101 }
102}