zoukankan      html  css  js  c++  java
  • Makefile 中的.PHONY

    PHONY 目标并非实际的文件名:只是在显式请求时执行命令的名字。有两种理由需要使用PHONY 目标:避免和同名文件冲突,改善性能。

    所谓的PHONY这个单词就是伪造的意思,makefile中将.PHONY放在一个目标前就是指明这个目标是伪文件目标,如下:
    .PHONY:clean
    这里clean目标没有依赖文件,如果执行make命令的目录中出现了clean文件,由于其没有依赖文件,所以它永远是最新的,所以根据make的规则clean目标下的命令是不会被执行的。如下的例子:

    [yangfan@dhcp-13-42 test]$ cat Makefile
    obj = 1.c 2.c 3.c 4.c

    all:
    touch $(obj)
    clean:
    rm -rf $(obj)
    [yangfan@dhcp-13-42 test]$
    [yangfan@dhcp-13-42 test]$ make
    touch 1.c 2.c 3.c 4.c
    [yangfan@dhcp-13-42 test]$ ls
    1.c 2.c 3.c 4.c Makefile
    [yangfan@dhcp-13-42 test]$ make clean
    rm -rf 1.c 2.c 3.c 4.c
    [yangfan@dhcp-13-42 test]$ ls
    Makefile
    [yangfan@dhcp-13-42 test]$ make
    touch 1.c 2.c 3.c 4.c
    [yangfan@dhcp-13-42 test]$ touch clean
    [yangfan@dhcp-13-42 test]$ ls
    1.c 2.c 3.c 4.c clean Makefile
    [yangfan@dhcp-13-42 test]$ make clean
    make: `clean' is up to date.
    [yangfan@dhcp-13-42 test]$ ls
    1.c 2.c 3.c 4.c clean Makefile
    [yangfan@dhcp-13-42 test]$

    这个Makefile中all目标是创建空的1.c 2.c 3.c 和4.c 。  clean目标是删除这些文件,但是如果当前目录中出现了一个clean文件,在执行
    make clean时就不会在执行clean目标下的命令了。下面看看在clean目标前加上.PHONY之后的情况:

    [yangfan@dhcp-13-42 test]$ cat Makefile
    obj = 1.c 2.c 3.c 4.c

    all:
    touch $(obj)
    .PHONY: clean
    clean:
    rm -rf $(obj)
    [yangfan@dhcp-13-42 test]$ ls
    1.c 2.c 3.c 4.c clean Makefile
    [yangfan@dhcp-13-42 test]$ make clean
    rm -rf 1.c 2.c 3.c 4.c
    [yangfan@dhcp-13-42 test]$ ls
    clean Makefile
    [yangfan@dhcp-13-42 test]$

  • 相关阅读:
    Responder一点也不神秘————iOS用户响应者链完全剖析
    loadView、viewDidLoad及viewDidUnload的关系
    iOS 离屏渲染的研究
    CoreData处理海量数据
    《驾驭Core Data》
    为什么都要在主线程中更新UI
    快速排序OC实现和快排思想找第n大的数(原创)
    最新版SDWebImage的使用
    UIViewContentMode各类型效果
    iOS 8 自适应 Cell
  • 原文地址:https://www.cnblogs.com/kex1n/p/8303619.html
Copyright © 2011-2022 走看看