2

我想使用 waf 触发生成文件来构建其他库。为此,我创建了以下任务:

def build(bld):
    def run(self):
        bld_dir = self.generator.bld.path.get_bld()
        src_dir = self.inputs[0].parent
        tgt = self.outputs[0]
        tgt_dir = bld_dir.make_node(os.path.splitext(tgt.name)[0])
        cmd = 'BUILDDIR="{tgt_dir}" make config gdb=1 debug=1 cc={cc} && BUILDDIR="    {tgt_dir}" make'.format(
        tgt_dir = tgt_dir.abspath(),
        cc = self.env.get_flat("CC"))
        self.exec_command(cmd, cwd=src_dir.abspath())
        return self.exec_command(['cp', lib.abspath(), tgt.abspath()],
                                 cwd=tgt_dir.abspath())

    bld(
            rule = run,
            source = "Makefile",
            target = 'metis',
    )

如何告诉 waf 该任务创建了一个静态库,以便我可以在 use 关键字中使用“metis”:

    bld(
            features = "cxx cxxprogramm"
            source = "main.cpp",
            target = 'main',
            use = 'metis'
    )    
4

1 回答 1

4

为了最终解决我在link_task上创建的问题,它基本上什么都不做(类似于ccroot.py中的fake_lib):

from waflib.TaskGen import feature, after_method
from waflib.Tools.ccroot import stlink_task

class custom_stlib(stlink_task):
    """ Dummy link task """
    pass

@feature("custom_stlib")
def custom_lib(self):
    self.env['custom_stlib_PATTERN']    = 'lib%s.a'
    self.link_task = self.create_task('custom_stlib', [])
    self.link_task.add_target(self.target)


def build(bld):
    # ...
    bld(
            features = "cxx custom_stlib",
            target = 'metis',
            after = "metis_bld",
    )
于 2012-08-17T07:20:08.597 回答