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