根据输入的位置定制目标

发布于 2025-01-19 20:43:50 字数 465 浏览 2 评论 0原文

是否有像 $@ 这样的变量,它包含需要当前目标的目标而不是当前目标?下面是我正在寻找的功能类型的简单示例。基本上,“make foo”将创建一个目录 foo,“make bar”将创建 bar 并“make Both”。到目前为止,我还没有找到任何可以实现这种定制的东西。

foo: foobar
    do stuff
bar: foobar
    do other stuff
both: foo bar
    ....

foobar:
    mkdir <foo or bar>

找到了一种解决方案,模式规则。

foo: from_foo
    @echo "This is foo"
from_%:
    @echo "Called from $(lastword $(subst _, ,$@))"
    @echo "Simpler version... $*"

Is there a variable like $@ which would contain instead of current target the target which required current target? Below is a simple example of what kind of functionality I am looking for. Basically "make foo" would create a directory foo, "make bar" would create bar and "make both" both. So far I haven't found anything which would enable this kind of customization.

foo: foobar
    do stuff
bar: foobar
    do other stuff
both: foo bar
    ....

foobar:
    mkdir <foo or bar>

Found one solution, pattern rules.

foo: from_foo
    @echo "This is foo"
from_%:
    @echo "Called from $(lastword $(subst _, ,$@))"
    @echo "Simpler version... $*"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文