make:规则调用规则 [英] make : rule call rule

查看:72
本文介绍了make:规则调用规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在makefile中,我可以从另一个规则中调用一个规则吗?

In a makefile, can I call a rule from another rule?

类似于:

rule1:
        echo "bye"
rule2:
        date
rule3:
        @echo "hello"
        rule1

推荐答案

可以使用依赖关系或递归方法将一条规则连接到另一条规则.

Either use dependencies or recursive making to connect from one rule to another.

依存关系将这样完成(尽管顺序会有所不同):

Dependencies would be done like this (though the order will be different):

rule1:
        echo "bye"
rule2:
        date
rule3: rule1
        @echo "hello"

递归生成将像这样完成(尽管它确实涉及一个子过程):

Recursive make would be done like this (though it does involve a subprocess):

rule1:
        echo "bye"
rule2:
        date
rule3:
        @echo "hello"
        $(MAKE) rule1

都不是完美的.实际上,使用递归可使您在构建循环时遇到重大问题.您可能还应该添加.PHONY规则,以将上述规则标记为合成规则,以便目录中的流浪rule1(等)不会引起混淆.

Neither is perfect; indeed, with recursive make you can get into significant problems if you build a loop. You also probably ought to add a .PHONY rule so as to mark those rules above as synthetic, so that a stray rule1 (etc.) in the directory won't cause confusion.

这篇关于make:规则调用规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆