Reland: Move more tests from ChromeShellTest to ChromePublicTest
[chromium-blink-merge.git] / third_party / yasm / BUILD.gn
blob23e160e14b19f70eaee268c67b557b58bf1befac
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") {
39     include_dirs = [
40       "source/config/$host_os",
41       "source/patched-yasm",
42     ]
43     defines = [ "HAVE_CONFIG_H" ]
44     if (is_posix) {
45       cflags = [ "-std=gnu99" ]
46     }
47   }
49   executable("genmacro") {
50     sources = [
51       "source/patched-yasm/tools/genmacro/genmacro.c",
52     ]
53     configs -= [ "//build/config/compiler:chromium_code" ]
54     configs += [
55       ":yasm_config",
56       "//build/config/compiler:no_chromium_code",
57     ]
58     deps = [
59       "//build/config/sanitizers:deps",
60     ]
61   }
63   executable("genmodule") {
64     sources = [
65       "source/patched-yasm/libyasm/genmodule.c",
66     ]
67     configs -= [ "//build/config/compiler:chromium_code" ]
68     configs += [
69       ":yasm_config",
70       "//build/config/compiler:no_chromium_code",
71     ]
72     deps = [
73       "//build/config/sanitizers:deps",
74     ]
75   }
77   executable("genperf") {
78     sources = [
79       "source/patched-yasm/tools/genperf/genperf.c",
80       "source/patched-yasm/tools/genperf/perfect.c",
81     ]
83     configs -= [ "//build/config/compiler:chromium_code" ]
84     configs += [
85       ":yasm_config",
86       "//build/config/compiler:no_chromium_code",
87     ]
89     deps = [
90       ":yasm_utils",
91       "//build/config/sanitizers:deps",
92     ]
93   }
95   # Used by both yasm and genperf binaries.
96   source_set("yasm_utils") {
97     sources = [
98       "source/patched-yasm/libyasm/phash.c",
99       "source/patched-yasm/libyasm/xmalloc.c",
100       "source/patched-yasm/libyasm/xstrdup.c",
101     ]
103     configs -= [ "//build/config/compiler:chromium_code" ]
104     configs += [
105       ":yasm_config",
106       "//build/config/compiler:no_chromium_code",
107     ]
108   }
110   executable("genstring") {
111     sources = [
112       "source/patched-yasm/genstring.c",
113     ]
114     configs -= [ "//build/config/compiler:chromium_code" ]
115     configs += [
116       ":yasm_config",
117       "//build/config/compiler:no_chromium_code",
118     ]
119     deps = [
120       "//build/config/sanitizers:deps",
121     ]
122   }
124   executable("genversion") {
125     sources = [
126       "source/patched-yasm/modules/preprocs/nasm/genversion.c",
127     ]
128     configs -= [ "//build/config/compiler:chromium_code" ]
129     configs += [
130       ":yasm_config",
131       "//build/config/compiler:no_chromium_code",
132     ]
133     deps = [
134       "//build/config/sanitizers:deps",
135     ]
136   }
138   executable("re2c") {
139     sources = [
140       "source/patched-yasm/tools/re2c/actions.c",
141       "source/patched-yasm/tools/re2c/code.c",
142       "source/patched-yasm/tools/re2c/dfa.c",
143       "source/patched-yasm/tools/re2c/main.c",
144       "source/patched-yasm/tools/re2c/mbo_getopt.c",
145       "source/patched-yasm/tools/re2c/parser.c",
146       "source/patched-yasm/tools/re2c/scanner.c",
147       "source/patched-yasm/tools/re2c/substr.c",
148       "source/patched-yasm/tools/re2c/translate.c",
149     ]
151     configs -= [ "//build/config/compiler:chromium_code" ]
152     configs += [
153       ":yasm_config",
154       "//build/config/compiler:no_chromium_code",
155     ]
157     # re2c is missing CLOSEVOP from one switch.
158     if (is_posix) {
159       cflags = [ "-Wno-switch" ]
160     }
161     deps = [
162       "//build/config/sanitizers:deps",
163     ]
164   }
166   executable("yasm") {
167     sources = [
168       "source/patched-yasm/frontends/yasm/yasm-options.c",
169       "source/patched-yasm/frontends/yasm/yasm.c",
170       "source/patched-yasm/libyasm/assocdat.c",
171       "source/patched-yasm/libyasm/bc-align.c",
172       "source/patched-yasm/libyasm/bc-data.c",
173       "source/patched-yasm/libyasm/bc-incbin.c",
174       "source/patched-yasm/libyasm/bc-org.c",
175       "source/patched-yasm/libyasm/bc-reserve.c",
176       "source/patched-yasm/libyasm/bitvect.c",
177       "source/patched-yasm/libyasm/bytecode.c",
178       "source/patched-yasm/libyasm/errwarn.c",
179       "source/patched-yasm/libyasm/expr.c",
180       "source/patched-yasm/libyasm/file.c",
181       "source/patched-yasm/libyasm/floatnum.c",
182       "source/patched-yasm/libyasm/hamt.c",
183       "source/patched-yasm/libyasm/insn.c",
184       "source/patched-yasm/libyasm/intnum.c",
185       "source/patched-yasm/libyasm/inttree.c",
186       "source/patched-yasm/libyasm/linemap.c",
187       "source/patched-yasm/libyasm/md5.c",
188       "source/patched-yasm/libyasm/mergesort.c",
189       "source/patched-yasm/libyasm/section.c",
190       "source/patched-yasm/libyasm/strcasecmp.c",
191       "source/patched-yasm/libyasm/strsep.c",
192       "source/patched-yasm/libyasm/symrec.c",
193       "source/patched-yasm/libyasm/valparam.c",
194       "source/patched-yasm/libyasm/value.c",
195       "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
196       "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
197       "source/patched-yasm/modules/arch/x86/x86arch.c",
198       "source/patched-yasm/modules/arch/x86/x86bc.c",
199       "source/patched-yasm/modules/arch/x86/x86expr.c",
200       "source/patched-yasm/modules/arch/x86/x86id.c",
201       "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
202       "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
203       "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
204       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
205       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
206       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
207       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
208       "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
209       "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
210       "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
211       "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
212       "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
213       "source/patched-yasm/modules/objfmts/coff/win64-except.c",
214       "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
215       "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
216       "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
217       "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
218       "source/patched-yasm/modules/objfmts/elf/elf.c",
219       "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
220       "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
221       "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
222       "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
223       "source/patched-yasm/modules/parsers/gas/gas-parse.c",
224       "source/patched-yasm/modules/parsers/gas/gas-parser.c",
225       "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
226       "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
227       "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
228       "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
229       "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
230       "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
231       "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
232       "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
234       # Files generated by compile_gperf
235       "$target_gen_dir/x86cpu.c",
236       "$target_gen_dir/x86regtmod.c",
238       # Files generated by compile_re2c
239       "$target_gen_dir/gas-token.c",
240       "$target_gen_dir/nasm-token.c",
242       # File generated by compile_re2c_lc3b
243       "$target_gen_dir/lc3bid.c",
245       # File generated by generate_module
246       "$target_gen_dir/module.c",
247     ]
249     configs -= [ "//build/config/compiler:chromium_code" ]
250     configs += [
251       ":yasm_config",
252       "//build/config/compiler:no_chromium_code",
253       "//build/config/compiler:no_incompatible_pointer_warnings",
254     ]
256     config("yasm_warnings") {
257       if (is_clang) {
258         cflags = [
259           # reg3264type in x86expr.c is unused.
260           "-Wno-unused-local-typedef",
261         ]
262       }
263     }
264     configs += [ ":yasm_warnings" ]
266     # Yasm generates a bunch of .c files which its source file #include.
267     # Add the |target_gen_dir| into the include path so it can find them.
268     # Ideally, these generated .c files would be placed into a separate
269     # directory, but the gen_x86_insn.py script does not make this easy.
270     include_dirs = [ yasm_gen_include_dir ]
272     if (!is_win) {
273       cflags = [
274         "-ansi",
275         "-pedantic",
276       ]
277     }
279     # TODO(ajwong): This should take most of the generated output as
280     # inputs.
281     deps = [
282       ":compile_gperf",
283       ":compile_gperf_for_include",
284       ":compile_nasm_macros",
285       ":compile_nasm_version",
286       ":compile_re2c_lc3b",
287       ":compile_win64_gas",
288       ":compile_win64_nasm",
289       ":compile_re2c",
290       ":generate_license",
291       ":generate_module",
292       ":generate_version",
293       ":yasm_utils",
294       "//build/config/sanitizers:deps",
295     ]
296   }
298   compiled_action_foreach("compile_gperf") {
299     tool = ":genperf"
300     sources = [
301       "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
302       "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
303     ]
305     outputs = [
306       "$target_gen_dir/{{source_name_part}}.c",
307     ]
308     args = [
309       "{{source}}",
310       rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
311     ]
312     deps = [
313       ":generate_x86_insn",
314     ]
315   }
317   # This differs from |compile_gperf| in where it places it output files.
318   compiled_action_foreach("compile_gperf_for_include") {
319     tool = ":genperf"
320     sources = [
321       # Make sure the generated gperf files in $target_gen_dir are synced with
322       # the outputs for the related generate_*_insn actions in the
323       # generate_files target below.
324       #
325       # The output for these two are #included by
326       #   source/patched-yasm/modules/arch/x86/x86id.c
327       "$yasm_gen_include_dir/x86insn_gas.gperf",
328       "$yasm_gen_include_dir/x86insn_nasm.gperf",
329     ]
331     outputs = [
332       "$yasm_gen_include_dir/{{source_name_part}}.c",
333     ]
334     args = [
335       "{{source}}",
336       rebase_path(yasm_gen_include_dir, root_build_dir) +
337           "/{{source_name_part}}.c",
338     ]
339     deps = [
340       ":generate_x86_insn",
341     ]
342   }
344   template("compile_macro") {
345     compiled_action(target_name) {
346       tool = ":genmacro"
348       # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
349       inputs = invoker.sources
350       outputs = invoker.outputs
351       args = [
352         rebase_path(outputs[0], root_build_dir),
353         invoker.macro_varname,
354         rebase_path(inputs[0], root_build_dir),
355       ]
356       if (defined(invoker.deps)) {
357         deps = invoker.deps
358       }
359     }
360   }
362   compile_macro("compile_nasm_macros") {
363     # Output #included by
364     #   source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
365     sources = [
366       "source/patched-yasm/modules/parsers/nasm/nasm-std.mac",
367     ]
368     outputs = [
369       "$yasm_gen_include_dir/nasm-macros.c",
370     ]
371     macro_varname = "nasm_standard_mac"
372   }
374   compile_macro("compile_nasm_version") {
375     # Output #included by
376     #   source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
377     sources = [
378       "$target_gen_dir/$version_file",
379     ]
380     outputs = [
381       "$yasm_gen_include_dir/nasm-version.c",
382     ]
383     macro_varname = "nasm_version_mac"
384     deps = [
385       ":generate_version",
386     ]
387   }
389   compile_macro("compile_win64_gas") {
390     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
391     sources = [
392       "source/patched-yasm/modules/objfmts/coff/win64-gas.mac",
393     ]
394     outputs = [
395       "$yasm_gen_include_dir/win64-gas.c",
396     ]
397     macro_varname = "win64_gas_stdmac"
398   }
400   compile_macro("compile_win64_nasm") {
401     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
402     sources = [
403       "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac",
404     ]
405     outputs = [
406       "$yasm_gen_include_dir/win64-nasm.c",
407     ]
408     macro_varname = "win64_nasm_stdmac"
409   }
411   compiled_action_foreach("compile_re2c") {
412     tool = ":re2c"
413     sources = [
414       "source/patched-yasm/modules/parsers/gas/gas-token.re",
415       "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
416     ]
417     outputs = [
418       "$target_gen_dir/{{source_name_part}}.c",
419     ]
420     args = [
421       "-b",
422       "-o",
423       rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
424       "{{source}}",
425     ]
426   }
428   # This call doesn't fit into the re2c template above.
429   compiled_action("compile_re2c_lc3b") {
430     tool = ":re2c"
431     inputs = [
432       "source/patched-yasm/modules/arch/lc3b/lc3bid.re",
433     ]
434     outputs = [
435       "$target_gen_dir/lc3bid.c",
436     ]
437     args = [
438       "-s",
439       "-o",
440       rebase_path(outputs[0], root_build_dir),
441       rebase_path(inputs[0], root_build_dir),
442     ]
443   }
445   compiled_action("generate_license") {
446     tool = ":genstring"
448     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
449     inputs = [
450       "source/patched-yasm/COPYING",
451     ]
452     outputs = [
453       "$yasm_gen_include_dir/license.c",
454     ]
455     args = [
456       "license_msg",
457       rebase_path(outputs[0], root_build_dir),
458       rebase_path(inputs[0], root_build_dir),
459     ]
460   }
462   compiled_action("generate_module") {
463     tool = ":genmodule"
464     inputs = [
465       "source/patched-yasm/libyasm/module.in",
466       config_makefile,
467     ]
468     outputs = [
469       "$target_gen_dir/module.c",
470     ]
471     args = [
472       rebase_path(inputs[0], root_build_dir),
473       rebase_path(config_makefile, root_build_dir),
474       rebase_path(outputs[0], root_build_dir),
475     ]
476   }
478   compiled_action("generate_version") {
479     tool = ":genversion"
480     outputs = [
481       "$target_gen_dir/$version_file",
482     ]
483     args = [ rebase_path(outputs[0], root_build_dir) ]
484   }
486   action("generate_x86_insn") {
487     script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
489     # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
490     outputs = [
491       "$yasm_gen_include_dir/x86insns.c",
492       "$yasm_gen_include_dir/x86insn_gas.gperf",
493       "$yasm_gen_include_dir/x86insn_nasm.gperf",
494     ]
495     args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]
496   }