使用 makefile 中的 filter 来运行其他 make 目标。

huangapple go评论39阅读模式
英文:

Using filter in makefile to run other make targets

问题

我正在尝试简化我的makefile,允许使用过滤器(%)的目标来捕获我希望其他目标具有扩展操作的时机。

一个示例是:

1-check:
  echo "1"

2-check:
  echo "2"

run-check:
  1-check-all 2-check-all

%-all:
  echo $*

这能够打印出2个目标的名称,分别为1-check和2-check。我原本期望,如果我在%-all中去掉echo,它会运行捕获的目标。

当我调用1-check-all时,我期望修改后的%-all - 如下所示 - 会调用该方法:

%-all:
  $*

这时$*的值将是"1-check",然后运行该目标,我会看到"echo 1"被执行。

我对makefile还不够了解,尚未找到类似这样做的示例。

英文:

I am trying to simplify my makefile by allowing a target with a filter (%) to capture when I want other targets to have expanded actions

An example of this would be

1-check: 
  echo "1"

2-check:
  echo "2"

run-check: 
  1-check-all 2-check-all

%-all: 
  echo $*

This is able to print the 2 targets names as 1-check and 2-check and I was expecting that if I remove the echo in %-all it would run the captured target

What I would expect when I call 1-check-all is that the modified %-all - seen below - it would invoke the method

%-all: 
  $*

Would have "1-check" as the value of $* and it would then run that target and I would see "echo 1" executed.

I am new to makefiles and haven't been able to find an example doing something similar to this.

答案1

得分: 1

以下是翻译的部分:

一些问题。这个:

%-all: 
  $*

在你的 makefile 中并不存在。最接近的是这个:

%-all: 
    echo $*

但是这两者都不会调用另一个规则。为了达到我认为你想要的效果,你必须将%列为规则的先决条件

%-all: %
    echo $*
英文:

A couple of problems. This:

%-all: 
  $*

does not appear in your makefile. The nearest thing to it is this:

%-all: 
    echo $*

But neither of these will invoke another rule. To get the effect I think you want, you must list % as a prerequisite of the rule:

%-all: %
    echo $*

huangapple
  • 本文由 发表于 2023年2月10日 09:56:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定