make 总是重建 Makefile 目标 [英] make always rebuilds Makefile targets
问题描述
我为我的论文项目重新设计了大部分 Makefile
文件,以正确反映工作流程(为项目子目录中的目标之间的依赖关系创建规则).但是,在特定的子目录 (prepare
) 中,make
always 会重建 所有目标,即使有依赖项没有变化.出现这种意外行为的原因可能是什么?
I redesigned most of the Makefile
files for my dissertation project in order to correctly reflect the workflow (Creating make rules for dependencies across targets in project's sub-directories). However, in a particular sub-directory (prepare
), make
always rebuilds all targets, even when there are no changes in dependencies. What could be the reason for this unexpected behavior?
注意:sf.done
是一个真实的文件(类型,我称之为标志文件"),位于不同的子目录中,并在数据收集完成后创建/更新(import
) - 目标 transform
的相关步骤.
NOTE: sf.done
is a real file (of type, which I call "flag files"), located in a different sub-directory and created/updated upon completion of data collection (import
) - dependent step for the target transform
.
准备/生成文件:
IMPORT_DIR=../import
prepare: import
transform
cleanup
merge
sample
import: $(IMPORT_DIR)/sf.done
transform: transform.done
cleanup: cleanup.done
merge: merge.done
sample: sample.done
transform.done: transform.R import
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
cleanup.done: cleanup.R transform
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
merge.done: merge.R cleanup
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
sample.done: sample.R merge
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
.PHONY: import transform cleanup merge sample clean
# remove intermediate files
clean:
rm -f tmp*.bz2 *.Rdata .Rout
更新:
IMPORT_DIR = ../import
IMPORT_DONE = $(IMPORT_DIR)/sf.done
prepare: import
transform
cleanup
merge
sample
import: import.done
transform: transform.done
cleanup: cleanup.done
merge: merge.done
sample: sample.done
import.done: $(IMPORT_DONE)
@cd $(IMPORT_DIR) && $(MAKE)
transform.done: transform.R import.done
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
cleanup.done: cleanup.R transform.done
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
merge.done: merge.R cleanup.done
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
sample.done: sample.R merge.done
@$(RSCRIPT) $(R_OPTS) $<
@touch $@
.PHONY: import transform cleanup merge sample clean
推荐答案
您已将目标 import transform cleanup merge sample clean
声明为 .PHONY
.这意味着 make 将始终认为它们已过时.
You've declared the targets import transform cleanup merge sample clean
to be .PHONY
. That means that make will always consider them to be out of date.
然后你声明各种 .done
目标依赖于那些 .PHONY
目标.由于虚假目标总是被认为是过时的,那些 .done
目标总是需要更新,并且配方总是会触发.
Then you declare the various .done
targets to depend on those .PHONY
targets. Since the phony targets are always considered out of date, those .done
targets always need to be updated, and the recipes always fire.
这篇关于make 总是重建 Makefile 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!