Migrate away from the PrefMetricsService-based device ID in PrefHashCalculator.
[chromium-blink-merge.git] / third_party / yasm / BUILD.gn
blob34638520e78b74e540bd1517df6ef7c9c10acbb6
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") {
40     include_dirs = [
41       "source/config/$os",
42       "source/patched-yasm",
43     ]
44     defines = [ "HAVE_CONFIG_H" ]
45     if (is_posix) {
46       cflags = [ "-std=gnu99" ]
47     }
48   }
50   executable("genmacro") {
51     sources = [ "source/patched-yasm/tools/genmacro/genmacro.c" ]
52     configs -= [ "//build/config/compiler:chromium_code" ]
53     configs += [ ":yasm_config",
54                  "//build/config/compiler:no_chromium_code" ]
55   }
57   executable("genmodule") {
58     sources = [ "source/patched-yasm/libyasm/genmodule.c" ]
59     configs -= [ "//build/config/compiler:chromium_code" ]
60     configs += [ ":yasm_config",
61                  "//build/config/compiler:no_chromium_code" ]
62   }
64   executable("genperf") {
65     sources = [
66       "source/patched-yasm/tools/genperf/genperf.c",
67       "source/patched-yasm/tools/genperf/perfect.c",
68     ]
70     configs -= [ "//build/config/compiler:chromium_code" ]
71     configs += [ ":yasm_config",
72                  "//build/config/compiler:no_chromium_code" ]
74     deps = [ ":yasm_utils" ]
75   }
77   # Used by both yasm and genperf binaries.
78   source_set("yasm_utils") {
79     sources = [
80       "source/patched-yasm/libyasm/phash.c",
81       "source/patched-yasm/libyasm/xmalloc.c",
82       "source/patched-yasm/libyasm/xstrdup.c",
83     ]
85     configs -= [ "//build/config/compiler:chromium_code" ]
86     configs += [ ":yasm_config",
87                  "//build/config/compiler:no_chromium_code" ]
88   }
90   executable("genstring") {
91     sources = [ "source/patched-yasm/genstring.c", ]
92     configs -= [ "//build/config/compiler:chromium_code" ]
93     configs += [ ":yasm_config",
94                  "//build/config/compiler:no_chromium_code" ]
95   }
97   executable("genversion") {
98     sources = [ "source/patched-yasm/modules/preprocs/nasm/genversion.c" ]
99     configs -= [ "//build/config/compiler:chromium_code" ]
100     configs += [ ":yasm_config",
101                  "//build/config/compiler:no_chromium_code" ]
102   }
104   executable("re2c") {
105     sources = [
106        "source/patched-yasm/tools/re2c/main.c",
107        "source/patched-yasm/tools/re2c/code.c",
108        "source/patched-yasm/tools/re2c/dfa.c",
109        "source/patched-yasm/tools/re2c/parser.c",
110        "source/patched-yasm/tools/re2c/actions.c",
111        "source/patched-yasm/tools/re2c/scanner.c",
112        "source/patched-yasm/tools/re2c/mbo_getopt.c",
113        "source/patched-yasm/tools/re2c/substr.c",
114        "source/patched-yasm/tools/re2c/translate.c",
115     ]
117     configs -= [ "//build/config/compiler:chromium_code" ]
118     configs += [ ":yasm_config",
119                  "//build/config/compiler:no_chromium_code" ]
121     # re2c is missing CLOSEVOP from one switch.
122     if (is_posix) {
123       cflags = [ "-Wno-switch" ]
124     }
125   }
127   executable("yasm") {
128     sources = [
129       "source/patched-yasm/frontends/yasm/yasm-options.c",
130       "source/patched-yasm/frontends/yasm/yasm.c",
131       "source/patched-yasm/libyasm/assocdat.c",
132       "source/patched-yasm/libyasm/bc-align.c",
133       "source/patched-yasm/libyasm/bc-data.c",
134       "source/patched-yasm/libyasm/bc-incbin.c",
135       "source/patched-yasm/libyasm/bc-org.c",
136       "source/patched-yasm/libyasm/bc-reserve.c",
137       "source/patched-yasm/libyasm/bitvect.c",
138       "source/patched-yasm/libyasm/bytecode.c",
139       "source/patched-yasm/libyasm/errwarn.c",
140       "source/patched-yasm/libyasm/expr.c",
141       "source/patched-yasm/libyasm/file.c",
142       "source/patched-yasm/libyasm/floatnum.c",
143       "source/patched-yasm/libyasm/hamt.c",
144       "source/patched-yasm/libyasm/insn.c",
145       "source/patched-yasm/libyasm/intnum.c",
146       "source/patched-yasm/libyasm/inttree.c",
147       "source/patched-yasm/libyasm/linemap.c",
148       "source/patched-yasm/libyasm/md5.c",
149       "source/patched-yasm/libyasm/mergesort.c",
150       "source/patched-yasm/libyasm/section.c",
151       "source/patched-yasm/libyasm/strcasecmp.c",
152       "source/patched-yasm/libyasm/strsep.c",
153       "source/patched-yasm/libyasm/symrec.c",
154       "source/patched-yasm/libyasm/valparam.c",
155       "source/patched-yasm/libyasm/value.c",
156       "source/patched-yasm/modules/arch/lc3b/lc3barch.c",
157       "source/patched-yasm/modules/arch/lc3b/lc3bbc.c",
158       "source/patched-yasm/modules/arch/x86/x86arch.c",
159       "source/patched-yasm/modules/arch/x86/x86bc.c",
160       "source/patched-yasm/modules/arch/x86/x86expr.c",
161       "source/patched-yasm/modules/arch/x86/x86id.c",
162       "source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c",
163       "source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c",
164       "source/patched-yasm/modules/dbgfmts/codeview/cv-type.c",
165       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c",
166       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c",
167       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c",
168       "source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c",
169       "source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c",
170       "source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c",
171       "source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c",
172       "source/patched-yasm/modules/objfmts/bin/bin-objfmt.c",
173       "source/patched-yasm/modules/objfmts/coff/coff-objfmt.c",
174       "source/patched-yasm/modules/objfmts/coff/win64-except.c",
175       "source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c",
176       "source/patched-yasm/modules/objfmts/elf/elf-objfmt.c",
177       "source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c",
178       "source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c",
179       "source/patched-yasm/modules/objfmts/elf/elf.c",
180       "source/patched-yasm/modules/objfmts/macho/macho-objfmt.c",
181       "source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c",
182       "source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c",
183       "source/patched-yasm/modules/parsers/gas/gas-parse.c",
184       "source/patched-yasm/modules/parsers/gas/gas-parse-intel.c",
185       "source/patched-yasm/modules/parsers/gas/gas-parser.c",
186       "source/patched-yasm/modules/parsers/nasm/nasm-parse.c",
187       "source/patched-yasm/modules/parsers/nasm/nasm-parser.c",
188       "source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c",
189       "source/patched-yasm/modules/preprocs/nasm/nasm-eval.c",
190       "source/patched-yasm/modules/preprocs/nasm/nasm-pp.c",
191       "source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c",
192       "source/patched-yasm/modules/preprocs/nasm/nasmlib.c",
193       "source/patched-yasm/modules/preprocs/raw/raw-preproc.c",
195       # Files generated by compile_gperf
196       "$target_gen_dir/x86cpu.c",
197       "$target_gen_dir/x86regtmod.c",
199       # Files generated by compile_re2c
200       "$target_gen_dir/gas-token.c",
201       "$target_gen_dir/nasm-token.c",
203       # File generated by compile_re2c_lc3b
204       "$target_gen_dir/lc3bid.c",
206       # File generated by generate_module
207       "$target_gen_dir/module.c"
208     ]
210     configs -= [ "//build/config/compiler:chromium_code" ]
211     configs += [ ":yasm_config",
212                  "//build/config/compiler:no_chromium_code" ]
214     # Yasm generates a bunch of .c files which its source file #include.
215     # Add the |target_gen_dir| into the include path so it can find them.
216     # Ideally, these generated .c files would be placed into a separate
217     # directory, but the gen_x86_insn.py script does not make this easy.
218     include_dirs = [ yasm_gen_include_dir ]
220     if (is_win) {
221       cflags = [ "/wd4267" ]  # size_t to int conversion.
222     } else {
223       cflags = [ "-ansi", "-pedantic" ]
224       if (is_clang) {
225         cflags += [ "-Wno-incompatible-pointer-types" ]
226       }
227     }
229     # TODO(ajwong): This should take most of the generated output as
230     # inputs.
231     deps = [
232       ":compile_gperf",
233       ":compile_gperf_for_include",
234       ":compile_nasm_macros",
235       ":compile_nasm_version",
236       ":compile_re2c_lc3b",
237       ":compile_win64_gas",
238       ":compile_win64_nasm",
239       ":compile_re2c",
240       ":generate_license",
241       ":generate_module",
242       ":generate_version",
243       ":yasm_utils",
244     ]
245   }
247   compiled_action_foreach("compile_gperf") {
248     tool = ":genperf"
249     sources = [
250       "source/patched-yasm/modules/arch/x86/x86cpu.gperf",
251       "source/patched-yasm/modules/arch/x86/x86regtmod.gperf",
252     ]
254     outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
255     args = [
256       "{{source}}",
257       rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
258     ]
259     deps = [
260       ":generate_x86_insn"
261     ]
262   }
264   # This differs from |compile_gperf| in where it places it output files.
265   compiled_action_foreach("compile_gperf_for_include") {
266     tool = ":genperf"
267     sources = [
268       # Make sure the generated gperf files in $target_gen_dir are synced with
269       # the outputs for the related generate_*_insn actions in the
270       # generate_files target below.
271       #
272       # The output for these two are #included by
273       #   source/patched-yasm/modules/arch/x86/x86id.c
274       "$yasm_gen_include_dir/x86insn_gas.gperf",
275       "$yasm_gen_include_dir/x86insn_nasm.gperf",
276     ]
278     outputs = [ "$yasm_gen_include_dir/{{source_name_part}}.c" ]
279     args = [
280       "{{source}}",
281       rebase_path(yasm_gen_include_dir, ".") + "/{{source_name_part}}.c",
282     ]
283     deps = [
284       ":generate_x86_insn"
285     ]
286   }
288   template("compile_macro") {
289     compiled_action(target_name) {
290       tool = ":genmacro"
291       # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
292       sources = invoker.sources
293       outputs = invoker.outputs
294       args = [
295         rebase_path(outputs[0], root_build_dir),
296         invoker.macro_varname,
297         rebase_path(sources[0], root_build_dir),
298       ]
299       if (defined(invoker.deps)) {
300         deps = invoker.deps
301       }
302     }
303   }
305   compile_macro("compile_nasm_macros") {
306     # Output #included by
307     #   source/patched-yasm/modules/preprocs/nasm/nasm-parser.c
308     sources = [ "source/patched-yasm/modules/parsers/nasm/nasm-std.mac" ]
309     outputs = [ "$yasm_gen_include_dir/nasm-macros.c" ]
310     macro_varname = "nasm_standard_mac"
311   }
313   compile_macro("compile_nasm_version") {
314     # Output #included by
315     #   source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
316     sources = [ "$target_gen_dir/$version_file" ]
317     outputs = [ "$yasm_gen_include_dir/nasm-version.c" ]
318     macro_varname = "nasm_version_mac"
319     deps = [ ":generate_version" ]
320   }
322   compile_macro("compile_win64_gas") {
323     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
324     sources = [ "source/patched-yasm/modules/objfmts/coff/win64-gas.mac" ]
325     outputs = [ "$yasm_gen_include_dir/win64-gas.c" ]
326     macro_varname = "win64_gas_stdmac"
327   }
329   compile_macro("compile_win64_nasm") {
330     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
331     sources = [ "source/patched-yasm/modules/objfmts/coff/win64-nasm.mac" ]
332     outputs = [ "$yasm_gen_include_dir/win64-nasm.c" ]
333     macro_varname = "win64_nasm_stdmac"
334   }
336   compiled_action_foreach("compile_re2c") {
337     tool = ":re2c"
338     sources = [
339       "source/patched-yasm/modules/parsers/gas/gas-token.re",
340       "source/patched-yasm/modules/parsers/nasm/nasm-token.re",
341     ]
342     outputs = [ "$target_gen_dir/{{source_name_part}}.c" ]
343     args = [
344       "-b",
345       "-o",
346       rebase_path(target_gen_dir, ".") + "/{{source_name_part}}.c",
347       "{{source}}",
348     ]
349   }
351   # This call doesn't fit into the re2c template above.
352   compiled_action("compile_re2c_lc3b") {
353     tool = ":re2c"
354     sources = [ "source/patched-yasm/modules/arch/lc3b/lc3bid.re" ]
355     outputs = [ "$target_gen_dir/lc3bid.c" ]
356     args = [
357       "-s",
358       "-o",
359       rebase_path(outputs[0], root_build_dir),
360       rebase_path(sources[0], root_build_dir),
361     ]
362   }
364   compiled_action("generate_license") {
365     tool = ":genstring"
366     # Output #included by source/patched-yasm/frontends/yasm/yasm.c.
367     sources = [ "source/patched-yasm/COPYING" ]
368     outputs = [ "$yasm_gen_include_dir/license.c" ]
369     args = [
370       "license_msg",
371       rebase_path(outputs[0], root_build_dir),
372       rebase_path(sources[0], root_build_dir),
373     ]
374   }
376   compiled_action("generate_module") {
377     tool = ":genmodule"
378     inputs = [ config_makefile ]
379     sources = [ "source/patched-yasm/libyasm/module.in" ]
380     outputs = [ "$target_gen_dir/module.c" ]
381     args = [
382       rebase_path(sources[0], root_build_dir),
383       rebase_path(config_makefile, root_build_dir),
384       rebase_path(outputs[0], root_build_dir),
385     ]
386   }
388   compiled_action("generate_version") {
389     tool = ":genversion"
390     outputs = [ "$target_gen_dir/$version_file" ]
391     args = [
392       rebase_path(outputs[0],
393       root_build_dir)
394     ]
395   }
397   action("generate_x86_insn") {
398     script = "source/patched-yasm/modules/arch/x86/gen_x86_insn.py"
399     # Output eventually #included by source/patched-yasm/frontends/yasm/x86id.c
400     outputs = [
401       "$yasm_gen_include_dir/x86insns.c",
402       "$yasm_gen_include_dir/x86insn_gas.gperf",
403       "$yasm_gen_include_dir/x86insn_nasm.gperf",
404     ]
405     args = [ rebase_path(yasm_gen_include_dir, root_build_dir) ]
406   }