如何使用自定义任务创建的静态库?

时间:2012-08-16 12:29:53

标签: waf

我想用waf触发makefile来构建另一个库。为此,我创建了以下任务:

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'
    )    

1 个答案:

答案 0 :(得分:4)

为了最终解决问题,我创建了一个on link任务,基本上什么都不做(类似于ccroot.py中的假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",
    )