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",
60 executable("genmodule") {
62 "source/patched-yasm/libyasm/genmodule.c",
64 configs -= [ "//build/config/compiler:chromium_code" ]
67 "//build/config/compiler:no_chromium_code",
71 executable("genperf") {
73 "source/patched-yasm/tools/genperf/genperf.c",
74 "source/patched-yasm/tools/genperf/perfect.c",
77 configs -= [ "//build/config/compiler:chromium_code" ]
80 "//build/config/compiler:no_chromium_code",
88 # Used by both yasm and genperf binaries.
89 source_set("yasm_utils") {
91 "source/patched-yasm/libyasm/phash.c",
92 "source/patched-yasm/libyasm/xmalloc.c",
93 "source/patched-yasm/libyasm/xstrdup.c",
96 configs -= [ "//build/config/compiler:chromium_code" ]
99 "//build/config/compiler:no_chromium_code",
103 executable("genstring") {
105 "source/patched-yasm/genstring.c",
107 configs -= [ "//build/config/compiler:chromium_code" ]
110 "//build/config/compiler:no_chromium_code",
114 executable("genversion") {
116 "source/patched-yasm/modules/preprocs/nasm/genversion.c",
118 configs -= [ "//build/config/compiler:chromium_code" ]
121 "//build/config/compiler:no_chromium_code",
127 "source/patched-yasm/tools/re2c/actions.c",
128 "source/patched-yasm/tools/re2c/code.c",
129 "source/patched-yasm/tools/re2c/dfa.c",
130 "source/patched-yasm/tools/re2c/main.c",
131 "source/patched-yasm/tools/re2c/mbo_getopt.c",
132 "source/patched-yasm/tools/re2c/parser.c",
133 "source/patched-yasm/tools/re2c/scanner.c",
134 "source/patched-yasm/tools/re2c/substr.c",
135 "source/patched-yasm/tools/re2c/translate.c",
138 configs -= [ "//build/config/compiler:chromium_code" ]
141 "//build/config/compiler:no_chromium_code",
144 # re2c is missing CLOSEVOP from one switch.
146 cflags = [ "-Wno-switch" ]
152 "source/patched-yasm/frontends/yasm/yasm-options.c",
153 "source/patched-yasm/frontends/yasm/yasm.c",
154 "source/patched-yasm/libyasm/assocdat.c",
155 "source/patched-yasm/libyasm/bc-align.c",
156 "source/patched-yasm/libyasm/bc-data.c",
157 "source/patched-yasm/libyasm/bc-incbin.c",
158 "source/patched-yasm/libyasm/bc-org.c",
159 "source/patched-yasm/libyasm/bc-reserve.c",
160 "source/patched-yasm/libyasm/bitvect.c",
161 "source/patched-yasm/libyasm/bytecode.c",
162 "source/patched-yasm/libyasm/errwarn.c",
163 "source/patched-yasm/libyasm/expr.c",
164 "source/patched-yasm/libyasm/file.c",
165 "source/patched-yasm/libyasm/floatnum.c",
166 "source/patched-yasm/libyasm/hamt.c",
167 "source/patched-yasm/libyasm/insn.c",
168 "source/patched-yasm/libyasm/intnum.c",
169 "source/patched-yasm/libyasm/inttree.c",
170 "source/patched-yasm/libyasm/linemap.c",
171 "source/patched-yasm/libyasm/md5.c",
172 "source/patched-yasm/libyasm/mergesort.c",
173 "source/patched-yasm/libyasm/section.c",
174 "source/patched-yasm/libyasm/strcasecmp.c",
175 "source/patched-yasm/libyasm/strsep.c",
176 "source/patched-yasm/libyasm/symrec.c",
177 "source/patched-yasm/libyasm/valparam.c",
178 "source/patched-yasm/libyasm/value.c",
179 "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
180 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
181 "source/patched-yasm/modules/arch/x86/x86arch.c",
182 "source/patched-yasm/modules/arch/x86/x86bc.c",
183 "source/patched-yasm/modules/arch/x86/x86expr.c",
184 "source/patched-yasm/modules/arch/x86/x86id.c",
185 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
186 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
187 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
188 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
189 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
190 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
191 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
192 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
193 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
194 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
195 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
196 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
197 "source/patched-yasm/modules/objfmts/coff/win64-except.c",
198 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
199 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
200 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
201 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
202 "source/patched-yasm/modules/objfmts/elf/elf.c",
203 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
204 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
205 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
206 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
207 "source/patched-yasm/modules/parsers/gas/gas-parse.c",
208 "source/patched-yasm/modules/parsers/gas/gas-parser.c",
209 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
210 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
211 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
212 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
213 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
214 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
215 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
216 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
218 # Files generated by compile_gperf
219 "$target_gen_dir/x86cpu.c",
220 "$target_gen_dir/x86regtmod.c",
222 # Files generated by compile_re2c
223 "$target_gen_dir/gas-token.c",
224 "$target_gen_dir/nasm-token.c",
226 # File generated by compile_re2c_lc3b
227 "$target_gen_dir/lc3bid.c",
229 # File generated by generate_module
230 "$target_gen_dir/module.c",
233 configs -= [ "//build/config/compiler:chromium_code" ]
236 "//build/config/compiler:no_chromium_code",
239 # Yasm generates a bunch of .c files which its source file #include.
240 # Add the |target_gen_dir| into the include path so it can find them.
241 # Ideally, these generated .c files would be placed into a separate
242 # directory, but the gen_x86_insn.py script does not make this easy.
243 include_dirs = [ yasm_gen_include_dir ]
251 cflags += [ "-Wno-incompatible-pointer-types" ]
255 # TODO(ajwong): This should take most of the generated output as
259 ":compile_gperf_for_include",
260 ":compile_nasm_macros",
261 ":compile_nasm_version",
262 ":compile_re2c_lc3b",
263 ":compile_win64_gas",
264 ":compile_win64_nasm",
273 compiled_action_foreach("compile_gperf") {
276 "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
277 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
281 "$target_gen_dir/{{source_name_part}}.c",
285 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
288 ":generate_x86_insn",
292 # This differs from |compile_gperf| in where it places it output files.
293 compiled_action_foreach("compile_gperf_for_include") {
296 # Make sure the generated gperf files in $target_gen_dir are synced with
297 # the outputs for the related generate_*_insn actions in the
298 # generate_files target below.
300 # The output for these two are #included by
301 # source/patched-yasm/modules/arch/x86/x86id.c
302 "$yasm_gen_include_dir/x86insn_gas.gperf",
303 "$yasm_gen_include_dir/x86insn_nasm.gperf",
307 "$yasm_gen_include_dir/{{source_name_part}}.c",
311 rebase_path(yasm_gen_include_dir, root_build_dir) +
312 "/{{source_name_part}}.c",
315 ":generate_x86_insn",
319 template("compile_macro") {
320 compiled_action(target_name) {
323 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
324 inputs = invoker.sources
325 outputs = invoker.outputs
327 rebase_path(outputs[0], root_build_dir),
328 invoker.macro_varname,
329 rebase_path(inputs[0], root_build_dir),
331 if (defined(invoker.deps)) {
337 compile_macro("compile_nasm_macros") {
338 # Output #included by
339 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
341 "source/patched-yasm/modules/parsers/nasm/nasm-std.mac",
344 "$yasm_gen_include_dir/nasm-macros.c",
346 macro_varname = "nasm_standard_mac"
349 compile_macro("compile_nasm_version") {
350 # Output #included by
351 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
353 "$target_gen_dir/$version_file",
356 "$yasm_gen_include_dir/nasm-version.c",
358 macro_varname = "nasm_version_mac"
364 compile_macro("compile_win64_gas") {
365 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
367 "source/patched-yasm/modules/objfmts/coff/win64-gas.mac",
370 "$yasm_gen_include_dir/win64-gas.c",
372 macro_varname = "win64_gas_stdmac"
375 compile_macro("compile_win64_nasm") {
376 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
378 "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac",
381 "$yasm_gen_include_dir/win64-nasm.c",
383 macro_varname = "win64_nasm_stdmac"
386 compiled_action_foreach("compile_re2c") {
389 "source/patched-yasm/modules/parsers/gas/gas-token.re",
390 "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
393 "$target_gen_dir/{{source_name_part}}.c",
398 rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
403 # This call doesn't fit into the re2c template above.
404 compiled_action("compile_re2c_lc3b") {
407 "source/patched-yasm/modules/arch/lc3b/lc3bid.re",
410 "$target_gen_dir/lc3bid.c",
415 rebase_path(outputs[0], root_build_dir),
416 rebase_path(inputs[0], root_build_dir),
420 compiled_action("generate_license") {
423 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
425 "source/patched-yasm/COPYING",
428 "$yasm_gen_include_dir/license.c",
432 rebase_path(outputs[0], root_build_dir),
433 rebase_path(inputs[0], root_build_dir),
437 compiled_action("generate_module") {
440 "source/patched-yasm/libyasm/module.in",
444 "$target_gen_dir/module.c",
447 rebase_path(inputs[0], root_build_dir),
448 rebase_path(config_makefile, root_build_dir),
449 rebase_path(outputs[0], root_build_dir),
453 compiled_action("generate_version") {
456 "$target_gen_dir/$version_file",
458 args = [ rebase_path(outputs[0], root_build_dir) ]
461 action("generate_x86_insn") {
462 script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
464 # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
466 "$yasm_gen_include_dir/x86insns.c",
467 "$yasm_gen_include_dir/x86insn_gas.gperf",
468 "$yasm_gen_include_dir/x86insn_nasm.gperf",
470 args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]