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
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.
34 'yasm_include_dirs': [
35 'source/config/<(OS)',
36 'source/patched-yasm',
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'],
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',
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' ],
67 'target_name': 'yasm',
76 'generate_files', # Needed to generate gperf and instruction files.
81 'clang_warning_flags': [
82 # yasm passes a `const elf_machine_sym*` through `void*`.
83 '-Wno-incompatible-pointer-types',
84 # reg3264type in x86expr.c is unused.
85 '-Wno-unused-local-typedef',
90 # As of VS 2013 Update 3, building this project with /analyze hits an
91 # internal compiler error on elf-x86-amd64.c in release builds with
92 # the amd64_x86 compiler. This halts the build and prevents subsequent
93 # analysis. Therefore, /analyze is disabled for this project. See this
95 # https://connect.microsoft.com/VisualStudio/feedback/details/1014799/internal-compiler-error-when-using-analyze
98 'AdditionalOptions!': [ '/analyze:WX-' ]
104 'source/patched-yasm/frontends/yasm/yasm-options.c',
105 'source/patched-yasm/frontends/yasm/yasm.c',
106 'source/patched-yasm/libyasm/assocdat.c',
107 'source/patched-yasm/libyasm/bc-align.c',
108 'source/patched-yasm/libyasm/bc-data.c',
109 'source/patched-yasm/libyasm/bc-incbin.c',
110 'source/patched-yasm/libyasm/bc-org.c',
111 'source/patched-yasm/libyasm/bc-reserve.c',
112 'source/patched-yasm/libyasm/bitvect.c',
113 'source/patched-yasm/libyasm/bytecode.c',
114 'source/patched-yasm/libyasm/errwarn.c',
115 'source/patched-yasm/libyasm/expr.c',
116 'source/patched-yasm/libyasm/file.c',
117 'source/patched-yasm/libyasm/floatnum.c',
118 'source/patched-yasm/libyasm/hamt.c',
119 'source/patched-yasm/libyasm/insn.c',
120 'source/patched-yasm/libyasm/intnum.c',
121 'source/patched-yasm/libyasm/inttree.c',
122 'source/patched-yasm/libyasm/linemap.c',
123 'source/patched-yasm/libyasm/md5.c',
124 'source/patched-yasm/libyasm/mergesort.c',
125 'source/patched-yasm/libyasm/section.c',
126 'source/patched-yasm/libyasm/strcasecmp.c',
127 'source/patched-yasm/libyasm/strsep.c',
128 'source/patched-yasm/libyasm/symrec.c',
129 'source/patched-yasm/libyasm/valparam.c',
130 'source/patched-yasm/libyasm/value.c',
131 'source/patched-yasm/modules/arch/lc3b/lc3barch.c',
132 'source/patched-yasm/modules/arch/lc3b/lc3bbc.c',
133 'source/patched-yasm/modules/arch/x86/x86arch.c',
134 'source/patched-yasm/modules/arch/x86/x86bc.c',
135 'source/patched-yasm/modules/arch/x86/x86expr.c',
136 'source/patched-yasm/modules/arch/x86/x86id.c',
137 'source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c',
138 'source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c',
139 'source/patched-yasm/modules/dbgfmts/codeview/cv-type.c',
140 'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c',
141 'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c',
142 'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c',
143 'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c',
144 'source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c',
145 'source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c',
146 'source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c',
147 'source/patched-yasm/modules/objfmts/bin/bin-objfmt.c',
148 'source/patched-yasm/modules/objfmts/coff/coff-objfmt.c',
149 'source/patched-yasm/modules/objfmts/coff/win64-except.c',
150 'source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c',
151 'source/patched-yasm/modules/objfmts/elf/elf-objfmt.c',
152 'source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c',
153 'source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c',
154 'source/patched-yasm/modules/objfmts/elf/elf.c',
155 'source/patched-yasm/modules/objfmts/macho/macho-objfmt.c',
156 'source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c',
157 'source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c',
158 'source/patched-yasm/modules/parsers/gas/gas-parse.c',
159 'source/patched-yasm/modules/parsers/gas/gas-parse-intel.c',
160 'source/patched-yasm/modules/parsers/gas/gas-parser.c',
161 'source/patched-yasm/modules/parsers/nasm/nasm-parse.c',
162 'source/patched-yasm/modules/parsers/nasm/nasm-parser.c',
163 'source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c',
164 'source/patched-yasm/modules/preprocs/nasm/nasm-eval.c',
165 'source/patched-yasm/modules/preprocs/nasm/nasm-pp.c',
166 'source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c',
167 'source/patched-yasm/modules/preprocs/nasm/nasmlib.c',
168 'source/patched-yasm/modules/preprocs/raw/raw-preproc.c',
170 # Sources needed by re2c.
171 'source/patched-yasm/modules/parsers/gas/gas-token.re',
172 'source/patched-yasm/modules/parsers/nasm/nasm-token.re',
174 # Sources needed by genperf. Make sure the generated gperf files
175 # (the ones in shared_generated_dir) are synced with the outputs
176 # for the related generate_*_insn actions in the generate_files
178 '<(shared_generated_dir)/x86insn_nasm.gperf',
179 '<(shared_generated_dir)/x86insn_gas.gperf',
180 '<(shared_generated_dir)/x86cpu.c',
181 '<(shared_generated_dir)/x86regtmod.c',
184 '<@(yasm_include_dirs)',
185 '<(shared_generated_dir)',
188 'defines': [ '<@(yasm_defines)' ],
189 'cflags': [ '<@(yasm_cflags)', ],
190 'msvs_disabled_warnings': [ 4267 ],
193 'rule_name': 'generate_gperf',
194 'extension': 'gperf',
195 'inputs': [ '<(PRODUCT_DIR)/'
196 '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
198 '<(generated_dir)/<(RULE_INPUT_ROOT).c',
200 'action': ['<(PRODUCT_DIR)/genperf',
201 '<(RULE_INPUT_PATH)',
202 '<(generated_dir)/<(RULE_INPUT_ROOT).c',
204 # These files are #included, so do not treat them as sources.
205 'process_outputs_as_sources': 0,
206 'message': 'yasm gperf for <(RULE_INPUT_PATH)',
209 'rule_name': 'generate_re2c',
211 'inputs': [ '<(PRODUCT_DIR)/'
212 '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)' ],
213 'outputs': [ '<(generated_dir)/<(RULE_INPUT_ROOT).c', ],
215 '<(PRODUCT_DIR)/re2c',
218 '<(generated_dir)/<(RULE_INPUT_ROOT).c',
219 '<(RULE_INPUT_PATH)',
221 'process_outputs_as_sources': 1,
222 'message': 'yasm re2c for <(RULE_INPUT_PATH)',
230 'action_name': 'generate_nasm_macros',
232 'infile': 'source/patched-yasm/modules/parsers/nasm/nasm-std.mac',
233 'varname': 'nasm_standard_mac',
234 'outfile': '<(generated_dir)/nasm-macros.c',
236 'inputs': [ '<(PRODUCT_DIR)/'
237 '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
239 'outputs': [ '<(outfile)', ],
240 'action': ['<(PRODUCT_DIR)/genmacro',
241 '<(outfile)', '<(varname)', '<(infile)', ],
242 # Not a direct source because this is #included by
243 # source/patched-yasm/modules/parsers/nasm/nasm-parser.c
244 'process_outputs_as_sources': 1,
245 'message': 'yasm genmacro for <(infile)',
248 'action_name': 'generate_nasm_version',
250 'infile': '<(shared_generated_dir)/<(version_file)',
251 'varname': 'nasm_version_mac',
252 'outfile': '<(generated_dir)/nasm-version.c',
254 'inputs': [ '<(PRODUCT_DIR)/'
255 '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
257 'outputs': [ '<(outfile)', ],
258 'action': ['<(PRODUCT_DIR)/genmacro',
259 '<(outfile)', '<(varname)', '<(infile)',
261 # Not a direct source because this is #included by
262 # source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
263 'process_outputs_as_sources': 0,
264 'message': 'yasm genmacro for <(infile)',
267 'action_name': 'generate_win64_gas',
269 'infile': 'source/patched-yasm/modules/objfmts/coff/win64-gas.mac',
270 'varname': 'win64_gas_stdmac',
271 'outfile': '<(generated_dir)/win64-gas.c',
273 'inputs': [ '<(PRODUCT_DIR)/'
274 '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
276 'outputs': [ '<(outfile)', ],
277 'action': ['<(PRODUCT_DIR)/genmacro',
278 '<(outfile)', '<(varname)', '<(infile)',
280 # Not a direct source because this is #included by
281 # source/patched-yasm/modules/objfmts/coff/coff-objfmt.c
282 'process_outputs_as_sources': 0,
283 'message': 'yasm genmacro for <(infile)',
286 'action_name': 'generate_win64_nasm',
288 'infile': 'source/patched-yasm/modules/objfmts/coff/win64-nasm.mac',
289 'varname': 'win64_nasm_stdmac',
290 'outfile': '<(generated_dir)/win64-nasm.c',
292 'inputs': [ '<(PRODUCT_DIR)/'
293 '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
295 'outputs': [ '<(outfile)', ],
296 'action': ['<(PRODUCT_DIR)/genmacro',
301 # Not a direct source because this is #included by
302 # source/patched-yasm/modules/objfmts/coff/coff-objfmt.c
303 'process_outputs_as_sources': 0,
304 'message': 'yasm genmacro for <(infile)',
311 'action_name': 'generate_license',
313 'infile': 'source/patched-yasm/COPYING',
314 'varname': 'license_msg',
315 'outfile': '<(generated_dir)/license.c',
317 'inputs': [ '<(PRODUCT_DIR)/'
318 '<(EXECUTABLE_PREFIX)genstring<(EXECUTABLE_SUFFIX)',
320 'outputs': [ '<(outfile)', ],
321 'action': ['<(PRODUCT_DIR)/genstring',
326 # Not a direct source because this is #included by
327 # source/patched-yasm/frontends/yasm/yasm.c
328 'process_outputs_as_sources': 0,
329 'message': 'Generating yasm embeddable license',
333 ### A re2c call that doesn't fit into the rule below.
336 'action_name': 'generate_lc3b_token',
338 'infile': 'source/patched-yasm/modules/arch/lc3b/lc3bid.re',
339 # The license file is #included by yasm.c.
340 'outfile': '<(generated_dir)/lc3bid.c',
342 'inputs': [ '<(PRODUCT_DIR)/'
343 '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)',
345 'outputs': [ '<(outfile)', ],
347 '<(PRODUCT_DIR)/re2c',
352 'process_outputs_as_sources': 1,
353 'message': 'Generating yasm tokens for lc3b',
360 'action_name': 'generate_module',
362 'makefile': 'source/config/<(OS)/Makefile',
363 'module_in': 'source/patched-yasm/libyasm/module.in',
364 'outfile': '<(generated_dir)/module.c',
367 '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)genmodule<(EXECUTABLE_SUFFIX)',
371 'outputs': [ '<(generated_dir)/module.c' ],
373 '<(PRODUCT_DIR)/genmodule',
378 'process_outputs_as_sources': 1,
379 'message': 'Generating yasm module information',
384 'target_name': 'config_sources',
386 'toolsets': ['host'],
388 'source/config/<(OS)/Makefile',
389 'source/config/<(OS)/config.h',
390 'source/config/<(OS)/libyasm-stdint.h',
394 'target_name': 'generate_files',
396 'toolsets': ['host'],
402 'source/patched-yasm/modules/arch/x86/x86cpu.gperf',
403 'source/patched-yasm/modules/arch/x86/x86regtmod.gperf',
407 'rule_name': 'generate_gperf',
408 'extension': 'gperf',
409 'inputs': [ '<(PRODUCT_DIR)/'
410 '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
411 'outputs': [ '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c', ],
413 '<(PRODUCT_DIR)/genperf',
414 '<(RULE_INPUT_PATH)',
415 '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c',
417 'process_outputs_as_sources': 0,
418 'message': 'yasm genperf for <(RULE_INPUT_PATH)',
423 'action_name': 'generate_x86_insn',
426 'source/patched-yasm/modules/arch/x86/gen_x86_insn.py',
428 'inputs': [ '<(gen_insn_path)', ],
430 '<(shared_generated_dir)/x86insns.c',
431 '<(shared_generated_dir)/x86insn_gas.gperf',
432 '<(shared_generated_dir)/x86insn_nasm.gperf',
437 '<(shared_generated_dir)',
439 'message': 'Running <(gen_insn_path)',
440 'process_outputs_as_sources': 0,
443 'action_name': 'generate_version',
444 'inputs': [ '<(PRODUCT_DIR)/'
445 '<(EXECUTABLE_PREFIX)genversion<(EXECUTABLE_SUFFIX)' ],
446 'outputs': [ '<(shared_generated_dir)/<(version_file)', ],
448 '<(PRODUCT_DIR)/genversion',
449 '<(shared_generated_dir)/<(version_file)'
451 'message': 'Generating yasm version file: '
452 '<(shared_generated_dir)/<(version_file)',
453 'process_outputs_as_sources': 0,
458 'target_name': 'genperf_libs',
459 'type': 'static_library',
460 'toolsets': ['host'],
461 'dependencies': [ 'config_sources', ],
463 'source/patched-yasm/libyasm/phash.c',
464 'source/patched-yasm/libyasm/xmalloc.c',
465 'source/patched-yasm/libyasm/xstrdup.c',
468 '<@(yasm_include_dirs)',
470 'defines': [ '<@(yasm_defines)' ],
476 'target_name': 'genstring',
477 'type': 'executable',
478 'toolsets': ['host'],
479 'dependencies': [ 'config_sources', ],
481 'source/patched-yasm/genstring.c',
484 '<@(yasm_include_dirs)',
491 'target_name': 'genperf',
492 'type': 'executable',
493 'toolsets': ['host'],
498 'source/patched-yasm/tools/genperf/genperf.c',
499 'source/patched-yasm/tools/genperf/perfect.c',
502 '<@(yasm_include_dirs)',
509 'target_name': 'genmacro',
510 'type': 'executable',
511 'toolsets': ['host'],
512 'dependencies': [ 'config_sources', ],
514 'source/patched-yasm/tools/genmacro/genmacro.c',
517 '<@(yasm_include_dirs)',
524 'target_name': 'genversion',
525 'type': 'executable',
526 'toolsets': ['host'],
527 'dependencies': [ 'config_sources', ],
529 'source/patched-yasm/modules/preprocs/nasm/genversion.c',
532 '<@(yasm_include_dirs)',
539 'target_name': 're2c',
540 'type': 'executable',
541 'toolsets': ['host'],
542 'dependencies': [ 'config_sources', ],
544 'source/patched-yasm/tools/re2c/main.c',
545 'source/patched-yasm/tools/re2c/code.c',
546 'source/patched-yasm/tools/re2c/dfa.c',
547 'source/patched-yasm/tools/re2c/parser.c',
548 'source/patched-yasm/tools/re2c/actions.c',
549 'source/patched-yasm/tools/re2c/scanner.c',
550 'source/patched-yasm/tools/re2c/mbo_getopt.c',
551 'source/patched-yasm/tools/re2c/substr.c',
552 'source/patched-yasm/tools/re2c/translate.c',
555 '<@(yasm_include_dirs)',
561 'clang_warning_flags': [
562 # re2c is missing CLOSEVOP from one switch.
564 # re2c contains many static functions in headers (because it's
565 # a C library predating C99.)
566 '-Wno-unused-function',
569 'msvs_disabled_warnings': [ 4267 ],
572 'target_name': 'genmodule',
573 'type': 'executable',
574 'toolsets': ['host'],
579 'source/patched-yasm/libyasm/genmodule.c',
582 '<@(yasm_include_dirs)',