在运行依赖于生成文件的目标时,我对Make的行为有疑问.
I have a question regarding the behavior of Make when running targets that are dependent on generated files.
考虑到下面的源代码树和Makefile,即使我在第一次运行时生成了所有内容,当我运行它时也需要两次运行才能完成构建".
Given the source tree and Makefile below, when I run this it takes two runs to complete the "build" even though everything was generated on the first run.
$ ls -R .: bar foo MakefileMakefile
all: foobar work: mkdir -p work work/foo: work foo cp foo work/foo work/bar: work bar cp bar work/bar foobar: work/foo work/barmake
$ make mkdir -p work cp foo work/foo cp bar work/bar $ ls -R .: work/ bar CMakeLists.txt foo Makefile ./work: bar foo $ make cp foo work/foo $ make make: Nothing to be done for 'all'.为什么会这样?
推荐答案您需要将目录设置为 仅订购 的先决条件,否则每次目录更改时都将重新建立目标;在第二次调用期间,work比work/foo更新,因为work/bar是在work/foo之后创建的,所以work的时间戳比work/foo更新.
You need to make the directory an order-only prerequisite, otherwise the targets will be remade each time the directory changes; during the second invocation work is newer than work/foo because work/bar was created after work/foo, so work's timestamp is newer than work/foo.
work/foo: foo | work cp foo work/foo work/bar: bar | work cp bar work/bar或更简洁
work/foo work/bar: work/%: % | work cp $< $@更多推荐
Makefile目标对生成文件的依赖
发布评论