使配方执行两次 [英] make recipe execute twice

查看:56
本文介绍了使配方执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以多次执行配方? 在下面的SSCCE中,该配方仅执行一次:

Is there a way to execute a recipe more than once? In the SSCCE below it appears that the recipe is executed only once:

$ cat Makefile 
.PHONY: a b
a: b b 
b:
    echo "beta"
$ make 
echo "beta"
beta

推荐答案

一旦您阅读并理解了注释;-),我可以想到两种方法来运行两次配方:

Once you've read and understood the comments ;-), there are two ways I can think of to run a recipe twice:

@OliCharlesworth提到了第一个-在配方内使用循环:

@OliCharlesworth mentions the first - use a loop inside your recipe:

.PHONY: a b
a: b b
b:
    for i in 1 2; do \
        echo "beta" ;\
    done

请注意,在配方中嵌入多行shell表达式时需要非常小心.除非您使用反斜杠终止行,否则make会将每行视为单独的shell调用,这对于循环无效.

Note you need to be quite careful when embedding multi-line shell expressions in recipes. Unless you terminate lines with backslashes, make will treat each line as a separate shell invocation, which wouldn't work for a loop.

另一种方法是复制b目标,以便两个副本具有相同的配方:

The other way is to duplicate your b target, so that both copies have the same recipe:

.PHONY: a b1 b2
a: b1 b2
b1 b2:
    echo "beta"

这用相同的配方定义了b1b2目标.然后a取决于b1b2,因此该配方被调用两次.请注意,不能保证b1b2的调用顺序-如果您的-j因子大于1,则很可能会同时调用它们.

This defines the b1 and b2 targets with the same recipe. Then a depends on both b1 and b2, so the recipe gets called twice. Note that there is no guarantee of the order in which b1 and b2 will be invoked - and they'll likely be invoked concurrently if you have a -j factor greater than 1.

这篇关于使配方执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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