Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: third_party/yasm/yasm_assemble.gni

Issue 321323004: Add yasm to the GN build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 # Parameters
11 #
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).
17 #
18 # Example: yasm_flags = [ "--force-strict" ]
19 #
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.
24 #
25 # Example: include_dirs = [ "//some/other/path", target_gen_dir ]
26 #
27 # defines (optional)
28 # [list of strings] List of defines, as with the native code defines.
29 #
30 # Example: defines = [ "FOO", "BAR=1" ]
31 #
32 # source_prereqs, deps, visibility (optional)
33 # These have the same meaning as in an action.
34 #
35 # Example
36 #
37 # yasm_assemble("my_yasm_target") {
38 # sources = [
39 # "ultra_optimized_awesome.asm",
40 # ]
41 # include_dirs = [ "assembly_include" ]
42 # }
43
44 import("//build/compiled_action.gni")
45
46 if (is_mac || is_ios) {
47 if (cpu_arch == "x86") {
48 _yasm_flags = [
49 "-fmacho32",
50 "-m", "x86",
51 ]
52 } else if (cpu_arch == "x64") {
53 _yasm_flags = [
54 "-fmacho64",
55 "-m", "amd64",
56 ]
57 }
58 } else if (is_posix) {
59 if (cpu_arch == "x86") {
60 _yasm_flags = [
61 "-felf32",
62 "-m", "x86",
63 ]
64 } else if (cpu_arch == "x64") {
65 _yasm_flags = [
66 "-DPIC",
67 "-felf64",
68 "-m", "amd64",
69 ]
70 }
71 } else if (is_win) {
72 if (cpu_arch == "x86") {
73 _yasm_flags = [
74 "-DPREFIX",
75 "-fwin32",
76 "-m", "x86",
77 ]
78 } else if (cpu_arch == "x64") {
79 _yasm_flags = [
80 "-fwin64",
81 "-m", "amd64",
82 ]
83 }
84 }
85
86 # Default yasm include dirs. Make it match the native build (source root and
87 # root generated code directory).
88 _yasm_flags += [
89 # Using "//." will produce a relative path "../.." which looks better than
90 # "../../" which will result from using "//" as the base (although both
91 # work). This is because rebase_path will terminate the result in a slash if
92 # the input ends in a slash.
93 "-I" + rebase_path("//.", root_build_dir),
94 "-I" + rebase_path(root_gen_dir, root_build_dir),
95 ]
96
97 if (is_win) {
98 asm_obj_extension = "obj"
99 } else {
100 asm_obj_extension = "o"
101 }
102
103 template("yasm_assemble") {
104 # TODO(ajwong): Support use_system_yasm.
105 assert(defined(invoker.sources), "Need sources defined for $target_name")
106
107 # Only depend on YASM on x86 systems. Force compilation of .asm files for
108 # ARM to fail.
109 assert(cpu_arch == "x86" || cpu_arch == "x64")
110
111 action_name = "${target_name}_action"
112 source_set_name = target_name
113
114 action_foreach(action_name) {
115 visibility = ":$source_set_name" # Only the source set can depend on this.
116
117 script = "//third_party/yasm/run_yasm.py"
118 sources = invoker.sources
119
120 if (defined(invoker.source_prereqs)) {
121 source_prereqs = invoker.source_prereqs
122 }
123
124 # Executable (first in the args). The binary might be in the root build dir
125 # (no cross-compiling) or in a toolchain-specific subdirectory of that
126 # (when cross-compiling).
127 yasm_label = "//third_party/yasm($host_toolchain)"
128 args = [
129 rebase_path(get_label_info(yasm_label, "root_out_dir") + "/yasm",
130 "root_build_dir")
131 ]
132
133 # Deps.
134 deps = [ yasm_label ]
135 if (defined(invoker.deps)) {
136 deps += invoker.deps
137 }
138
139 # Flags.
140 args += _yasm_flags
141 if (defined(invoker.yasm_flags)) {
142 args += invoker.yasm_flags
143 }
144
145 # Extra include directories.
146 if (defined(invoker.include_dirs)) {
147 foreach(include, invoker.include_dirs) {
148 args += [ "-I" + rebase_path(include, root_build_dir) ]
149 }
150 }
151
152 # Extra defines.
153 if (defined(invoker.defines)) {
154 foreach(def, invoker.defines) {
155 args += [ "-D$def" ]
156 }
157 }
158
159 # Output file.
160 #
161 # TODO(brettw) it might be nice if there was a source expansion for the
162 # path of the source file relative to the source root. Then we could
163 # exactly duplicate the naming and location of object files from the
164 # native build, which would be:
165 # "$root_out_dir/${target_name}.{{source_dir_part}}.$asm_obj_extension"
166 outputs = [ "$target_out_dir/{{source_name_part}}.o" ]
167 args += [
168 "-o", rebase_path(outputs[0], root_build_dir),
169 "{{source}}"
170 ]
171
172 # The wrapper script run_yasm will write the depfile to the same name as
173 # the output but with .d appended (like gcc will).
174 depfile = outputs[0] + ".d"
175 }
176
177 # Gather the .o files into a linkable thing. This doesn't actually link
178 # anything (a source set just compiles files to link later), but will pass
179 # the object files generated by the action up the dependency chain.
180 source_set(source_set_name) {
181 if (defined(invoker.visibility)) {
182 visibility = invoker.visibility
183 }
184
185 sources = get_target_outputs(":$action_name")
186 }
187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698