Linux上目录的制作和上次修改时间 [英] Make and last modification times of directories on Linux
问题描述
考虑以下makefile:
Consider the following makefile:
foo :
mkdir foo
foo/a.out : foo a.in
cp a.in foo/a.out
foo/b.out : foo b.in
cp b.in foo/b.out
及其随后的交互,从包含文件a.in
和b.in
的目录开始,并且没有其他内容:
and the following interaction with it, starting from a directory that contains files a.in
and b.in
and nothing else:
$ make foo/a.out
mkdir foo
cp a.in foo/a.out
到目前为止,很好.
$ make foo/b.out
cp b.in foo/b.out
仍然很好,但是现在:
$ make foo/a.out # a.out should be up to date now!
cp a.in foo/a.out
即使未更改任何先决条件,它也会重建a.out
目标.
It rebuilds the a.out
target, even though none of its prerequisites have changed.
似乎正在发生的事情是,在创建foo/b.out
时,目录foo
的上次修改时间已更新,因此它将其视为已更改".
It seems like what's happening is that when foo/b.out
is created, the last modification time of the directory foo
is updated, so it picks that up as having "changed".
有办法避免这种情况吗?例如,是否有一种方法可以声明foo/a.out
依赖于foo
仅在于foo
必须存在,并且在foo
内部创建文件不会导致foo
被认为已过时. ?
Is there a way to avoid this? For example, is there a way to declare that foo/a.out
depends on foo
only in that foo
has to exist, and the creating of files inside foo
doesn't cause foo
to be considered out of date?
推荐答案
永远不要做的一件事就是使用目录作为简单的先决条件.文件系统用来更新目录上修改时间的规则不适用于make."
但是我认为这会满足您的要求:
But I think this will do what you want:
foo :
mkdir foo
foo/a.out : a.in | foo
cp a.in foo/a.out
foo/b.out : b.in | foo
cp b.in foo/b.out
这篇关于Linux上目录的制作和上次修改时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!