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) {
31 # Various files referenced by multiple targets.
32 yasm_gen_include_dir = "$target_gen_dir/include"
33 config_makefile = "source/config/$host_os/Makefile"
34 version_file = "version.mac"
36 import("//build/compiled_action.gni")
38 config("yasm_config") {
40 "source/config/$host_os",
41 "source/patched-yasm",
43 defines = [ "HAVE_CONFIG_H" ]
45 cflags = [ "-std=gnu99" ]
49 executable("genmacro") {
51 "source/patched-yasm/tools/genmacro/genmacro.c",
53 configs -= [ "//build/config/compiler:chromium_code" ]
56 "//build/config/compiler:no_chromium_code",
59 "//build/config/sanitizers:deps",
63 executable("genmodule") {
65 "source/patched-yasm/libyasm/genmodule.c",
67 configs -= [ "//build/config/compiler:chromium_code" ]
70 "//build/config/compiler:no_chromium_code",
73 "//build/config/sanitizers:deps",
77 executable("genperf") {
79 "source/patched-yasm/tools/genperf/genperf.c",
80 "source/patched-yasm/tools/genperf/perfect.c",
83 configs -= [ "//build/config/compiler:chromium_code" ]
86 "//build/config/compiler:no_chromium_code",
91 "//build/config/sanitizers:deps",
95 # Used by both yasm and genperf binaries.
96 source_set("yasm_utils") {
98 "source/patched-yasm/libyasm/phash.c",
99 "source/patched-yasm/libyasm/xmalloc.c",
100 "source/patched-yasm/libyasm/xstrdup.c",
103 configs -= [ "//build/config/compiler:chromium_code" ]
106 "//build/config/compiler:no_chromium_code",
110 executable("genstring") {
112 "source/patched-yasm/genstring.c",
114 configs -= [ "//build/config/compiler:chromium_code" ]
117 "//build/config/compiler:no_chromium_code",
120 "//build/config/sanitizers:deps",
124 executable("genversion") {
126 "source/patched-yasm/modules/preprocs/nasm/genversion.c",
128 configs -= [ "//build/config/compiler:chromium_code" ]
131 "//build/config/compiler:no_chromium_code",
134 "//build/config/sanitizers:deps",
138 config("re2c_warnings") {
139 # re2c is missing CLOSEVOP from one switch.
142 # re2c is missing CLOSEVOP from one switch.
145 # re2c contains many static functions in headers (because it's
146 # a C library predating C99.)
147 "-Wno-unused-function",
154 "source/patched-yasm/tools/re2c/actions.c",
155 "source/patched-yasm/tools/re2c/code.c",
156 "source/patched-yasm/tools/re2c/dfa.c",
157 "source/patched-yasm/tools/re2c/main.c",
158 "source/patched-yasm/tools/re2c/mbo_getopt.c",
159 "source/patched-yasm/tools/re2c/parser.c",
160 "source/patched-yasm/tools/re2c/scanner.c",
161 "source/patched-yasm/tools/re2c/substr.c",
162 "source/patched-yasm/tools/re2c/translate.c",
165 configs -= [ "//build/config/compiler:chromium_code" ]
169 "//build/config/compiler:no_chromium_code",
172 "//build/config/sanitizers:deps",
176 config("yasm_warnings") {
179 # reg3264type in x86expr.c is unused.
180 "-Wno-unused-local-typedef",
187 "source/patched-yasm/frontends/yasm/yasm-options.c",
188 "source/patched-yasm/frontends/yasm/yasm.c",
189 "source/patched-yasm/libyasm/assocdat.c",
190 "source/patched-yasm/libyasm/bc-align.c",
191 "source/patched-yasm/libyasm/bc-data.c",
192 "source/patched-yasm/libyasm/bc-incbin.c",
193 "source/patched-yasm/libyasm/bc-org.c",
194 "source/patched-yasm/libyasm/bc-reserve.c",
195 "source/patched-yasm/libyasm/bitvect.c",
196 "source/patched-yasm/libyasm/bytecode.c",
197 "source/patched-yasm/libyasm/errwarn.c",
198 "source/patched-yasm/libyasm/expr.c",
199 "source/patched-yasm/libyasm/file.c",
200 "source/patched-yasm/libyasm/floatnum.c",
201 "source/patched-yasm/libyasm/hamt.c",
202 "source/patched-yasm/libyasm/insn.c",
203 "source/patched-yasm/libyasm/intnum.c",
204 "source/patched-yasm/libyasm/inttree.c",
205 "source/patched-yasm/libyasm/linemap.c",
206 "source/patched-yasm/libyasm/md5.c",
207 "source/patched-yasm/libyasm/mergesort.c",
208 "source/patched-yasm/libyasm/section.c",
209 "source/patched-yasm/libyasm/strcasecmp.c",
210 "source/patched-yasm/libyasm/strsep.c",
211 "source/patched-yasm/libyasm/symrec.c",
212 "source/patched-yasm/libyasm/valparam.c",
213 "source/patched-yasm/libyasm/value.c",
214 "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
215 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
216 "source/patched-yasm/modules/arch/x86/x86arch.c",
217 "source/patched-yasm/modules/arch/x86/x86bc.c",
218 "source/patched-yasm/modules/arch/x86/x86expr.c",
219 "source/patched-yasm/modules/arch/x86/x86id.c",
220 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
221 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
222 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
223 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
224 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
225 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
226 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
227 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
228 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
229 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
230 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
231 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
232 "source/patched-yasm/modules/objfmts/coff/win64-except.c",
233 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
234 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
235 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
236 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
237 "source/patched-yasm/modules/objfmts/elf/elf.c",
238 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
239 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
240 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
241 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
242 "source/patched-yasm/modules/parsers/gas/gas-parse.c",
243 "source/patched-yasm/modules/parsers/gas/gas-parser.c",
244 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
245 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
246 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
247 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
248 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
249 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
250 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
251 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
253 # Files generated by compile_gperf
254 "$target_gen_dir/x86cpu.c",
255 "$target_gen_dir/x86regtmod.c",
257 # Files generated by compile_re2c
258 "$target_gen_dir/gas-token.c",
259 "$target_gen_dir/nasm-token.c",
261 # File generated by compile_re2c_lc3b
262 "$target_gen_dir/lc3bid.c",
264 # File generated by generate_module
265 "$target_gen_dir/module.c",
268 configs -= [ "//build/config/compiler:chromium_code" ]
272 "//build/config/compiler:no_chromium_code",
273 "//build/config/compiler:no_incompatible_pointer_warnings",
276 # Yasm generates a bunch of .c files which its source file #include.
277 # Add the |target_gen_dir| into the include path so it can find them.
278 # Ideally, these generated .c files would be placed into a separate
279 # directory, but the gen_x86_insn.py script does not make this easy.
280 include_dirs = [ yasm_gen_include_dir ]
289 # TODO(ajwong): This should take most of the generated output as
293 ":compile_gperf_for_include",
294 ":compile_nasm_macros",
295 ":compile_nasm_version",
296 ":compile_re2c_lc3b",
297 ":compile_win64_gas",
298 ":compile_win64_nasm",
304 "//build/config/sanitizers:deps",
308 compiled_action_foreach("compile_gperf") {
311 "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
312 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
316 "$target_gen_dir/{{source_name_part}}.c",
320 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
323 ":generate_x86_insn",
327 # This differs from |compile_gperf| in where it places it output files.
328 compiled_action_foreach("compile_gperf_for_include") {
331 # Make sure the generated gperf files in $target_gen_dir are synced with
332 # the outputs for the related generate_*_insn actions in the
333 # generate_files target below.
335 # The output for these two are #included by
336 # source/patched-yasm/modules/arch/x86/x86id.c
337 "$yasm_gen_include_dir/x86insn_gas.gperf",
338 "$yasm_gen_include_dir/x86insn_nasm.gperf",
342 "$yasm_gen_include_dir/{{source_name_part}}.c",
346 rebase_path(yasm_gen_include_dir, root_build_dir) +
347 "/{{source_name_part}}.c",
350 ":generate_x86_insn",
354 template("compile_macro") {
355 compiled_action(target_name) {
358 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
359 inputs = invoker.sources
360 outputs = invoker.outputs
362 rebase_path(outputs[0], root_build_dir),
363 invoker.macro_varname,
364 rebase_path(inputs[0], root_build_dir),
366 if (defined(invoker.deps)) {
372 compile_macro("compile_nasm_macros") {
373 # Output #included by
374 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
376 "source/patched-yasm/modules/parsers/nasm/nasm-std.mac",
379 "$yasm_gen_include_dir/nasm-macros.c",
381 macro_varname = "nasm_standard_mac"
384 compile_macro("compile_nasm_version") {
385 # Output #included by
386 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
388 "$target_gen_dir/$version_file",
391 "$yasm_gen_include_dir/nasm-version.c",
393 macro_varname = "nasm_version_mac"
399 compile_macro("compile_win64_gas") {
400 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
402 "source/patched-yasm/modules/objfmts/coff/win64-gas.mac",
405 "$yasm_gen_include_dir/win64-gas.c",
407 macro_varname = "win64_gas_stdmac"
410 compile_macro("compile_win64_nasm") {
411 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
413 "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac",
416 "$yasm_gen_include_dir/win64-nasm.c",
418 macro_varname = "win64_nasm_stdmac"
421 compiled_action_foreach("compile_re2c") {
424 "source/patched-yasm/modules/parsers/gas/gas-token.re",
425 "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
428 "$target_gen_dir/{{source_name_part}}.c",
433 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
438 # This call doesn't fit into the re2c template above.
439 compiled_action("compile_re2c_lc3b") {
442 "source/patched-yasm/modules/arch/lc3b/lc3bid.re",
445 "$target_gen_dir/lc3bid.c",
450 rebase_path(outputs[0], root_build_dir),
451 rebase_path(inputs[0], root_build_dir),
455 compiled_action("generate_license") {
458 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
460 "source/patched-yasm/COPYING",
463 "$yasm_gen_include_dir/license.c",
467 rebase_path(outputs[0], root_build_dir),
468 rebase_path(inputs[0], root_build_dir),
472 compiled_action("generate_module") {
475 "source/patched-yasm/libyasm/module.in",
479 "$target_gen_dir/module.c",
482 rebase_path(inputs[0], root_build_dir),
483 rebase_path(config_makefile, root_build_dir),
484 rebase_path(outputs[0], root_build_dir),
488 compiled_action("generate_version") {
491 "$target_gen_dir/$version_file",
493 args = [ rebase_path(outputs[0], root_build_dir) ]
496 action("generate_x86_insn") {
497 script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
499 # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
501 "$yasm_gen_include_dir/x86insns.c",
502 "$yasm_gen_include_dir/x86insn_gas.gperf",
503 "$yasm_gen_include_dir/x86insn_nasm.gperf",
505 args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]