单词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默认是文件。
    举个例子:

    1. $ cat -n Makefile1
    2. 1 clean:
    3. 2 rm -f foo
    4. $ cat -n Makefile2
    5. 1 .PHONY: clean
    6. 2 clean:
    7. 3 rm -f foo

    Makefile1和Makefile2的差别就是在Makefile2中定义了:
    1 .PHONY: clean
    直接Make看看

    1. $ ls -l
    2. total 8
    3. -rw-r--r-- 1 huanli huanli 18 Jul 13 17:51 Makefile1
    4. -rw-r--r-- 1 huanli huanli 32 Jul 13 17:51 Makefile2
    5. $ make -f Makefile1 clean
    6. rm -f foo
    7. $ make -f Makefile2 clean
    8. rm -f foo

    Makefile中.PHONY的作用 - 图1Makefile1和Makefile2的行为没有啥子区别嘛,呵呵
    创建一个文件clean, 再make看看

    1. $ touch clean
    2. $ ls -l
    3. total 8
    4. -rw-r--r-- 1 huanli huanli 0 Jul 13 18:06 clean
    5. -rw-r--r-- 1 huanli huanli 18 Jul 13 17:51 Makefile1
    6. -rw-r--r-- 1 huanli huanli 32 Jul 13 17:51 Makefile2
    7. $ make -f Makefile1 clean
    8. make: 'clean' is up to date.
    9. $ make -f Makefile2 clean
    10. rm -f foo

    Makefile中.PHONY的作用 - 图2总结:
    区别来了,Makefile1拒绝了执行clean, 因为文件clean存在。而Makefile2却不理会文件clean的存在,总是执行clean后面的规则。由此可见,.PHONY clean发挥了作用。
    小结:

    1. .PHONY: clean
    2. o means the word "clean" doesn't represent a file name in this Makefile;
    3. o means the Makefile has nothing to do with a file called "clean"
    4. in the same directory.