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