单词phony (即phoney)的意思是:伪造的,假的。来自collins的解释是:
If you describe something as phoney, you disapprove of it because it is false
rather than genuine.
那么,在Makefile中,.PHONY后面的target表示的也是一个伪造的target, 而不是真实存在的文件target,注意Makefile的target默认是文件。
举个例子
Makefile内容如下:
clean:
rm -f test.txt
该目录下只有test.txt时,执行make,得到结果如下:
rm -f test.txt
在改目录下透彻test.txt和clean两个文件,这时执行make命令,得到结果如下:
make: “clean”是最新的。
可以看到make会将clean文件当成目标文件,而执行失败
如果将Makefile修改为如下内容:
.PHONY:clean
clean:
rm -f test.txt
然后再执行make,得到结果如下:
rm -f test.txt
即该makefile并没有将clean当成是目标文件,所以执行成功
小结:
.PHONY: clean
o means the word "clean" doesn't represent a file name in this Makefile;
o means the Makefile has nothing to do with a file called "clean"
in the same directory.