make:依赖项中的文本函数
学习make,在下面的Makefile中,如何将%.tar.bz2
的依赖定义为somefile.tar.bz2
?
它会是这样的: %.tar.bz2: $(function_to_cut_from_end_till_/ %.tar.bz2)
但我找不到如何在 man make
中做到这一点。
我是否从错误的角度处理这个问题?
source=http://example.net/somefile.tar.bz2
source:=$(subst :,\:,$(source))
.PHONY: download
download: $(source)
%.tar.bz2:
@wget "$@"
Learning make, In the following Makefile, how can I define the dependancy of %.tar.bz2
to be somefile.tar.bz2
?
It would be something like:%.tar.bz2: $(function_to_cut_from_end_till_/ %.tar.bz2)
But I couldn't find how to do it in man make
.
Am I approaching this from the wrong side?
source=http://example.net/somefile.tar.bz2
source:=$(subst :,\:,$(source))
.PHONY: download
download: $(source)
%.tar.bz2:
@wget "$@"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取
%.tar.bz2
规则的命令中目标名称的文件名部分,您可以使用 notdir 函数,或 $(@D) 变量 。但实际上,您应该使目标名称与输出文件匹配,以便 make 可以检查文件是否存在,并且不会在每次运行时尝试重新下载它。一种简单的方法是
,或者,如果您有不同的源档案要从不同的位置下载(我想您会这样做,否则为什么要费心使用模板规则呢?),您可以使用 目标特定变量 来存储下载 URL,如下所示
To get the filename part of the target name inside the commands of the
%.tar.bz2
rule, you could use the notdir function, or the $(@D) variable.Really, though, you should make the target name match the output file, so that
make
can check for existence of the file, and won't try to download it anew each time you run it. A simple way to do that would beor, if you have different source archives to download from different locations (which I imagine you do, otherwise why bother with a template rule at all?), you could use a target-specific variable to store the download URL, like this
好吧,没有理由太复杂 - 虽然可能可以做到这一点,但这样做不是更具可读性吗:
然后文件名就在那里可以使用
您也可以尝试
哪个应该删除直到最后的所有内容来自
$(source)
的正斜杠Well, no reason to be too complicated - while it might be possible to do that, wouldn't it be much more readable to do this:
Then the filename is right there to use
You could also try
Which should remove everything up to the last forward slash from
$(source)