考虑这个简单的makefile:
all: output.txt
# The actual build command won't be this simple.
# It'll more be like "some-compiler file1.txt",
# which includes file2.txt automatically.
output.txt: file1.txt
cat file1.txt file2.txt > output.txt
file2.txt:
echo "heyo" > file2.txt
file1.txt: file2.txt
在第一次运行时,Make 识别出它file2.txt是 的依赖项file1.txt,因此需要构建它才能output.txt构建它。因此,它运行echo "heyo" > file2.txt,然后cat file1.txt file2.txt > output.txt。
但是,在后续运行中,如果file2.txt更改,Make 不会重建!如果file1.txt改变了,它会改变,但不是 for file2.txt。它只是给出了可怕的make: Nothing to be done for 'all'.信息。
我见过人们建议的一种 hacky 解决方案是执行以下操作:
all: output.txt
output.txt: file1.txt file2.txt
cat file1.txt file2.txt > output.txt
但是,在我的情况下这是不可能的,因为我的次要依赖项(如 的行file1.txt: file2.txt)是使用include.
当我有多个级别的依赖项时,如何确保 Make 检查所有的修改?