Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / third_party / yasm / yasm.gyp
blobee03c8fc83b8a7e4d9a68418c578e0aa097973fc
1 # Copyright (c) 2012 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) config_sources -- Checked in version of files generated by manually
19 #                        running configure that are used by all binaries.
20 #   3) generate_files -- Actions and rules for files of type #3.
21 #   4) genperf_libs -- Object files shared between yasm and the genperf
22 #                      subprogram.
23 #   5) genmacro, genmodule, etc. -- One executable target for each subprogram.
25 # You will notice that a lot of the action targets seem very similar --
26 # especially for genmacro invocations. This makes it seem like they should
27 # be a rule. The problem is that the correct invocation cannot be inferred
28 # purely from the file name, or extension.  Nor is it obvious whether the
29 # output should be processed as a source or not.  Thus, we are left with a
30 # large amount of repetitive code.
33   'variables': {
34     'yasm_include_dirs': [
35       'source/config/<(OS)',
36       'source/patched-yasm',
37     ],
39     # The cflags used by any target that will be directly linked into yasm.
40     # These are specifically not used when building the subprograms.  While
41     # it would probably be safe to use these flags there as well, the
42     # ./configure based build does not use the same flags between the main
43     # yasm executable, and its subprograms.
44     'yasm_defines': ['HAVE_CONFIG_H'],
45     'yasm_cflags': [
46       '-std=gnu99',
47       '-ansi',
48       '-pedantic',
49     ],
51     # Locations for various generated artifacts.
52     'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/third_party/yasm',
53     'generated_dir': '<(INTERMEDIATE_DIR)/third_party/yasm',
55     # Various files referenced by multiple targets.
56     'version_file': 'version.mac',  # Generated by genversion.
57     'genmodule_source': 'genmodule_outfile.c',
58   },
59   'target_defaults': {
60     # Silence warnings in libc++ builds (C code doesn't need this flag).
61     'ldflags!': [ '-stdlib=libc++', ],
62     # https://crbug.com/489901
63     'cflags!': [ '-fsanitize=bounds' ],
64   },
65   'targets': [
66     {
67       'target_name': 'yasm',
68       'type': 'executable',
69       'toolsets': ['host'],
70       'dependencies': [
71         'config_sources',
72         'genmacro',
73         'genmodule',
74         'genperf',
75         'genperf_libs',
76         'generate_files',  # Needed to generate gperf and instruction files.
77         'genstring',
78         're2c',
79       ],
80       'variables': {
81         'clang_warning_flags': [
82           # yasm passes a `const elf_machine_sym*` through `void*`.
83           '-Wno-incompatible-pointer-types',
84         ],
85       },
86       'conditions': [
87         ['OS=="win"', {
88           # As of VS 2013 Update 3, building this project with /analyze hits an
89           # internal compiler error on elf-x86-amd64.c in release builds with
90           # the amd64_x86 compiler. This halts the build and prevents subsequent
91           # analysis. Therefore, /analyze is disabled for this project. See this
92           # bug for details:
93           # https://connect.microsoft.com/VisualStudio/feedback/details/1014799/internal-compiler-error-when-using-analyze
94           'msvs_settings': {
95             'VCCLCompilerTool': {
96               'AdditionalOptions!': [ '/analyze' ]
97             },
98           },
99         }],
100       ],
101       'sources': [
102          'source/patched-yasm/frontends/yasm/yasm-options.c',
103          'source/patched-yasm/frontends/yasm/yasm.c',
104          'source/patched-yasm/libyasm/assocdat.c',
105          'source/patched-yasm/libyasm/bc-align.c',
106          'source/patched-yasm/libyasm/bc-data.c',
107          'source/patched-yasm/libyasm/bc-incbin.c',
108          'source/patched-yasm/libyasm/bc-org.c',
109          'source/patched-yasm/libyasm/bc-reserve.c',
110          'source/patched-yasm/libyasm/bitvect.c',
111          'source/patched-yasm/libyasm/bytecode.c',
112          'source/patched-yasm/libyasm/errwarn.c',
113          'source/patched-yasm/libyasm/expr.c',
114          'source/patched-yasm/libyasm/file.c',
115          'source/patched-yasm/libyasm/floatnum.c',
116          'source/patched-yasm/libyasm/hamt.c',
117          'source/patched-yasm/libyasm/insn.c',
118          'source/patched-yasm/libyasm/intnum.c',
119          'source/patched-yasm/libyasm/inttree.c',
120          'source/patched-yasm/libyasm/linemap.c',
121          'source/patched-yasm/libyasm/md5.c',
122          'source/patched-yasm/libyasm/mergesort.c',
123          'source/patched-yasm/libyasm/section.c',
124          'source/patched-yasm/libyasm/strcasecmp.c',
125          'source/patched-yasm/libyasm/strsep.c',
126          'source/patched-yasm/libyasm/symrec.c',
127          'source/patched-yasm/libyasm/valparam.c',
128          'source/patched-yasm/libyasm/value.c',
129          'source/patched-yasm/modules/arch/lc3b/lc3barch.c',
130          'source/patched-yasm/modules/arch/lc3b/lc3bbc.c',
131          'source/patched-yasm/modules/arch/x86/x86arch.c',
132          'source/patched-yasm/modules/arch/x86/x86bc.c',
133          'source/patched-yasm/modules/arch/x86/x86expr.c',
134          'source/patched-yasm/modules/arch/x86/x86id.c',
135          'source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c',
136          'source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c',
137          'source/patched-yasm/modules/dbgfmts/codeview/cv-type.c',
138          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c',
139          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c',
140          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c',
141          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c',
142          'source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c',
143          'source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c',
144          'source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c',
145          'source/patched-yasm/modules/objfmts/bin/bin-objfmt.c',
146          'source/patched-yasm/modules/objfmts/coff/coff-objfmt.c',
147          'source/patched-yasm/modules/objfmts/coff/win64-except.c',
148          'source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c',
149          'source/patched-yasm/modules/objfmts/elf/elf-objfmt.c',
150          'source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c',
151          'source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c',
152          'source/patched-yasm/modules/objfmts/elf/elf.c',
153          'source/patched-yasm/modules/objfmts/macho/macho-objfmt.c',
154          'source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c',
155          'source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c',
156          'source/patched-yasm/modules/parsers/gas/gas-parse.c',
157          'source/patched-yasm/modules/parsers/gas/gas-parse-intel.c',
158          'source/patched-yasm/modules/parsers/gas/gas-parser.c',
159          'source/patched-yasm/modules/parsers/nasm/nasm-parse.c',
160          'source/patched-yasm/modules/parsers/nasm/nasm-parser.c',
161          'source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c',
162          'source/patched-yasm/modules/preprocs/nasm/nasm-eval.c',
163          'source/patched-yasm/modules/preprocs/nasm/nasm-pp.c',
164          'source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c',
165          'source/patched-yasm/modules/preprocs/nasm/nasmlib.c',
166          'source/patched-yasm/modules/preprocs/raw/raw-preproc.c',
168          # Sources needed by re2c.
169          'source/patched-yasm/modules/parsers/gas/gas-token.re',
170          'source/patched-yasm/modules/parsers/nasm/nasm-token.re',
172          # Sources needed by genperf. Make sure the generated gperf files
173          # (the ones in shared_generated_dir) are synced with the outputs
174          # for the related generate_*_insn actions in the generate_files
175          # target below.
176          '<(shared_generated_dir)/x86insn_nasm.gperf',
177          '<(shared_generated_dir)/x86insn_gas.gperf',
178          '<(shared_generated_dir)/x86cpu.c',
179          '<(shared_generated_dir)/x86regtmod.c',
180       ],
181       'include_dirs': [
182         '<@(yasm_include_dirs)',
183         '<(shared_generated_dir)',
184         '<(generated_dir)',
185       ],
186       'defines': [ '<@(yasm_defines)' ],
187       'cflags': [ '<@(yasm_cflags)', ],
188       'msvs_disabled_warnings': [ 4267 ],
189       'rules': [
190         {
191           'rule_name': 'generate_gperf',
192           'extension': 'gperf',
193           'inputs': [ '<(PRODUCT_DIR)/'
194                       '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
195           'outputs': [
196             '<(generated_dir)/<(RULE_INPUT_ROOT).c',
197           ],
198           'action': ['<(PRODUCT_DIR)/genperf',
199                      '<(RULE_INPUT_PATH)',
200                      '<(generated_dir)/<(RULE_INPUT_ROOT).c',
201           ],
202           # These files are #included, so do not treat them as sources.
203           'process_outputs_as_sources': 0,
204           'message': 'yasm gperf for <(RULE_INPUT_PATH)',
205         },
206         {
207           'rule_name': 'generate_re2c',
208           'extension': 're',
209           'inputs': [ '<(PRODUCT_DIR)/'
210                       '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)' ],
211           'outputs': [ '<(generated_dir)/<(RULE_INPUT_ROOT).c', ],
212           'action': [
213             '<(PRODUCT_DIR)/re2c',
214             '-b',
215             '-o',
216             '<(generated_dir)/<(RULE_INPUT_ROOT).c',
217             '<(RULE_INPUT_PATH)',
218           ],
219           'process_outputs_as_sources': 1,
220           'message': 'yasm re2c for <(RULE_INPUT_PATH)',
221         },
222       ],
223       'actions': [
224         ###
225         ###  genmacro calls.
226         ###
227         {
228           'action_name': 'generate_nasm_macros',
229           'variables': {
230             'infile': 'source/patched-yasm/modules/parsers/nasm/nasm-std.mac',
231             'varname': 'nasm_standard_mac',
232             'outfile': '<(generated_dir)/nasm-macros.c',
233           },
234           'inputs': [ '<(PRODUCT_DIR)/'
235                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
236                       '<(infile)', ],
237           'outputs': [ '<(outfile)', ],
238           'action': ['<(PRODUCT_DIR)/genmacro',
239                      '<(outfile)', '<(varname)', '<(infile)', ],
240            # Not a direct source because this is #included by
241            #   source/patched-yasm/modules/parsers/nasm/nasm-parser.c
242           'process_outputs_as_sources': 1,
243           'message': 'yasm genmacro for <(infile)',
244         },
245         {
246           'action_name': 'generate_nasm_version',
247           'variables': {
248             'infile': '<(shared_generated_dir)/<(version_file)',
249             'varname': 'nasm_version_mac',
250             'outfile': '<(generated_dir)/nasm-version.c',
251           },
252           'inputs': [ '<(PRODUCT_DIR)/'
253                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
254                       '<(infile)', ],
255           'outputs': [ '<(outfile)', ],
256           'action': ['<(PRODUCT_DIR)/genmacro',
257                      '<(outfile)', '<(varname)', '<(infile)',
258           ],
259            # Not a direct source because this is #included by
260            #   source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
261           'process_outputs_as_sources': 0,
262           'message': 'yasm genmacro for <(infile)',
263         },
264         {
265           'action_name': 'generate_win64_gas',
266           'variables': {
267             'infile': 'source/patched-yasm/modules/objfmts/coff/win64-gas.mac',
268             'varname': 'win64_gas_stdmac',
269             'outfile': '<(generated_dir)/win64-gas.c',
270           },
271           'inputs': [ '<(PRODUCT_DIR)/'
272                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
273                       '<(infile)', ],
274           'outputs': [ '<(outfile)', ],
275           'action': ['<(PRODUCT_DIR)/genmacro',
276                      '<(outfile)', '<(varname)', '<(infile)',
277           ],
278            # Not a direct source because this is #included by
279            #   source/patched-yasm/modules/objfmts/coff/coff-objfmt.c
280           'process_outputs_as_sources': 0,
281           'message': 'yasm genmacro for <(infile)',
282         },
283         {
284           'action_name': 'generate_win64_nasm',
285           'variables': {
286             'infile': 'source/patched-yasm/modules/objfmts/coff/win64-nasm.mac',
287             'varname': 'win64_nasm_stdmac',
288             'outfile': '<(generated_dir)/win64-nasm.c',
289           },
290           'inputs': [ '<(PRODUCT_DIR)/'
291                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
292                       '<(infile)', ],
293           'outputs': [ '<(outfile)', ],
294           'action': ['<(PRODUCT_DIR)/genmacro',
295                      '<(outfile)',
296                      '<(varname)',
297                      '<(infile)',
298           ],
299            # Not a direct source because this is #included by
300            #   source/patched-yasm/modules/objfmts/coff/coff-objfmt.c
301           'process_outputs_as_sources': 0,
302           'message': 'yasm genmacro for <(infile)',
303         },
305         ###
306         ###  genstring call.
307         ###
308         {
309           'action_name': 'generate_license',
310           'variables': {
311             'infile': 'source/patched-yasm/COPYING',
312             'varname': 'license_msg',
313             'outfile': '<(generated_dir)/license.c',
314           },
315           'inputs': [ '<(PRODUCT_DIR)/'
316                       '<(EXECUTABLE_PREFIX)genstring<(EXECUTABLE_SUFFIX)',
317                       '<(infile)', ],
318           'outputs': [ '<(outfile)', ],
319           'action': ['<(PRODUCT_DIR)/genstring',
320                      '<(varname)',
321                      '<(outfile)',
322                      '<(infile)',
323           ],
324           # Not a direct source because this is #included by
325           #   source/patched-yasm/frontends/yasm/yasm.c
326           'process_outputs_as_sources': 0,
327           'message': 'Generating yasm embeddable license',
328         },
330         ###
331         ###  A re2c call that doesn't fit into the rule below.
332         ###
333         {
334           'action_name': 'generate_lc3b_token',
335           'variables': {
336             'infile': 'source/patched-yasm/modules/arch/lc3b/lc3bid.re',
337             # The license file is #included by yasm.c.
338             'outfile': '<(generated_dir)/lc3bid.c',
339           },
340           'inputs': [ '<(PRODUCT_DIR)/'
341                       '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)',
342                       '<(infile)', ],
343           'outputs': [ '<(outfile)', ],
344           'action': [
345             '<(PRODUCT_DIR)/re2c',
346             '-s',
347             '-o', '<(outfile)',
348             '<(infile)'
349           ],
350           'process_outputs_as_sources': 1,
351           'message': 'Generating yasm tokens for lc3b',
352         },
354         ###
355         ###  genmodule call.
356         ###
357         {
358           'action_name': 'generate_module',
359           'variables': {
360             'makefile': 'source/config/<(OS)/Makefile',
361             'module_in': 'source/patched-yasm/libyasm/module.in',
362             'outfile': '<(generated_dir)/module.c',
363           },
364           'inputs': [
365             '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)genmodule<(EXECUTABLE_SUFFIX)',
366             '<(module_in)',
367             '<(makefile)'
368           ],
369           'outputs': [ '<(generated_dir)/module.c' ],
370           'action': [
371             '<(PRODUCT_DIR)/genmodule',
372             '<(module_in)',
373             '<(makefile)',
374             '<(outfile)'
375           ],
376           'process_outputs_as_sources': 1,
377           'message': 'Generating yasm module information',
378         },
379       ],
380     },
381     {
382       'target_name': 'config_sources',
383       'type': 'none',
384       'toolsets': ['host'],
385       'sources': [
386         'source/config/<(OS)/Makefile',
387         'source/config/<(OS)/config.h',
388         'source/config/<(OS)/libyasm-stdint.h',
389       ],
390     },
391     {
392       'target_name': 'generate_files',
393       'type': 'none',
394       'toolsets': ['host'],
395       'dependencies': [
396         'genperf',
397         'genversion',
398       ],
399       'sources': [
400          'source/patched-yasm/modules/arch/x86/x86cpu.gperf',
401          'source/patched-yasm/modules/arch/x86/x86regtmod.gperf',
402       ],
403       'rules': [
404         {
405           'rule_name': 'generate_gperf',
406           'extension': 'gperf',
407           'inputs': [ '<(PRODUCT_DIR)/'
408                       '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
409           'outputs': [ '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c', ],
410           'action': [
411             '<(PRODUCT_DIR)/genperf',
412             '<(RULE_INPUT_PATH)',
413             '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c',
414           ],
415           'process_outputs_as_sources': 0,
416           'message': 'yasm genperf for <(RULE_INPUT_PATH)',
417         },
418       ],
419       'actions': [
420         {
421           'action_name': 'generate_x86_insn',
422           'variables': {
423             'gen_insn_path':
424                 'source/patched-yasm/modules/arch/x86/gen_x86_insn.py',
425           },
426           'inputs': [ '<(gen_insn_path)', ],
427           'outputs': [
428             '<(shared_generated_dir)/x86insns.c',
429             '<(shared_generated_dir)/x86insn_gas.gperf',
430             '<(shared_generated_dir)/x86insn_nasm.gperf',
431           ],
432           'action': [
433             'python',
434             '<(gen_insn_path)',
435             '<(shared_generated_dir)',
436           ],
437           'message': 'Running <(gen_insn_path)',
438           'process_outputs_as_sources': 0,
439         },
440         {
441           'action_name': 'generate_version',
442           'inputs': [ '<(PRODUCT_DIR)/'
443                       '<(EXECUTABLE_PREFIX)genversion<(EXECUTABLE_SUFFIX)' ],
444           'outputs': [ '<(shared_generated_dir)/<(version_file)', ],
445           'action': [
446             '<(PRODUCT_DIR)/genversion',
447             '<(shared_generated_dir)/<(version_file)'
448           ],
449           'message': 'Generating yasm version file: '
450                      '<(shared_generated_dir)/<(version_file)',
451           'process_outputs_as_sources': 0,
452         },
453       ],
454     },
455     {
456       'target_name': 'genperf_libs',
457       'type': 'static_library',
458       'toolsets': ['host'],
459       'dependencies': [ 'config_sources', ],
460       'sources': [
461          'source/patched-yasm/libyasm/phash.c',
462          'source/patched-yasm/libyasm/xmalloc.c',
463          'source/patched-yasm/libyasm/xstrdup.c',
464       ],
465       'include_dirs': [
466         '<@(yasm_include_dirs)',
467       ],
468       'defines': [ '<@(yasm_defines)' ],
469       'cflags': [
470         '<@(yasm_cflags)',
471       ],
472     },
473     {
474       'target_name': 'genstring',
475       'type': 'executable',
476       'toolsets': ['host'],
477       'dependencies': [ 'config_sources', ],
478       'sources': [
479          'source/patched-yasm/genstring.c',
480       ],
481       'include_dirs': [
482         '<@(yasm_include_dirs)',
483       ],
484       'cflags': [
485         '-std=gnu99',
486       ],
487     },
488     {
489       'target_name': 'genperf',
490       'type': 'executable',
491       'toolsets': ['host'],
492       'dependencies': [
493         'genperf_libs',
494       ],
495       'sources': [
496          'source/patched-yasm/tools/genperf/genperf.c',
497          'source/patched-yasm/tools/genperf/perfect.c',
498       ],
499       'include_dirs': [
500         '<@(yasm_include_dirs)',
501       ],
502       'cflags': [
503         '-std=gnu99',
504       ],
505     },
506     {
507       'target_name': 'genmacro',
508       'type': 'executable',
509       'toolsets': ['host'],
510       'dependencies': [ 'config_sources', ],
511       'sources': [
512         'source/patched-yasm/tools/genmacro/genmacro.c',
513       ],
514       'include_dirs': [
515         '<@(yasm_include_dirs)',
516       ],
517       'cflags': [
518         '-std=gnu99',
519       ],
520     },
521     {
522       'target_name': 'genversion',
523       'type': 'executable',
524       'toolsets': ['host'],
525       'dependencies': [ 'config_sources', ],
526       'sources': [
527          'source/patched-yasm/modules/preprocs/nasm/genversion.c',
528       ],
529       'include_dirs': [
530         '<@(yasm_include_dirs)',
531       ],
532       'cflags': [
533         '-std=gnu99',
534       ],
535     },
536     {
537       'target_name': 're2c',
538       'type': 'executable',
539       'toolsets': ['host'],
540       'dependencies': [ 'config_sources', ],
541       'sources': [
542          'source/patched-yasm/tools/re2c/main.c',
543          'source/patched-yasm/tools/re2c/code.c',
544          'source/patched-yasm/tools/re2c/dfa.c',
545          'source/patched-yasm/tools/re2c/parser.c',
546          'source/patched-yasm/tools/re2c/actions.c',
547          'source/patched-yasm/tools/re2c/scanner.c',
548          'source/patched-yasm/tools/re2c/mbo_getopt.c',
549          'source/patched-yasm/tools/re2c/substr.c',
550          'source/patched-yasm/tools/re2c/translate.c',
551       ],
552       'include_dirs': [
553         '<@(yasm_include_dirs)',
554       ],
555       'cflags': [
556         '-std=gnu99',
557       ],
558       'variables': {
559           # re2c is missing CLOSEVOP from one switch.
560         'clang_warning_flags': [ '-Wno-switch' ],
561       },
562       'msvs_disabled_warnings': [ 4267 ],
563     },
564     {
565       'target_name': 'genmodule',
566       'type': 'executable',
567       'toolsets': ['host'],
568       'dependencies': [
569         'config_sources',
570       ],
571       'sources': [
572         'source/patched-yasm/libyasm/genmodule.c',
573       ],
574       'include_dirs': [
575         '<@(yasm_include_dirs)',
577       ],
578       'cflags': [
579         '-std=gnu99',
580       ],
581     },
582   ],