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 # The yasm build process creates a slew of small C subprograms that
6 # dynamically generate files at various point in the build process. This makes
7 # the build integration moderately complex.
9 # There are three classes of dynamically generated files:
10 # 1) C source files that should be included in the build (eg., lc3bid.c)
11 # 2) C source files that are #included by static C sources (eg., license.c)
12 # 3) Intermediate files that are used as input by other subprograms to
13 # further generate files in category #1 or #2. (eg., version.mac)
15 # This structure is represented with the following targets:
16 # 1) yasm -- Sources, flags for the main yasm executable. Also has most of
17 # of the actions and rules that invoke the subprograms.
18 # 2) yasm_config -- General build configuration including setting a
19 # inputs listing the checked in version of files
20 # generated by manually running configure. These manually
21 # generated files are used by all binaries.
22 # 3) yasm_utils -- Object files with memory management and hashing utilities
23 # shared between yasm and the genperf subprogram.
24 # 4) genmacro, genmodule, etc. -- One executable target for each subprogram.
25 # 5) generate_license, generate_module, etc. -- Actions that invoke programs
26 # built in #4 to generate .c files.
27 # 6) compile_gperf, compile_re2c, etc. -- Actions that invoke programs that
28 # turn intermediate files into .c files.
30 if (current_toolchain == host_toolchain) {
32 # Various files referenced by multiple targets.
33 yasm_gen_include_dir = "$target_gen_dir/include"
38 config_makefile = "source/config/$yasm_os/Makefile"
39 version_file = "version.mac"
41 import("//build/compiled_action.gni")
43 config("yasm_config") {
45 "source/config/$yasm_os",
46 "source/patched-yasm",
48 defines = [ "HAVE_CONFIG_H" ]
50 cflags = [ "-std=gnu99" ]
54 executable("genmacro") {
55 sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ]
56 configs -= [ "//build/config/compiler:chromium_code" ]
57 configs += [ ":yasm_config",
58 "//build/config/compiler:no_chromium_code" ]
61 executable("genmodule") {
62 sources = [ "source/patched-yasm/libyasm/genmodule.c" ]
63 configs -= [ "//build/config/compiler:chromium_code" ]
64 configs += [ ":yasm_config",
65 "//build/config/compiler:no_chromium_code" ]
68 executable("genperf") {
70 "source/patched-yasm/tools/genperf/genperf.c",
71 "source/patched-yasm/tools/genperf/perfect.c",
74 configs -= [ "//build/config/compiler:chromium_code" ]
75 configs += [ ":yasm_config",
76 "//build/config/compiler:no_chromium_code" ]
78 deps = [ ":yasm_utils" ]
81 # Used by both yasm and genperf binaries.
82 source_set("yasm_utils") {
84 "source/patched-yasm/libyasm/phash.c",
85 "source/patched-yasm/libyasm/xmalloc.c",
86 "source/patched-yasm/libyasm/xstrdup.c",
89 configs -= [ "//build/config/compiler:chromium_code" ]
90 configs += [ ":yasm_config",
91 "//build/config/compiler:no_chromium_code" ]
94 executable("genstring") {
95 sources = [ "source/patched-yasm/genstring.c", ]
96 configs -= [ "//build/config/compiler:chromium_code" ]
97 configs += [ ":yasm_config",
98 "//build/config/compiler:no_chromium_code" ]
101 executable("genversion") {
102 sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ]
103 configs -= [ "//build/config/compiler:chromium_code" ]
104 configs += [ ":yasm_config",
105 "//build/config/compiler:no_chromium_code" ]
110 "source/patched-yasm/tools/re2c/main.c",
111 "source/patched-yasm/tools/re2c/code.c",
112 "source/patched-yasm/tools/re2c/dfa.c",
113 "source/patched-yasm/tools/re2c/parser.c",
114 "source/patched-yasm/tools/re2c/actions.c",
115 "source/patched-yasm/tools/re2c/scanner.c",
116 "source/patched-yasm/tools/re2c/mbo_getopt.c",
117 "source/patched-yasm/tools/re2c/substr.c",
118 "source/patched-yasm/tools/re2c/translate.c",
121 configs -= [ "//build/config/compiler:chromium_code" ]
122 configs += [ ":yasm_config",
123 "//build/config/compiler:no_chromium_code" ]
125 # re2c is missing CLOSEVOP from one switch.
127 cflags = [ "-Wno-switch" ]
129 cflags = [ "/wd4267" ] # size_t to int conversion.
135 "source/patched-yasm/frontends/yasm/yasm-options.c",
136 "source/patched-yasm/frontends/yasm/yasm.c",
137 "source/patched-yasm/libyasm/assocdat.c",
138 "source/patched-yasm/libyasm/bc-align.c",
139 "source/patched-yasm/libyasm/bc-data.c",
140 "source/patched-yasm/libyasm/bc-incbin.c",
141 "source/patched-yasm/libyasm/bc-org.c",
142 "source/patched-yasm/libyasm/bc-reserve.c",
143 "source/patched-yasm/libyasm/bitvect.c",
144 "source/patched-yasm/libyasm/bytecode.c",
145 "source/patched-yasm/libyasm/errwarn.c",
146 "source/patched-yasm/libyasm/expr.c",
147 "source/patched-yasm/libyasm/file.c",
148 "source/patched-yasm/libyasm/floatnum.c",
149 "source/patched-yasm/libyasm/hamt.c",
150 "source/patched-yasm/libyasm/insn.c",
151 "source/patched-yasm/libyasm/intnum.c",
152 "source/patched-yasm/libyasm/inttree.c",
153 "source/patched-yasm/libyasm/linemap.c",
154 "source/patched-yasm/libyasm/md5.c",
155 "source/patched-yasm/libyasm/mergesort.c",
156 "source/patched-yasm/libyasm/section.c",
157 "source/patched-yasm/libyasm/strcasecmp.c",
158 "source/patched-yasm/libyasm/strsep.c",
159 "source/patched-yasm/libyasm/symrec.c",
160 "source/patched-yasm/libyasm/valparam.c",
161 "source/patched-yasm/libyasm/value.c",
162 "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
163 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
164 "source/patched-yasm/modules/arch/x86/x86arch.c",
165 "source/patched-yasm/modules/arch/x86/x86bc.c",
166 "source/patched-yasm/modules/arch/x86/x86expr.c",
167 "source/patched-yasm/modules/arch/x86/x86id.c",
168 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
169 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
170 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
171 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
172 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
173 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
174 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
175 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
176 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
177 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
178 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
179 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
180 "source/patched-yasm/modules/objfmts/coff/win64-except.c",
181 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
182 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
183 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
184 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
185 "source/patched-yasm/modules/objfmts/elf/elf.c",
186 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
187 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
188 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
189 "source/patched-yasm/modules/parsers/gas/gas-parse.c",
190 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
191 "source/patched-yasm/modules/parsers/gas/gas-parser.c",
192 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
193 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
194 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
195 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
196 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
197 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
198 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
199 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
201 # Files generated by compile_gperf
202 "$target_gen_dir/x86cpu.c",
203 "$target_gen_dir/x86regtmod.c",
205 # Files generated by compile_re2c
206 "$target_gen_dir/gas-token.c",
207 "$target_gen_dir/nasm-token.c",
209 # File generated by compile_re2c_lc3b
210 "$target_gen_dir/lc3bid.c",
212 # File generated by generate_module
213 "$target_gen_dir/module.c"
216 configs -= [ "//build/config/compiler:chromium_code" ]
217 configs += [ ":yasm_config",
218 "//build/config/compiler:no_chromium_code" ]
220 # Yasm generates a bunch of .c files which its source file #include.
221 # Add the |target_gen_dir| into the include path so it can find them.
222 # Ideally, these generated .c files would be placed into a separate
223 # directory, but the gen_x86_insn.py script does not make this easy.
224 include_dirs = [ yasm_gen_include_dir ]
227 cflags = [ "/wd4267" ] # size_t to int conversion.
229 cflags = [ "-ansi", "-pedantic" ]
231 cflags += [ "-Wno-incompatible-pointer-types" ]
235 # TODO(ajwong): This should take most of the generated output as
239 ":compile_gperf_for_include",
240 ":compile_nasm_macros",
241 ":compile_nasm_version",
242 ":compile_re2c_lc3b",
243 ":compile_win64_gas",
244 ":compile_win64_nasm",
253 compiled_action_foreach("compile_gperf") {
256 "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
257 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
260 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
263 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
270 # This differs from |compile_gperf| in where it places it output files.
271 compiled_action_foreach("compile_gperf_for_include") {
274 # Make sure the generated gperf files in $target_gen_dir are synced with
275 # the outputs for the related generate_*_insn actions in the
276 # generate_files target below.
278 # The output for these two are #included by
279 # source/patched-yasm/modules/arch/x86/x86id.c
280 "$yasm_gen_include_dir/x86insn_gas.gperf",
281 "$yasm_gen_include_dir/x86insn_nasm.gperf",
284 outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ]
287 rebase_path(yasm_gen_include_dir, root_build_dir) +
288 "/{{source_name_part}}.c",
295 template("compile_macro") {
296 compiled_action(target_name) {
298 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
299 inputs = invoker.sources
300 outputs = invoker.outputs
302 rebase_path(outputs[0], root_build_dir),
303 invoker.macro_varname,
304 rebase_path(inputs[0], root_build_dir),
306 if (defined(invoker.deps)) {
312 compile_macro("compile_nasm_macros") {
313 # Output #included by
314 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
315 sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ]
316 outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ]
317 macro_varname = "nasm_standard_mac"
320 compile_macro("compile_nasm_version") {
321 # Output #included by
322 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
323 sources = [ "$target_gen_dir/$version_file" ]
324 outputs = [ "$yasm_gen_include_dir/nasm-version.c" ]
325 macro_varname = "nasm_version_mac"
326 deps = [ ":generate_version" ]
329 compile_macro("compile_win64_gas") {
330 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
331 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ]
332 outputs = [ "$yasm_gen_include_dir/win64-gas.c" ]
333 macro_varname = "win64_gas_stdmac"
336 compile_macro("compile_win64_nasm") {
337 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
338 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ]
339 outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ]
340 macro_varname = "win64_nasm_stdmac"
343 compiled_action_foreach("compile_re2c") {
346 "source/patched-yasm/modules/parsers/gas/gas-token.re",
347 "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
349 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
353 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
358 # This call doesn't fit into the re2c template above.
359 compiled_action("compile_re2c_lc3b") {
361 inputs = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ]
362 outputs = [ "$target_gen_dir/lc3bid.c" ]
366 rebase_path(outputs[0], root_build_dir),
367 rebase_path(inputs[0], root_build_dir),
371 compiled_action("generate_license") {
373 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
374 inputs = [ "source/patched-yasm/COPYING" ]
375 outputs = [ "$yasm_gen_include_dir/license.c" ]
378 rebase_path(outputs[0], root_build_dir),
379 rebase_path(inputs[0], root_build_dir),
383 compiled_action("generate_module") {
386 "source/patched-yasm/libyasm/module.in",
389 outputs = [ "$target_gen_dir/module.c" ]
391 rebase_path(inputs[0], root_build_dir),
392 rebase_path(config_makefile, root_build_dir),
393 rebase_path(outputs[0], root_build_dir),
397 compiled_action("generate_version") {
399 outputs = [ "$target_gen_dir/$version_file" ]
401 rebase_path(outputs[0],
406 action("generate_x86_insn") {
407 script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
408 # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
410 "$yasm_gen_include_dir/x86insns.c",
411 "$yasm_gen_include_dir/x86insn_gas.gperf",
412 "$yasm_gen_include_dir/x86insn_nasm.gperf",
414 args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]