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