在这个makefile中,为什么是目标的先决条件;bunzip2/data2.tar“;总是被翻拍?

在这个makefile中,为什么是目标的先决条件;bunzip2/data2.tar“;总是被翻拍?,makefile,compression,bzip2,xz,Makefile,Compression,Bzip2,Xz,我有一个make文件,它始终在重新运行规则,尽管前提条件是最新的: data.tar.bz2: data.tar bzip2 --keep data.tar # The following rule always runs the rule for its prerequisite # even if it is up-to-date. Note that it doesn't matter whether # the bunzip2 directory exists or not.

我有一个make文件,它始终在重新运行规则,尽管前提条件是最新的:

data.tar.bz2: data.tar
    bzip2 --keep data.tar

# The following rule always runs the rule for its prerequisite
# even if it is up-to-date. Note that it doesn't matter whether
# the bunzip2 directory exists or not. I suppose is has something
# to do with the dir/file naming of the rule but I haven't been
# able to decipher why.
bunzip2/data2.tar: data.tar.bz2
    mkdir bunzip2 && cd bunzip2 && bzip2 -ckd ../data.tar.bz2 > data2.tar && cd ..

.PHONY: clean
clean:
    rm -f data.tar.bz2
    rm -Rf bunzip2

任何想法都值得赞赏。

示例中缺少了一些东西,但分析过程是相同的,不管怎样:您可以使用make的调试功能查看它使用了哪些规则,例如

make -d

我想我知道这里发生了什么

使用@Thomas Dickey advice尝试
make-d
,意思是文件
data.tar.bz2
data.tar
本身更新。这似乎很愚蠢,因为前者是由后者创造的。但是使用
ls--full-time
显示bzip2归档文件似乎使用了源文件的时间戳,但它也会在第二位之后截断它。在我的例子中,时间戳
2015-03-12 09:32:02.452091888
被截断为
2015-03-12 09:32:02.000000000
,这使得它看起来比源代码更新。(我所说的截断是指
2015-03-12 13:10:29.681793152
转到
2015-03-12 13:10:29.000000000
…即使在这种情况下也不会取整)似乎bzip需要提高时间戳的准确性


似乎
lunzip
也会截断时间戳,
unxz
保留原始时间戳,而
gzip
使用当前时间。换句话说,在使用压缩实用程序时要小心makefiles,因为它们的处理方式不同。

在文件上设置时间戳的标准POSIX系统调用不支持亚秒精度。为了让这些工具在文件上设置特定时间(他们尝试这样做,以使压缩文件具有与原始文件相同的时间戳),并保持原始准确性,他们需要使用不同的系统调用;显然他们没有这样做

要解决这一问题,您可以这样更改规则:

data.tar.bz2: data.tar
        bzip2 --keep data.tar && touch $@
因此,目标的时间戳设置为“现在”

ETA用于设置文件修改时间的传统系统调用是,它只接受以1秒为增量的时间戳。新版本的POSIX规范允许纳秒时间戳设置。还有
utimes()
,允许微秒精度,但长期以来一直被认为是“传统”


如果这个行为存在于<代码> BZIP2</代码>的最新版本中,我会认为这是一个值得向它们报告bug的bug。触摸是我发现问题后的变通方法。谢谢你提到POSIX。我正在运行Debian喘息。值得一提的是,我有bzip2v1.0.6、lzip v1.13(带有lunzip v1.1)和unxz5.1.0alpha。似乎BZIP2v1.0.6(从2010年开始!)是,而lzip(v1.16)和xz(v5.2.1)不是。我没有定义新标签的名声,但如果你能在这个问题上添加“lzip”作为标签,那将是有益的。