makefile 对目标的内部调用
如何在 makefile 中区分哪些目标以及如何(何时)内部调用它们?我有一个 makefile,其中包含实际上是变量的目标数量。
UPD:这是一个例子
build_dir := $(bin_dir)/build
xpi_built := $(build_dir)/$(install_rdf) \
$(build_dir)/$(chrome_manifest) \
$(chrome_jar_file) \
$(default_prefs)/*
xpi_built_no_dir := $(subst $(build_dir)/,,$(xpi_built))
.PHONY: install
install: $(build_dir) $(xpi_built)
@echo "Installing in profile folder: $(profile_location)"
@cp -Rf $(build_dir)/* $(profile_location)
@echo "Installing in profile folder. Done!"
@echo
$(xpi_file): $(build_dir) $(xpi_built)
@echo "Creating XPI file."
@cd $(build_dir); $(ZIP) -r ../$(xpi_file) $(xpi_built_no_dir)
@echo "Creating XPI file. Done!"
@cp update.rdf $(bin_dir)/
@cp -u *.xhtml $(bin_dir)/
@cp -Rf $(default_prefs) $(build_dir)/; \
$(build_dir)/%: %
cp -f $< $@
$(build_dir):
@if [ ! -x $(build_dir) ]; \
then \
mkdir $(build_dir); \
fi
How can I distinguish in makefile, which targets and how(when) they are called internally? I have a makefile with number of targets which are actually variables.
UPD: here is an example
build_dir := $(bin_dir)/build
xpi_built := $(build_dir)/$(install_rdf) \
$(build_dir)/$(chrome_manifest) \
$(chrome_jar_file) \
$(default_prefs)/*
xpi_built_no_dir := $(subst $(build_dir)/,,$(xpi_built))
.PHONY: install
install: $(build_dir) $(xpi_built)
@echo "Installing in profile folder: $(profile_location)"
@cp -Rf $(build_dir)/* $(profile_location)
@echo "Installing in profile folder. Done!"
@echo
$(xpi_file): $(build_dir) $(xpi_built)
@echo "Creating XPI file."
@cd $(build_dir); $(ZIP) -r ../$(xpi_file) $(xpi_built_no_dir)
@echo "Creating XPI file. Done!"
@cp update.rdf $(bin_dir)/
@cp -u *.xhtml $(bin_dir)/
@cp -Rf $(default_prefs) $(build_dir)/; \
$(build_dir)/%: %
cp -f lt; $@
$(build_dir):
@if [ ! -x $(build_dir) ]; \
then \
mkdir $(build_dir); \
fi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在命令行上指定目标,如
make clean
中那样,Make 将尝试构建该目标。如果您不这样做(即,如果您只是运行make
),Make 将尝试构建默认目标;默认目标是 makefile 中的第一个目标(在您的情况下是install
),除非您使用.DEFAULT_GOAL
变量将其设置为其他目标。当 Make 尝试构建目标时,如果有必要,它首先构建该目标的先决条件。 (什么时候有必要?当目标是一个不真实存在的文件或目录时(除非它是
.PHONY
,但这是一个高级主题),或者当它的先决条件之一比目标新时(除非它是“仅限订单”,但这是一个高级主题))。因此,如果 Make 尝试构建您的all
,它会首先尝试构建$(build_dir)
和$(xpi_built)
,它们已被在 makefile 的其他地方定义。如果您想弄清楚 Make 将做什么以及何时做什么,可以使用一些技巧。例如,您可以运行 make -n,Make 会告诉您它将做什么,而不是执行它。或者您可以在规则中放置像
@echo now Making $@
这样的命令,来告诉您它正在做什么。或者了解更多信息:If you specify a target on the command line, as in
make clean
Make will attempt to build that target. If you don't (that is, if you just runmake
), Make will attempt to build the default target; the default target is the first target in the makefile (in your caseinstall
) unless you set it to something else with the.DEFAULT_GOAL
variable.When Make tries to build a target, it first builds that target's prerequisites, if necessary. (When is it necessary? When a target is a file or directory that does not exist real (unless it's
.PHONY
, but that's an advanced topic), or when one of it's prerequisites is newer than the target (unless it's "order-only", but that's an advanced topic)). So if Make is trying to build yourall
, it will first try to build$(build_dir)
and$(xpi_built)
, which have been defined elsewhere in the makefile.If you're trying to figure out what Make will do and when, there are tricks you can use. For example, you can run
make -n
, and Make would tell you what it would do, instead of doing it. Or you can put a command like@echo now making $@
in a rule, to tell you what it's doing. Or for even more information: