作为构建过程的一部分,Make会创建多个.tgz
文件:
blah_1.tgz blah_2.tgz .... blah_n.tgz
如何在每个文件上调用另一个命令(例如rsync
)?
在bash,我会:
for file in `ls *.tgz`' do rsync $file DESTINATION; done
或者:
ls | grep tgz | xargs rsync {} DESTINATION
但熟悉的bash语法似乎不符合Make。有什么想法吗?
答案 0 :(得分:1)
嗯......这样的事情应该有效:
TGZ_FILES := blah_1.tgz blah_2.tgz .... blah_n.tgz
RSYNC_TARGETS := $(TGZ_FILES:%=rsync-%)
all : $(RSYNC_TARGETS)
.PHONY : $(RSYNC_TARGETS)
$(RSYNC_TARGETS) : rsync-% : %
rsync $* DESTINATION
# Omit the following rule
# if .tgz files are made somewhere else (outside Make),
# and you assume they are always up-to-date
$(TGZ_FILES) : %.tgz : ...
# rule to make each .tgz file
此示例使用GNU Make的以下功能:
$(TGZ_FILES:%=rsync-%)
)$(RSYNC_TARGETS) : rsync-% : %
).PHONY : $(RSYNC_TARGETS)
)$*
)