コード例 #1
0
def build_examples(env, work_queue):
    """Build the examples"""
    example_exes = []
    env['example_exes'] = []  # used by install
    examples_dag = mbuild.dag_t('xedexamples', env=env)

    if not env.on_windows():
        for d in env['example_rpaths']:
            env.add_to_var('example_linkflags', '-Wl,-rpath,{}'.format(d))
    env.add_to_var('LINKFLAGS', env['example_linkflags'])
    # put the examples in their own subdirectory
    env['build_dir'] = mbuild.join(env['build_dir'], 'examples')
    mbuild.cmkdir(env['build_dir'])

    link_libxed = env['link_libxed']

    if env['shared']:
        _add_libxed_rpath(env)

    # C vs C++: env is for C++ and env_c is for C programs.
    if env['compiler'] in ['gnu', 'clang', 'icc']:
        env['LINK'] = env['CXX']
    env_c = copy.deepcopy(env)
    if env_c['compiler'] in ['gnu', 'clang']:
        env_c['LINK'] = '%(CC)s'

    if env['pin_crt']:
        xbc.compile_with_pin_crt_lin_mac_common_cplusplus(env)

    # shared files
    cc_shared_files = env.src_dir_join(['xed-examples-util.c'])
    if env['decoder']:
        cc_shared_files.extend(
            env.src_dir_join(['xed-dot.c', 'xed-dot-prep.c']))

    if env['encoder']:
        cc_shared_files += env.src_dir_join(['xed-enc-lang.c'])
    cc_shared_objs = env.compile(examples_dag, cc_shared_files)
    # the XED command line tool
    xed_cmdline_files = [
        'xed-disas-raw.c', 'avltree.c', 'xed-disas-hex.c', 'xed-symbol-table.c'
    ]
    if env.on_windows() and env['set_copyright']:
        xed_cmdline_files.append("xed.rc")
    extra_libs = []
    if env['decoder']:

        if env.on_linux() or env.on_freebsd() or env.on_netbsd():
            xed_cmdline_files.append('xed-disas-elf.c')

        elif env.on_mac():
            xed_cmdline_files.append('xed-disas-macho.c')

        elif env.on_windows():
            xed_cmdline_files.append('xed-disas-pecoff.cpp')
            if (env['dbghelp'] and env['msvs_version'] not in ['6', '7']):
                env.add_define("XED_DBGHELP")
                xed_cmdline_files.append('udhelp.cpp')
                extra_libs = ['dbghelp.lib', 'version.lib']

    xed_cmdline_files = env.src_dir_join(xed_cmdline_files)
    xed_cmdline_obj = copy.deepcopy(cc_shared_objs)

    # Env for cmdline tool (with libelf/dwarf on linux.)
    if env.on_windows():  # still C++
        cenv = copy.deepcopy(env)
    else:  # lin/mac are C code only.
        cenv = copy.deepcopy(env_c)

    if env.on_linux():
        xbc.cond_add_elf_dwarf(cenv)

    xed_cmdline_obj += cenv.compile(examples_dag, xed_cmdline_files)

    xed_cmdline = ex_compile_and_link(
        cenv, examples_dag, env.src_dir_join('xed.c'),
        xed_cmdline_obj + [link_libxed] + extra_libs)
    mbuild.msgb("CMDLINE", xed_cmdline)
    example_exes.append(xed_cmdline)

    ild_examples = []
    other_c_examples = []
    small_examples = ['xed-size.c']
    if env['encoder']:
        small_examples += ['xed-ex5-enc.c']
        other_c_examples += ['xed-ex3.c']
    if env['decoder'] and env['encoder']:
        other_c_examples += ['xed-ex6.c']
    if env['decoder']:
        ild_examples += ['xed-ex-ild.c']
        other_c_examples += [
            'xed-ex1.c', 'xed-ex-ild2.c', 'xed-min.c', 'xed-reps.c',
            'xed-ex4.c', 'xed-tester.c', 'xed-dec-print.c', 'xed-ex-agen.c',
            'xed-ex7.c', 'xed-ex8.c', 'xed-ex-cpuid.c', 'xed-tables.c',
            'xed-dll-discovery.c'
        ]

    # compile & link other_c_examples
    for example in env.src_dir_join(other_c_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example,
                                cc_shared_objs + [link_libxed]))
    # compile & link ild_examples
    for example in env.src_dir_join(ild_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example,
                                [env['link_libild']]))

    # compile & link small_examples
    for example in env.src_dir_join(small_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example, [link_libxed]))
    if mbuild.verbose(3):
        mbuild.msgb("ALL EXAMPLES", "\n\t".join(example_exes))

    examples_to_build = example_exes
    env['example_exes'] = example_exes

    mbuild.msgb("BUILDING EXAMPLES")
    okay = work_queue.build(examples_dag,
                            targets=examples_to_build,
                            die_on_errors=env['die_on_errors'],
                            show_progress=True,
                            show_output=True,
                            show_errors_only=_wk_show_errors_only())
    if not okay:
        xbc.cdie("XED EXAMPLES build failed")
    if mbuild.verbose(2):
        mbuild.msgb("XED EXAMPLES", "build succeeded")
    return 0
コード例 #2
0
def build_examples(env, work_queue):
    """Build the examples"""
    example_exes = [] 
    env['example_exes'] = []  # used by install
    examples_dag = mbuild.dag_t('xedexamples', env=env)
    
    if not env.on_windows():
        for d in env['example_rpaths']:
            env.add_to_var('example_linkflags',
                                   '-Wl,-rpath,{}'.format(d))
    env.add_to_var('LINKFLAGS', env['example_linkflags'])
    env.add_to_var('CCFLAGS', env['example_flags'])
    env.add_to_var('CXXFLAGS', env['example_flags'])
    mbuild.cmkdir(env['build_dir'])

    link_libxed = env['link_libxed']
    
    if env['shared']:
       _add_libxed_rpath(env)

    # C vs C++: env is for C++ and env_c is for C programs.
    if env['compiler'] in  ['gnu','clang', 'icc']:
        env['LINK'] = env['CXX']
    env_c = copy.deepcopy(env)
    if env_c['compiler'] in ['gnu','clang']:
        env_c['LINK'] = '%(CC)s'
        
    if env['pin_crt']:
        xbc.compile_with_pin_crt_lin_mac_common_cplusplus(env)
    
    # shared files
    cc_shared_files = env.src_dir_join([ 
          'xed-examples-util.c'])
    if env['decoder']:
        cc_shared_files.extend(env.src_dir_join([ 
          'xed-dot.c',
          'xed-dot-prep.c']))
        
    if env['encoder']:
       cc_shared_files += env.src_dir_join([ 'xed-enc-lang.c'])
    cc_shared_objs  = env.compile( examples_dag, cc_shared_files)
    # the XED command line tool
    xed_cmdline_files = [ 'xed-disas-raw.c',
                          'avltree.c',
                          'xed-disas-hex.c',
                          'xed-symbol-table.c']
    if env.on_windows() and env['set_copyright']:
        # AUTOMATICALLY UPDATE YEAR IN THE RC FILE
        year = time.strftime("%Y")
        lines = open(env.src_dir_join('xed-rc-template.txt')).readlines()
        lines = [ re.sub('%%YEAR%%',year,x) for x in lines ]
        xbc.write_file(env.src_dir_join('xed.rc'), lines)
        xed_cmdline_files.append("xed.rc")
        
    extra_libs = []    
    if env['decoder']:

        if env.on_linux() or env.on_freebsd() or env.on_netbsd():
            xed_cmdline_files.append('xed-disas-filter.c')
            xed_cmdline_files.append('xed-nm-symtab.c')
            
        elif env.on_mac():
            xed_cmdline_files.append('xed-disas-macho.c')

        elif env.on_windows():
            xed_cmdline_files.append('xed-disas-pecoff.cpp')
            if ( env['dbghelp'] and 
                 env['msvs_version'] not in ['6','7'] ):
                env.add_define("XED_DBGHELP")
                xed_cmdline_files.append('udhelp.cpp')
                extra_libs = ['dbghelp.lib', 'version.lib' ]

    xed_cmdline_files = env.src_dir_join(xed_cmdline_files)
    xed_cmdline_obj = copy.deepcopy(cc_shared_objs)

    # Env for cmdline tool (with libelf/dwarf on linux.)
    if env.on_windows():  # still C++
        cenv = copy.deepcopy(env)
    else: # lin/mac are C code only.
        cenv = copy.deepcopy(env_c)
        
    if env.on_linux():
        xbc.cond_add_elf_dwarf(cenv)
        
    if env.on_linux() or env.on_freebsd() or env.on_netbsd():
        src_elf = env.src_dir_join('xed-disas-elf.c')
        if env['use_elf_dwarf_precompiled']:
            cenv2 = copy.deepcopy(cenv)
            # need to remove -pedantic because of redundant typedef Elf in dwarf header file
            cenv2.remove_from_var('CCFLAGS','-pedantic')
            xed_cmdline_obj += cenv2.compile(examples_dag, [src_elf])
        else:
            xed_cmdline_files.append(src_elf)
            
    xed_cmdline_obj += cenv.compile(examples_dag, xed_cmdline_files)
    xed_cmdline = ex_compile_and_link(cenv, examples_dag,
                                      env.src_dir_join('xed.c'),
                                      xed_cmdline_obj + [link_libxed] +
                                      extra_libs)

    mbuild.msgb("CMDLINE", xed_cmdline)
    example_exes.append(xed_cmdline)

    if env['encoder']:
        exe = build_asmparse(cenv, examples_dag, cc_shared_objs)
        example_exes.append(exe)
        

    ild_examples = []
    other_c_examples = []
    enc2_examples = []
    small_examples = ['xed-size.c']
    if env['enc2']:
        enc2_examples += [ 'xed-enc2-1.c',
                           'xed-enc2-2.c',
                           'xed-enc2-3.c' ]
    if env['encoder']:
       small_examples += ['xed-ex5-enc.c']
       other_c_examples += ['xed-ex3.c']
    if env['decoder'] and env['encoder']:
       other_c_examples += ['xed-ex6.c',
                            'xed-ex9-patch.c' ]
    if env['decoder']:
       ild_examples += [ 'xed-ex-ild.c' ]
       other_c_examples += ['xed-ex1.c',
                            'xed-ex-ild2.c',
                            'xed-min.c',
                            'xed-reps.c',
                            'xed-ex4.c',
                            'xed-tester.c',
                            'xed-dec-print.c',           
                            'xed-ex-agen.c',
                            'xed-ex7.c',
                            'xed-ex8.c',
                            'xed-ex-cpuid.c',
                            'xed-tables.c',
                            'xed-find-special.c',                            
                            'xed-dll-discovery.c']

    # compile & link other_c_examples
    for example in env.src_dir_join(other_c_examples):
        example_exes.append(ex_compile_and_link(env_c,
                                                examples_dag,
                                                example,
                                                cc_shared_objs + [ link_libxed ]))
    # compile & link ild_examples
    if os.path.exists(env['link_libild']):
        for example in env.src_dir_join(ild_examples):
            example_exes.append(ex_compile_and_link(env_c,
                                                    examples_dag,
                                                    example,
                                                    [ env['link_libild'] ]))
            
    # compile & link small_examples
    for example in env.src_dir_join(small_examples):
        example_exes.append(ex_compile_and_link(env_c,
                                                examples_dag,
                                                example,
                                                [ link_libxed ]))
    
    for example in env.src_dir_join(enc2_examples):
        example_exes.append(ex_compile_and_link(  env_c,
                                                  examples_dag,
                                                  example,
                                                  env['xed_enc2_libs'] + [link_libxed]  ))

    mbuild.vmsgb(4, "ALL EXAMPLES", "\n\t".join(example_exes))

    examples_to_build   = example_exes
    env['example_exes'] = example_exes
    
    mbuild.msgb("BUILDING EXAMPLES")
    okay = work_queue.build(examples_dag,
                            targets=examples_to_build,
                            die_on_errors=env['die_on_errors'],
                            show_progress=True, 
                            show_output=True,
                            show_errors_only=_wk_show_errors_only())
    if not okay:
        xbc.cdie( "XED EXAMPLES build failed")
    mbuild.vmsgb(3, "XED EXAMPLES", "build succeeded")
    return 0