cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / third_party / yasm / BUILD.gn
blob36937b801fa8addfd026c01f4019f0c61d328f53
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   config("re2c_warnings") {
139     # re2c is missing CLOSEVOP from one switch.
140     if (is_clang) {
141       cflags = [
142         # re2c is missing CLOSEVOP from one switch.
143         "-Wno-switch",
145         # re2c contains many static functions in headers (because it's
146         # a C library predating C99.)
147         "-Wno-unused-function",
148       ]
149     }
150   }
152   executable("re2c") {
153     sources = [
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",
163     ]
165     configs -= [ "//build/config/compiler:chromium_code" ]
166     configs += [
167       ":yasm_config",
168       "//build/config/compiler:no_chromium_code",
170       # Must be after no_chromium_code for warning flags to be ordered
171       # correctly.
172       ":re2c_warnings",
173     ]
174     deps = [
175       "//build/config/sanitizers:deps",
176     ]
177   }
179   config("yasm_warnings") {
180     if (is_clang) {
181       cflags = [
182         # reg3264type in x86expr.c is unused.
183         "-Wno-unused-local-typedef",
184       ]
185     }
186   }
188   executable("yasm") {
189     sources = [
190       "source/patched-yasm/frontends/yasm/yasm-options.c",
191       "source/patched-yasm/frontends/yasm/yasm.c",
192       "source/patched-yasm/libyasm/assocdat.c",
193       "source/patched-yasm/libyasm/bc-align.c",
194       "source/patched-yasm/libyasm/bc-data.c",
195       "source/patched-yasm/libyasm/bc-incbin.c",
196       "source/patched-yasm/libyasm/bc-org.c",
197       "source/patched-yasm/libyasm/bc-reserve.c",
198       "source/patched-yasm/libyasm/bitvect.c",
199       "source/patched-yasm/libyasm/bytecode.c",
200       "source/patched-yasm/libyasm/errwarn.c",
201       "source/patched-yasm/libyasm/expr.c",
202       "source/patched-yasm/libyasm/file.c",
203       "source/patched-yasm/libyasm/floatnum.c",
204       "source/patched-yasm/libyasm/hamt.c",
205       "source/patched-yasm/libyasm/insn.c",
206       "source/patched-yasm/libyasm/intnum.c",
207       "source/patched-yasm/libyasm/inttree.c",
208       "source/patched-yasm/libyasm/linemap.c",
209       "source/patched-yasm/libyasm/md5.c",
210       "source/patched-yasm/libyasm/mergesort.c",
211       "source/patched-yasm/libyasm/section.c",
212       "source/patched-yasm/libyasm/strcasecmp.c",
213       "source/patched-yasm/libyasm/strsep.c",
214       "source/patched-yasm/libyasm/symrec.c",
215       "source/patched-yasm/libyasm/valparam.c",
216       "source/patched-yasm/libyasm/value.c",
217       "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
218       "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
219       "source/patched-yasm/modules/arch/x86/x86arch.c",
220       "source/patched-yasm/modules/arch/x86/x86bc.c",
221       "source/patched-yasm/modules/arch/x86/x86expr.c",
222       "source/patched-yasm/modules/arch/x86/x86id.c",
223       "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
224       "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
225       "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
226       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
227       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
228       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
229       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
230       "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
231       "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
232       "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
233       "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
234       "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
235       "source/patched-yasm/modules/objfmts/coff/win64-except.c",
236       "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
237       "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
238       "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
239       "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
240       "source/patched-yasm/modules/objfmts/elf/elf.c",
241       "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
242       "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
243       "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
244       "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
245       "source/patched-yasm/modules/parsers/gas/gas-parse.c",
246       "source/patched-yasm/modules/parsers/gas/gas-parser.c",
247       "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
248       "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
249       "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
250       "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
251       "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
252       "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
253       "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
254       "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
256       # Files generated by compile_gperf
257       "$target_gen_dir/x86cpu.c",
258       "$target_gen_dir/x86regtmod.c",
260       # Files generated by compile_re2c
261       "$target_gen_dir/gas-token.c",
262       "$target_gen_dir/nasm-token.c",
264       # File generated by compile_re2c_lc3b
265       "$target_gen_dir/lc3bid.c",
267       # File generated by generate_module
268       "$target_gen_dir/module.c",
269     ]
271     configs -= [ "//build/config/compiler:chromium_code" ]
272     configs += [
273       ":yasm_config",
274       "//build/config/compiler:no_chromium_code",
275       "//build/config/compiler:no_incompatible_pointer_warnings",
277       # Must be after no_chromium_code for warning flags to be ordered
278       # correctly.
279       ":yasm_warnings",
280     ]
282     # Yasm generates a bunch of .c files which its source file #include.
283     # Add the |target_gen_dir| into the include path so it can find them.
284     # Ideally, these generated .c files would be placed into a separate
285     # directory, but the gen_x86_insn.py script does not make this easy.
286     include_dirs = [ yasm_gen_include_dir ]
288     if (!is_win) {
289       cflags = [
290         "-ansi",
291         "-pedantic",
292       ]
293     }
295     # TODO(ajwong): This should take most of the generated output as
296     # inputs.
297     deps = [
298       ":compile_gperf",
299       ":compile_gperf_for_include",
300       ":compile_nasm_macros",
301       ":compile_nasm_version",
302       ":compile_re2c_lc3b",
303       ":compile_win64_gas",
304       ":compile_win64_nasm",
305       ":compile_re2c",
306       ":generate_license",
307       ":generate_module",
308       ":generate_version",
309       ":yasm_utils",
310       "//build/config/sanitizers:deps",
311     ]
312   }
314   compiled_action_foreach("compile_gperf") {
315     tool = ":genperf"
316     sources = [
317       "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
318       "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
319     ]
321     outputs = [
322       "$target_gen_dir/{{source_name_part}}.c",
323     ]
324     args = [
325       "{{source}}",
326       rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
327     ]
328     deps = [
329       ":generate_x86_insn",
330     ]
331   }
333   # This differs from |compile_gperf| in where it places it output files.
334   compiled_action_foreach("compile_gperf_for_include") {
335     tool = ":genperf"
336     sources = [
337       # Make sure the generated gperf files in $target_gen_dir are synced with
338       # the outputs for the related generate_*_insn actions in the
339       # generate_files target below.
340       #
341       # The output for these two are #included by
342       #   source/patched-yasm/modules/arch/x86/x86id.c
343       "$yasm_gen_include_dir/x86insn_gas.gperf",
344       "$yasm_gen_include_dir/x86insn_nasm.gperf",
345     ]
347     outputs = [
348       "$yasm_gen_include_dir/{{source_name_part}}.c",
349     ]
350     args = [
351       "{{source}}",
352       rebase_path(yasm_gen_include_dir, root_build_dir) +
353           "/{{source_name_part}}.c",
354     ]
355     deps = [
356       ":generate_x86_insn",
357     ]
358   }
360   template("compile_macro") {
361     compiled_action(target_name) {
362       tool = ":genmacro"
364       # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
365       inputs = invoker.sources
366       outputs = invoker.outputs
367       args = [
368         rebase_path(outputs[0], root_build_dir),
369         invoker.macro_varname,
370         rebase_path(inputs[0], root_build_dir),
371       ]
372       if (defined(invoker.deps)) {
373         deps = invoker.deps
374       }
375     }
376   }
378   compile_macro("compile_nasm_macros") {
379     # Output #included by
380     #   source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
381     sources = [
382       "source/patched-yasm/modules/parsers/nasm/nasm-std.mac",
383     ]
384     outputs = [
385       "$yasm_gen_include_dir/nasm-macros.c",
386     ]
387     macro_varname = "nasm_standard_mac"
388   }
390   compile_macro("compile_nasm_version") {
391     # Output #included by
392     #   source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
393     sources = [
394       "$target_gen_dir/$version_file",
395     ]
396     outputs = [
397       "$yasm_gen_include_dir/nasm-version.c",
398     ]
399     macro_varname = "nasm_version_mac"
400     deps = [
401       ":generate_version",
402     ]
403   }
405   compile_macro("compile_win64_gas") {
406     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
407     sources = [
408       "source/patched-yasm/modules/objfmts/coff/win64-gas.mac",
409     ]
410     outputs = [
411       "$yasm_gen_include_dir/win64-gas.c",
412     ]
413     macro_varname = "win64_gas_stdmac"
414   }
416   compile_macro("compile_win64_nasm") {
417     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
418     sources = [
419       "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac",
420     ]
421     outputs = [
422       "$yasm_gen_include_dir/win64-nasm.c",
423     ]
424     macro_varname = "win64_nasm_stdmac"
425   }
427   compiled_action_foreach("compile_re2c") {
428     tool = ":re2c"
429     sources = [
430       "source/patched-yasm/modules/parsers/gas/gas-token.re",
431       "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
432     ]
433     outputs = [
434       "$target_gen_dir/{{source_name_part}}.c",
435     ]
436     args = [
437       "-b",
438       "-o",
439       rebase_path(target_gen_dir, root_build_dir) + "/{{source_name_part}}.c",
440       "{{source}}",
441     ]
442   }
444   # This call doesn't fit into the re2c template above.
445   compiled_action("compile_re2c_lc3b") {
446     tool = ":re2c"
447     inputs = [
448       "source/patched-yasm/modules/arch/lc3b/lc3bid.re",
449     ]
450     outputs = [
451       "$target_gen_dir/lc3bid.c",
452     ]
453     args = [
454       "-s",
455       "-o",
456       rebase_path(outputs[0], root_build_dir),
457       rebase_path(inputs[0], root_build_dir),
458     ]
459   }
461   compiled_action("generate_license") {
462     tool = ":genstring"
464     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
465     inputs = [
466       "source/patched-yasm/COPYING",
467     ]
468     outputs = [
469       "$yasm_gen_include_dir/license.c",
470     ]
471     args = [
472       "license_msg",
473       rebase_path(outputs[0], root_build_dir),
474       rebase_path(inputs[0], root_build_dir),
475     ]
476   }
478   compiled_action("generate_module") {
479     tool = ":genmodule"
480     inputs = [
481       "source/patched-yasm/libyasm/module.in",
482       config_makefile,
483     ]
484     outputs = [
485       "$target_gen_dir/module.c",
486     ]
487     args = [
488       rebase_path(inputs[0], root_build_dir),
489       rebase_path(config_makefile, root_build_dir),
490       rebase_path(outputs[0], root_build_dir),
491     ]
492   }
494   compiled_action("generate_version") {
495     tool = ":genversion"
496     outputs = [
497       "$target_gen_dir/$version_file",
498     ]
499     args = [ rebase_path(outputs[0], root_build_dir) ]
500   }
502   action("generate_x86_insn") {
503     script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
505     # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
506     outputs = [
507       "$yasm_gen_include_dir/x86insns.c",
508       "$yasm_gen_include_dir/x86insn_gas.gperf",
509       "$yasm_gen_include_dir/x86insn_nasm.gperf",
510     ]
511     args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]
512   }