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"
34 config_makefile = "source/config/$os/Makefile"
35 version_file = "version.mac"
37 import("//build/compiled_action.gni")
39 config("yasm_config") {
42 "source/patched-yasm",
46 "source/config/$os/config.h",
47 "source/config/$os/libyasm-stdint.h",
49 defines = [ "HAVE_CONFIG_H" ]
51 cflags = [ "-std=gnu99" ]
55 executable("genmacro") {
56 sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ]
57 configs -= [ "//build/config/compiler:chromium_code" ]
58 configs += [ ":yasm_config",
59 "//build/config/compiler:no_chromium_code" ]
62 executable("genmodule") {
63 sources = [ "source/patched-yasm/libyasm/genmodule.c" ]
64 configs -= [ "//build/config/compiler:chromium_code" ]
65 configs += [ ":yasm_config",
66 "//build/config/compiler:no_chromium_code" ]
69 executable("genperf") {
71 "source/patched-yasm/tools/genperf/genperf.c",
72 "source/patched-yasm/tools/genperf/perfect.c",
75 configs -= [ "//build/config/compiler:chromium_code" ]
76 configs += [ ":yasm_config",
77 "//build/config/compiler:no_chromium_code" ]
79 deps = [ ":yasm_utils" ]
82 # Used by both yasm and genperf binaries.
83 source_set("yasm_utils") {
85 "source/patched-yasm/libyasm/phash.c",
86 "source/patched-yasm/libyasm/xmalloc.c",
87 "source/patched-yasm/libyasm/xstrdup.c",
90 configs -= [ "//build/config/compiler:chromium_code" ]
91 configs += [ ":yasm_config",
92 "//build/config/compiler:no_chromium_code" ]
95 executable("genstring") {
96 sources = [ "source/patched-yasm/genstring.c", ]
97 configs -= [ "//build/config/compiler:chromium_code" ]
98 configs += [ ":yasm_config",
99 "//build/config/compiler:no_chromium_code" ]
102 executable("genversion") {
103 sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ]
104 configs -= [ "//build/config/compiler:chromium_code" ]
105 configs += [ ":yasm_config",
106 "//build/config/compiler:no_chromium_code" ]
111 "source/patched-yasm/tools/re2c/main.c",
112 "source/patched-yasm/tools/re2c/code.c",
113 "source/patched-yasm/tools/re2c/dfa.c",
114 "source/patched-yasm/tools/re2c/parser.c",
115 "source/patched-yasm/tools/re2c/actions.c",
116 "source/patched-yasm/tools/re2c/scanner.c",
117 "source/patched-yasm/tools/re2c/mbo_getopt.c",
118 "source/patched-yasm/tools/re2c/substr.c",
119 "source/patched-yasm/tools/re2c/translate.c",
122 configs -= [ "//build/config/compiler:chromium_code" ]
123 configs += [ ":yasm_config",
124 "//build/config/compiler:no_chromium_code" ]
126 # re2c is missing CLOSEVOP from one switch.
128 cflags = [ "-Wno-switch" ]
134 "source/patched-yasm/frontends/yasm/yasm-options.c",
135 "source/patched-yasm/frontends/yasm/yasm.c",
136 "source/patched-yasm/libyasm/assocdat.c",
137 "source/patched-yasm/libyasm/bc-align.c",
138 "source/patched-yasm/libyasm/bc-data.c",
139 "source/patched-yasm/libyasm/bc-incbin.c",
140 "source/patched-yasm/libyasm/bc-org.c",
141 "source/patched-yasm/libyasm/bc-reserve.c",
142 "source/patched-yasm/libyasm/bitvect.c",
143 "source/patched-yasm/libyasm/bytecode.c",
144 "source/patched-yasm/libyasm/errwarn.c",
145 "source/patched-yasm/libyasm/expr.c",
146 "source/patched-yasm/libyasm/file.c",
147 "source/patched-yasm/libyasm/floatnum.c",
148 "source/patched-yasm/libyasm/hamt.c",
149 "source/patched-yasm/libyasm/insn.c",
150 "source/patched-yasm/libyasm/intnum.c",
151 "source/patched-yasm/libyasm/inttree.c",
152 "source/patched-yasm/libyasm/linemap.c",
153 "source/patched-yasm/libyasm/md5.c",
154 "source/patched-yasm/libyasm/mergesort.c",
155 "source/patched-yasm/libyasm/section.c",
156 "source/patched-yasm/libyasm/strcasecmp.c",
157 "source/patched-yasm/libyasm/strsep.c",
158 "source/patched-yasm/libyasm/symrec.c",
159 "source/patched-yasm/libyasm/valparam.c",
160 "source/patched-yasm/libyasm/value.c",
161 "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
162 "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
163 "source/patched-yasm/modules/arch/x86/x86arch.c",
164 "source/patched-yasm/modules/arch/x86/x86bc.c",
165 "source/patched-yasm/modules/arch/x86/x86expr.c",
166 "source/patched-yasm/modules/arch/x86/x86id.c",
167 "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
168 "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
169 "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
170 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
171 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
172 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
173 "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
174 "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
175 "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
176 "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
177 "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
178 "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
179 "source/patched-yasm/modules/objfmts/coff/win64-except.c",
180 "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
181 "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
182 "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
183 "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
184 "source/patched-yasm/modules/objfmts/elf/elf.c",
185 "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
186 "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
187 "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
188 "source/patched-yasm/modules/parsers/gas/gas-parse.c",
189 "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
190 "source/patched-yasm/modules/parsers/gas/gas-parser.c",
191 "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
192 "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
193 "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
194 "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
195 "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
196 "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
197 "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
198 "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
200 # Files generated by compile_gperf
201 "$target_gen_dir/x86cpu.c",
202 "$target_gen_dir/x86regtmod.c",
204 # Files generated by compile_re2c
205 "$target_gen_dir/gas-token.c",
206 "$target_gen_dir/nasm-token.c",
208 # File generated by compile_re2c_lc3b
209 "$target_gen_dir/lc3bid.c",
211 # File generated by generate_module
212 "$target_gen_dir/module.c"
215 configs -= [ "//build/config/compiler:chromium_code" ]
216 configs += [ ":yasm_config",
217 "//build/config/compiler:no_chromium_code" ]
219 # Yasm generates a bunch of .c files which its source file #include.
220 # Add the |target_gen_dir| into the include path so it can find them.
221 # Ideally, these generated .c files would be placed into a separate
222 # directory, but the gen_x86_insn.py script does not make this easy.
223 include_dirs = [ yasm_gen_include_dir ]
226 cflags = [ "/wd4267" ] # size_t to int conversion.
228 cflags = [ "-ansi", "-pedantic" ]
230 cflags += [ "-Wno-incompatible-pointer-types" ]
234 # TODO(ajwong): This should take most of the generated output as
238 ":compile_gperf_for_include",
239 ":compile_nasm_macros",
240 ":compile_nasm_version",
241 ":compile_re2c_lc3b",
242 ":compile_win64_gas",
243 ":compile_win64_nasm",
252 compiled_action_foreach("compile_gperf") {
255 "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
256 "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
259 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
262 rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
269 # This differs from |compile_gperf| in where it places it output files.
270 compiled_action_foreach("compile_gperf_for_include") {
273 # Make sure the generated gperf files in $target_gen_dir are synced with
274 # the outputs for the related generate_*_insn actions in the
275 # generate_files target below.
277 # The output for these two are #included by
278 # source/patched-yasm/modules/arch/x86/x86id.c
279 "$yasm_gen_include_dir/x86insn_gas.gperf",
280 "$yasm_gen_include_dir/x86insn_nasm.gperf",
283 outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ]
286 rebase_path(yasm_gen_include_dir, ".") + "/{{source_name_part}}.c",
293 template("compile_macro") {
294 compiled_action(target_name) {
296 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
297 sources = invoker.sources
298 outputs = invoker.outputs
300 rebase_path(outputs[0], root_build_dir),
301 invoker.macro_varname,
302 rebase_path(sources[0], root_build_dir),
304 if (defined(invoker.deps)) {
310 compile_macro("compile_nasm_macros") {
311 # Output #included by
312 # source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
313 sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ]
314 outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ]
315 macro_varname = "nasm_standard_mac"
318 compile_macro("compile_nasm_version") {
319 # Output #included by
320 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
321 sources = [ "$target_gen_dir/$version_file" ]
322 outputs = [ "$yasm_gen_include_dir/nasm-version.c" ]
323 macro_varname = "nasm_version_mac"
324 deps = [ ":generate_version" ]
327 compile_macro("compile_win64_gas") {
328 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
329 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ]
330 outputs = [ "$yasm_gen_include_dir/win64-gas.c" ]
331 macro_varname = "win64_gas_stdmac"
334 compile_macro("compile_win64_nasm") {
335 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
336 sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ]
337 outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ]
338 macro_varname = "win64_nasm_stdmac"
341 compiled_action_foreach("compile_re2c") {
344 "source/patched-yasm/modules/parsers/gas/gas-token.re",
345 "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
347 outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
351 rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
356 # This call doesn't fit into the re2c template above.
357 compiled_action("compile_re2c_lc3b") {
359 sources = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ]
360 outputs = [ "$target_gen_dir/lc3bid.c" ]
364 rebase_path(outputs[0], root_build_dir),
365 rebase_path(sources[0], root_build_dir),
369 compiled_action("generate_license") {
371 # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
372 sources = [ "source/patched-yasm/COPYING" ]
373 outputs = [ "$yasm_gen_include_dir/license.c" ]
376 rebase_path(outputs[0], root_build_dir),
377 rebase_path(sources[0], root_build_dir),
381 compiled_action("generate_module") {
383 sources = [ "source/patched-yasm/libyasm/module.in" ]
384 outputs = [ "$target_gen_dir/module.c" ]
386 rebase_path(sources[0], root_build_dir),
387 rebase_path(config_makefile, root_build_dir),
388 rebase_path(outputs[0], root_build_dir),
392 compiled_action("generate_version") {
394 outputs = [ "$target_gen_dir/$version_file" ]
396 rebase_path(outputs[0],
401 action("generate_x86_insn") {
402 script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
403 # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
405 "$yasm_gen_include_dir/x86insns.c",
406 "$yasm_gen_include_dir/x86insn_gas.gperf",
407 "$yasm_gen_include_dir/x86insn_nasm.gperf",
409 args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]