[英]Downloading files with Makefile rules
I was planning something like: 我正在计划类似:
URLS=www.host.com/file1.tar.gz www.host2.com/file2.tar.gz
$(somefunc $URLS): #somefunc produces downloads/file1.tar.gz downloads/file2.tar.gz
mkdir -P downloads
wget whatever # I can't get the real url here because the targets don't contain the full url anymore
myproject: $(somefunc URLS)
#Files should already be in downloads/ here
The problem I have is that if I convert URLS with somefunc I lose the urls, if I don't I can't use it as a target to avoid being downloaded when it is already there. 我的问题是,如果我用somefunc转换URL,我会丢失URL,如果不这样做,我就不能将其用作目标,以避免已经存在时被下载。
Any ideas? 有任何想法吗?
If somefunc
only modifies the path, not the actual filename, and there are no duplicates, you could try searching $(URLS)
for the original filename. 如果somefunc
仅修改路径,而不修改实际文件名,并且没有重复项,则可以尝试在$(URLS)
搜索原始文件名。
Maybe something like this? 也许是这样的吗? (untested) (未试)
$(somefunc $URLS): #somefunc produces downloads/file1.tar.gz downloads/file2.tar.gz
mkdir -p $(dir $@)
wget $(filter $(addprefix %/,$(notdir $@)),$(URLS)) -O $@
$(notdir $@)
evaluates to file1.tar.gz
for one of the targets. $(notdir $@)
对目标之一求值为file1.tar.gz
。 $(addprefix %/,file1.tar.gz)
evaluates to %/file1.tar.gz
$(addprefix %/,file1.tar.gz)
计算结果为%/file1.tar.gz
$(filter %/file1.tar.gz,www.host.com/file1.tar.gz www.host2.com/file2.tar.gz)
evaluates to www.host.com/file1.tar.gz
. $(filter %/file1.tar.gz,www.host.com/file1.tar.gz www.host2.com/file2.tar.gz)
计算结果为www.host.com/file1.tar.gz
。 (Presumably you want an http://
on there too?) (想必您也想要http://
吗?)
At this point, I don't think you can do it directly with make. 在这一点上,我认为您不能直接使用make进行操作。 But here's a solution if you are willing to use some scripting: 但是,如果您愿意使用一些脚本,这是一个解决方案:
$(URLS):
@for url in ${URLS}; do \
if [ ! -e $$(somefunc $${url}) ]; then \
echo wget $${url}; \
wget $${url}; \
fi \
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.