解释 makefile % 以及 $<和$@
xpi_built := $(build_dir)/$(install_rdf) \
$(build_dir)/$(chrome_manifest) \
$(chrome_jar_file) \
$(default_prefs)
xpi_built_no_dir := $(subst $(build_dir)/,,$(xpi_built))
$(xpi_file): $(build_dir) $(xpi_built)
@echo "Creating XPI file."
cd $(build_dir); $(ZIP) ../$(xpi_file) $(xpi_built_no_dir)
@echo "Creating XPI file. Done!"
$(build_dir)/%: %
cp -f $< $@
$(build_dir):
@if [ ! -x $(build_dir) ]; \
then \
mkdir $(build_dir); \
fi
谁能给我解释一下这个 makefile 部分吗?对
$(build_dir)/%: %
以及$<
和$@
指令- 两个标签
$(build_dir )
存在,我猜两者都执行了,但是按什么顺序执行?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个静态模式规则,在其命令中使用自动变量;
$<
扩展到最左边的先决条件,$@
扩展到目标。如果您尝试创建$(build_dir)/foo
(无论$(build_dir)
是什么),Make 会将此规则视为下一个规则,
适用于
$ (build_dir)
本身,并且不必要地复杂。它说“如果$(build_dir)
不存在,则 mkdir 它”,可以这样写:看起来您的主要目标是
$(xpi_file):
因此,Make 将首先创建
$(build_dir)
(如果需要),然后创建列表的成员%(xpi_built)
,其中包括形式$(build_dir)/%
。一旦完成这些,它将执行此规则的命令:它将 cd 到 $(build_dir) ,压缩一些内容,并回显一些消息。This is a static pattern rule which uses automatic variables in its command;
$<
expands to the leftmost prerequisite,$@
expands to the target. If you try to make$(build_dir)/foo
(whatever$(build_dir)
is), Make will treat this rule asThe next rule,
is for
$(build_dir)
itself, and is unnecessarily complicated. It says "if$(build_dir)
doesn't exist, then mkdir it", and it could be written this way:It looks as if your primary target is
$(xpi_file)
:So Make will first make
$(build_dir)
(if necessary), then the members of the list%(xpi_built)
, which includes a couple of things of the form$(build_dir)/%
. Once those are done, it will execute the commands of this rule: it will cd into$(build_dir)
, zip some things up, andecho
a couple of messages.请参阅模式规则和自动变量。第一条规则匹配
$(build_dir)
内部的文件,而不是$(build_dir)
本身。$<
扩展为当前规则的先决条件列表,$@
是当前规则的目标。See Pattern Rules and Automatic Variables in the GNU make documentation. The first rule matches files inside
$(build_dir)
, not$(build_dir)
itself.$<
expands to the list of prerequisites of the current rule,$@
is the target for the current rule.