Home | History | Annotate | Download | only in yasm
      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.
      4 
      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.
      8 #
      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)
     14 #
     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.
     24 #
     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.
     31 
     32 {
     33   'variables': {
     34     'yasm_include_dirs': [
     35       'source/config/<(OS)',
     36       'source/patched-yasm',
     37     ],
     38 
     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     ],
     50 
     51     # Locations for various generated artifacts.
     52     'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/third_party/yasm',
     53     'generated_dir': '<(INTERMEDIATE_DIR)/third_party/yasm',
     54 
     55     # Various files referenced by multiple targets.
     56     'version_file': 'version.mac',  # Generated by genversion.
     57     'genmodule_source': 'genmodule_outfile.c',
     58   },
     59   'targets': [
     60     {
     61       'target_name': 'yasm',
     62       'type': 'executable',
     63       'toolsets': ['host'],
     64       'dependencies': [
     65         'config_sources',
     66         'genmacro',
     67         'genmodule',
     68         'genperf',
     69         'genperf_libs',
     70         'generate_files',  # Needed to generate gperf and instruction files.
     71         'genstring',
     72         're2c',
     73       ],
     74       'variables': {
     75         'clang_warning_flags': [
     76           # yasm passes a `const elf_machine_sym*` through `void*`.
     77           '-Wno-incompatible-pointer-types',
     78         ],
     79       },
     80       'sources': [
     81          'source/patched-yasm/frontends/yasm/yasm-options.c',
     82          'source/patched-yasm/frontends/yasm/yasm.c',
     83          'source/patched-yasm/libyasm/assocdat.c',
     84          'source/patched-yasm/libyasm/bc-align.c',
     85          'source/patched-yasm/libyasm/bc-data.c',
     86          'source/patched-yasm/libyasm/bc-incbin.c',
     87          'source/patched-yasm/libyasm/bc-org.c',
     88          'source/patched-yasm/libyasm/bc-reserve.c',
     89          'source/patched-yasm/libyasm/bitvect.c',
     90          'source/patched-yasm/libyasm/bytecode.c',
     91          'source/patched-yasm/libyasm/errwarn.c',
     92          'source/patched-yasm/libyasm/expr.c',
     93          'source/patched-yasm/libyasm/file.c',
     94          'source/patched-yasm/libyasm/floatnum.c',
     95          'source/patched-yasm/libyasm/hamt.c',
     96          'source/patched-yasm/libyasm/insn.c',
     97          'source/patched-yasm/libyasm/intnum.c',
     98          'source/patched-yasm/libyasm/inttree.c',
     99          'source/patched-yasm/libyasm/linemap.c',
    100          'source/patched-yasm/libyasm/md5.c',
    101          'source/patched-yasm/libyasm/mergesort.c',
    102          'source/patched-yasm/libyasm/section.c',
    103          'source/patched-yasm/libyasm/strcasecmp.c',
    104          'source/patched-yasm/libyasm/strsep.c',
    105          'source/patched-yasm/libyasm/symrec.c',
    106          'source/patched-yasm/libyasm/valparam.c',
    107          'source/patched-yasm/libyasm/value.c',
    108          'source/patched-yasm/modules/arch/lc3b/lc3barch.c',
    109          'source/patched-yasm/modules/arch/lc3b/lc3bbc.c',
    110          'source/patched-yasm/modules/arch/x86/x86arch.c',
    111          'source/patched-yasm/modules/arch/x86/x86bc.c',
    112          'source/patched-yasm/modules/arch/x86/x86expr.c',
    113          'source/patched-yasm/modules/arch/x86/x86id.c',
    114          'source/patched-yasm/modules/dbgfmts/codeview/cv-dbgfmt.c',
    115          'source/patched-yasm/modules/dbgfmts/codeview/cv-symline.c',
    116          'source/patched-yasm/modules/dbgfmts/codeview/cv-type.c',
    117          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-aranges.c',
    118          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c',
    119          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-info.c',
    120          'source/patched-yasm/modules/dbgfmts/dwarf2/dwarf2-line.c',
    121          'source/patched-yasm/modules/dbgfmts/null/null-dbgfmt.c',
    122          'source/patched-yasm/modules/dbgfmts/stabs/stabs-dbgfmt.c',
    123          'source/patched-yasm/modules/listfmts/nasm/nasm-listfmt.c',
    124          'source/patched-yasm/modules/objfmts/bin/bin-objfmt.c',
    125          'source/patched-yasm/modules/objfmts/coff/coff-objfmt.c',
    126          'source/patched-yasm/modules/objfmts/coff/win64-except.c',
    127          'source/patched-yasm/modules/objfmts/dbg/dbg-objfmt.c',
    128          'source/patched-yasm/modules/objfmts/elf/elf-objfmt.c',
    129          'source/patched-yasm/modules/objfmts/elf/elf-x86-amd64.c',
    130          'source/patched-yasm/modules/objfmts/elf/elf-x86-x86.c',
    131          'source/patched-yasm/modules/objfmts/elf/elf.c',
    132          'source/patched-yasm/modules/objfmts/macho/macho-objfmt.c',
    133          'source/patched-yasm/modules/objfmts/rdf/rdf-objfmt.c',
    134          'source/patched-yasm/modules/objfmts/xdf/xdf-objfmt.c',
    135          'source/patched-yasm/modules/parsers/gas/gas-parse.c',
    136          'source/patched-yasm/modules/parsers/gas/gas-parse-intel.c',
    137          'source/patched-yasm/modules/parsers/gas/gas-parser.c',
    138          'source/patched-yasm/modules/parsers/nasm/nasm-parse.c',
    139          'source/patched-yasm/modules/parsers/nasm/nasm-parser.c',
    140          'source/patched-yasm/modules/preprocs/cpp/cpp-preproc.c',
    141          'source/patched-yasm/modules/preprocs/nasm/nasm-eval.c',
    142          'source/patched-yasm/modules/preprocs/nasm/nasm-pp.c',
    143          'source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c',
    144          'source/patched-yasm/modules/preprocs/nasm/nasmlib.c',
    145          'source/patched-yasm/modules/preprocs/raw/raw-preproc.c',
    146 
    147          # Sources needed by re2c.
    148          'source/patched-yasm/modules/parsers/gas/gas-token.re',
    149          'source/patched-yasm/modules/parsers/nasm/nasm-token.re',
    150 
    151          # Sources needed by genperf. Make sure the generated gperf files
    152          # (the ones in shared_generated_dir) are synced with the outputs
    153          # for the related generate_*_insn actions in the generate_files
    154          # target below.
    155          '<(shared_generated_dir)/x86insn_nasm.gperf',
    156          '<(shared_generated_dir)/x86insn_gas.gperf',
    157          '<(shared_generated_dir)/x86cpu.c',
    158          '<(shared_generated_dir)/x86regtmod.c',
    159       ],
    160       'include_dirs': [
    161         '<@(yasm_include_dirs)',
    162         '<(shared_generated_dir)',
    163         '<(generated_dir)',
    164       ],
    165       'defines': [ '<@(yasm_defines)' ],
    166       'cflags': [ '<@(yasm_cflags)', ],
    167       'msvs_disabled_warnings': [ 4267 ],
    168       'rules': [
    169         {
    170           'rule_name': 'generate_gperf',
    171           'extension': 'gperf',
    172           'inputs': [ '<(PRODUCT_DIR)/'
    173                       '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
    174           'outputs': [
    175             '<(generated_dir)/<(RULE_INPUT_ROOT).c',
    176           ],
    177           'action': ['<(PRODUCT_DIR)/genperf',
    178                      '<(RULE_INPUT_PATH)',
    179                      '<(generated_dir)/<(RULE_INPUT_ROOT).c',
    180           ],
    181           # These files are #included, so do not treat them as sources.
    182           'process_outputs_as_sources': 0,
    183           'message': 'yasm gperf for <(RULE_INPUT_PATH)',
    184         },
    185         {
    186           'rule_name': 'generate_re2c',
    187           'extension': 're',
    188           'inputs': [ '<(PRODUCT_DIR)/'
    189                       '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)' ],
    190           'outputs': [ '<(generated_dir)/<(RULE_INPUT_ROOT).c', ],
    191           'action': [
    192             '<(PRODUCT_DIR)/re2c',
    193             '-b',
    194             '-o',
    195             '<(generated_dir)/<(RULE_INPUT_ROOT).c',
    196             '<(RULE_INPUT_PATH)',
    197           ],
    198           'process_outputs_as_sources': 1,
    199           'message': 'yasm re2c for <(RULE_INPUT_PATH)',
    200         },
    201       ],
    202       'actions': [
    203         ###
    204         ###  genmacro calls.
    205         ###
    206         {
    207           'action_name': 'generate_nasm_macros',
    208           'variables': {
    209             'infile': 'source/patched-yasm/modules/parsers/nasm/nasm-std.mac',
    210             'varname': 'nasm_standard_mac',
    211             'outfile': '<(generated_dir)/nasm-macros.c',
    212           },
    213           'inputs': [ '<(PRODUCT_DIR)/'
    214                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
    215                       '<(infile)', ],
    216           'outputs': [ '<(outfile)', ],
    217           'action': ['<(PRODUCT_DIR)/genmacro',
    218                      '<(outfile)', '<(varname)', '<(infile)', ],
    219            # Not a direct source because this is #included by
    220            #   source/patched-yasm/modules/parsers/nasm/nasm-parser.c
    221           'process_outputs_as_sources': 1,
    222           'message': 'yasm genmacro for <(infile)',
    223         },
    224         {
    225           'action_name': 'generate_nasm_version',
    226           'variables': {
    227             'infile': '<(shared_generated_dir)/<(version_file)',
    228             'varname': 'nasm_version_mac',
    229             'outfile': '<(generated_dir)/nasm-version.c',
    230           },
    231           'inputs': [ '<(PRODUCT_DIR)/'
    232                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
    233                       '<(infile)', ],
    234           'outputs': [ '<(outfile)', ],
    235           'action': ['<(PRODUCT_DIR)/genmacro',
    236                      '<(outfile)', '<(varname)', '<(infile)',
    237           ],
    238            # Not a direct source because this is #included by
    239            #   source/patched-yasm/modules/preprocs/nasm/nasm-preproc.c
    240           'process_outputs_as_sources': 0,
    241           'message': 'yasm genmacro for <(infile)',
    242         },
    243         {
    244           'action_name': 'generate_win64_gas',
    245           'variables': {
    246             'infile': 'source/patched-yasm/modules/objfmts/coff/win64-gas.mac',
    247             'varname': 'win64_gas_stdmac',
    248             'outfile': '<(generated_dir)/win64-gas.c',
    249           },
    250           'inputs': [ '<(PRODUCT_DIR)/'
    251                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
    252                       '<(infile)', ],
    253           'outputs': [ '<(outfile)', ],
    254           'action': ['<(PRODUCT_DIR)/genmacro',
    255                      '<(outfile)', '<(varname)', '<(infile)',
    256           ],
    257            # Not a direct source because this is #included by
    258            #   source/patched-yasm/modules/objfmts/coff/coff-objfmt.c
    259           'process_outputs_as_sources': 0,
    260           'message': 'yasm genmacro for <(infile)',
    261         },
    262         {
    263           'action_name': 'generate_win64_nasm',
    264           'variables': {
    265             'infile': 'source/patched-yasm/modules/objfmts/coff/win64-nasm.mac',
    266             'varname': 'win64_nasm_stdmac',
    267             'outfile': '<(generated_dir)/win64-nasm.c',
    268           },
    269           'inputs': [ '<(PRODUCT_DIR)/'
    270                       '<(EXECUTABLE_PREFIX)genmacro<(EXECUTABLE_SUFFIX)',
    271                       '<(infile)', ],
    272           'outputs': [ '<(outfile)', ],
    273           'action': ['<(PRODUCT_DIR)/genmacro',
    274                      '<(outfile)',
    275                      '<(varname)',
    276                      '<(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         ###
    285         ###  genstring call.
    286         ###
    287         {
    288           'action_name': 'generate_license',
    289           'variables': {
    290             'infile': 'source/patched-yasm/COPYING',
    291             'varname': 'license_msg',
    292             'outfile': '<(generated_dir)/license.c',
    293           },
    294           'inputs': [ '<(PRODUCT_DIR)/'
    295                       '<(EXECUTABLE_PREFIX)genstring<(EXECUTABLE_SUFFIX)',
    296                       '<(infile)', ],
    297           'outputs': [ '<(outfile)', ],
    298           'action': ['<(PRODUCT_DIR)/genstring',
    299                      '<(varname)',
    300                      '<(outfile)',
    301                      '<(infile)',
    302           ],
    303           # Not a direct source because this is #included by
    304           #   source/patched-yasm/frontends/yasm/yasm.c
    305           'process_outputs_as_sources': 0,
    306           'message': 'Generating yasm embeddable license',
    307         },
    308 
    309         ###
    310         ###  A re2c call that doesn't fit into the rule below.
    311         ###
    312         {
    313           'action_name': 'generate_lc3b_token',
    314           'variables': {
    315             'infile': 'source/patched-yasm/modules/arch/lc3b/lc3bid.re',
    316             # The license file is #included by yasm.c.
    317             'outfile': '<(generated_dir)/lc3bid.c',
    318           },
    319           'inputs': [ '<(PRODUCT_DIR)/'
    320                       '<(EXECUTABLE_PREFIX)re2c<(EXECUTABLE_SUFFIX)',
    321                       '<(infile)', ],
    322           'outputs': [ '<(outfile)', ],
    323           'action': [
    324             '<(PRODUCT_DIR)/re2c',
    325             '-s',
    326             '-o', '<(outfile)',
    327             '<(infile)'
    328           ],
    329           'process_outputs_as_sources': 1,
    330           'message': 'Generating yasm tokens for lc3b',
    331         },
    332 
    333         ###
    334         ###  genmodule call.
    335         ###
    336         {
    337           'action_name': 'generate_module',
    338           'variables': {
    339             'makefile': 'source/config/<(OS)/Makefile',
    340             'module_in': 'source/patched-yasm/libyasm/module.in',
    341             'outfile': '<(generated_dir)/module.c',
    342           },
    343           'inputs': [
    344             '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)genmodule<(EXECUTABLE_SUFFIX)',
    345             '<(module_in)',
    346             '<(makefile)'
    347           ],
    348           'outputs': [ '<(generated_dir)/module.c' ],
    349           'action': [
    350             '<(PRODUCT_DIR)/genmodule',
    351             '<(module_in)',
    352             '<(makefile)',
    353             '<(outfile)'
    354           ],
    355           'process_outputs_as_sources': 1,
    356           'message': 'Generating yasm module information',
    357         },
    358       ],
    359     },
    360     {
    361       'target_name': 'config_sources',
    362       'type': 'none',
    363       'toolsets': ['host'],
    364       'sources': [
    365         'source/config/<(OS)/Makefile',
    366         'source/config/<(OS)/config.h',
    367         'source/config/<(OS)/libyasm-stdint.h',
    368       ],
    369     },
    370     {
    371       'target_name': 'generate_files',
    372       'type': 'none',
    373       'toolsets': ['host'],
    374       'dependencies': [
    375         'genperf',
    376         'genversion',
    377       ],
    378       'sources': [
    379          'source/patched-yasm/modules/arch/x86/x86cpu.gperf',
    380          'source/patched-yasm/modules/arch/x86/x86regtmod.gperf',
    381       ],
    382       'rules': [
    383         {
    384           'rule_name': 'generate_gperf',
    385           'extension': 'gperf',
    386           'inputs': [ '<(PRODUCT_DIR)/'
    387                       '<(EXECUTABLE_PREFIX)genperf<(EXECUTABLE_SUFFIX)' ],
    388           'outputs': [ '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c', ],
    389           'action': [
    390             '<(PRODUCT_DIR)/genperf',
    391             '<(RULE_INPUT_PATH)',
    392             '<(shared_generated_dir)/<(RULE_INPUT_ROOT).c',
    393           ],
    394           'process_outputs_as_sources': 0,
    395           'message': 'yasm genperf for <(RULE_INPUT_PATH)',
    396         },
    397       ],
    398       'actions': [
    399         {
    400           'action_name': 'generate_x86_insn',
    401           'variables': {
    402             'gen_insn_path':
    403                 'source/patched-yasm/modules/arch/x86/gen_x86_insn.py',
    404           },
    405           'inputs': [ '<(gen_insn_path)', ],
    406           'outputs': [
    407             '<(shared_generated_dir)/x86insns.c',
    408             '<(shared_generated_dir)/x86insn_gas.gperf',
    409             '<(shared_generated_dir)/x86insn_nasm.gperf',
    410           ],
    411           'action': [
    412             'python',
    413             '<(gen_insn_path)',
    414             '<(shared_generated_dir)',
    415           ],
    416           'message': 'Running <(gen_insn_path)',
    417           'process_outputs_as_sources': 0,
    418         },
    419         {
    420           'action_name': 'generate_version',
    421           'inputs': [ '<(PRODUCT_DIR)/'
    422                       '<(EXECUTABLE_PREFIX)genversion<(EXECUTABLE_SUFFIX)' ],
    423           'outputs': [ '<(shared_generated_dir)/<(version_file)', ],
    424           'action': [
    425             '<(PRODUCT_DIR)/genversion',
    426             '<(shared_generated_dir)/<(version_file)'
    427           ],
    428           'message': 'Generating yasm version file: '
    429                      '<(shared_generated_dir)/<(version_file)',
    430           'process_outputs_as_sources': 0,
    431         },
    432       ],
    433     },
    434     {
    435       'target_name': 'genperf_libs',
    436       'type': 'static_library',
    437       'toolsets': ['host'],
    438       'dependencies': [ 'config_sources', ],
    439       'sources': [
    440          'source/patched-yasm/libyasm/phash.c',
    441          'source/patched-yasm/libyasm/xmalloc.c',
    442          'source/patched-yasm/libyasm/xstrdup.c',
    443       ],
    444       'include_dirs': [
    445         '<@(yasm_include_dirs)',
    446       ],
    447       'defines': [ '<@(yasm_defines)' ],
    448       'cflags': [
    449         '<@(yasm_cflags)',
    450       ],
    451     },
    452     {
    453       'target_name': 'genstring',
    454       'type': 'executable',
    455       'toolsets': ['host'],
    456       'dependencies': [ 'config_sources', ],
    457       'sources': [
    458          'source/patched-yasm/genstring.c',
    459       ],
    460       'include_dirs': [
    461         '<@(yasm_include_dirs)',
    462       ],
    463       'cflags': [
    464         '-std=gnu99',
    465       ],
    466     },
    467     {
    468       'target_name': 'genperf',
    469       'type': 'executable',
    470       'toolsets': ['host'],
    471       'dependencies': [
    472         'genperf_libs',
    473       ],
    474       'sources': [
    475          'source/patched-yasm/tools/genperf/genperf.c',
    476          'source/patched-yasm/tools/genperf/perfect.c',
    477       ],
    478       'include_dirs': [
    479         '<@(yasm_include_dirs)',
    480       ],
    481       'cflags': [
    482         '-std=gnu99',
    483       ],
    484     },
    485     {
    486       'target_name': 'genmacro',
    487       'type': 'executable',
    488       'toolsets': ['host'],
    489       'dependencies': [ 'config_sources', ],
    490       'sources': [
    491         'source/patched-yasm/tools/genmacro/genmacro.c',
    492       ],
    493       'include_dirs': [
    494         '<@(yasm_include_dirs)',
    495       ],
    496       'cflags': [
    497         '-std=gnu99',
    498       ],
    499     },
    500     {
    501       'target_name': 'genversion',
    502       'type': 'executable',
    503       'toolsets': ['host'],
    504       'dependencies': [ 'config_sources', ],
    505       'sources': [
    506          'source/patched-yasm/modules/preprocs/nasm/genversion.c',
    507       ],
    508       'include_dirs': [
    509         '<@(yasm_include_dirs)',
    510       ],
    511       'cflags': [
    512         '-std=gnu99',
    513       ],
    514     },
    515     {
    516       'target_name': 're2c',
    517       'type': 'executable',
    518       'toolsets': ['host'],
    519       'dependencies': [ 'config_sources', ],
    520       'sources': [
    521          'source/patched-yasm/tools/re2c/main.c',
    522          'source/patched-yasm/tools/re2c/code.c',
    523          'source/patched-yasm/tools/re2c/dfa.c',
    524          'source/patched-yasm/tools/re2c/parser.c',
    525          'source/patched-yasm/tools/re2c/actions.c',
    526          'source/patched-yasm/tools/re2c/scanner.c',
    527          'source/patched-yasm/tools/re2c/mbo_getopt.c',
    528          'source/patched-yasm/tools/re2c/substr.c',
    529          'source/patched-yasm/tools/re2c/translate.c',
    530       ],
    531       'include_dirs': [
    532         '<@(yasm_include_dirs)',
    533       ],
    534       'cflags': [
    535         '-std=gnu99',
    536       ],
    537       'variables': {
    538           # re2c is missing CLOSEVOP from one switch.
    539         'clang_warning_flags': [ '-Wno-switch' ],
    540       },
    541       'msvs_disabled_warnings': [ 4267 ],
    542     },
    543     {
    544       'target_name': 'genmodule',
    545       'type': 'executable',
    546       'toolsets': ['host'],
    547       'dependencies': [
    548         'config_sources',
    549       ],
    550       'sources': [
    551         'source/patched-yasm/libyasm/genmodule.c',
    552       ],
    553       'include_dirs': [
    554         '<@(yasm_include_dirs)',
    555 
    556       ],
    557       'cflags': [
    558         '-std=gnu99',
    559       ],
    560     },
    561   ],
    562 }
    563