Makefile 知识整理

参考:
http://zebozhuang.blog.163.com/blog/static/1714798042012981194731/
http://www.cnblogs.com/hnrainll/archive/2011/04/12/2013377.html

  • PHONY
    PHONY 目标并非实际的文件名:只是在显式请求时执行命令的名字。有两种理由需要使用PHONY 目标:避免和同名文件冲突,改善性能。
    如果编写一个规则,并不产生目标文件,则其命令在每次make 该目标时都执行。例如:
      clean:
      rm *.o temp
    因为”rm”命令并不产生”clean”文件,则每次执行”make clean”的时候,该命令都会执行。如果目录中出现了”clean”文件,则规则失效了:没有依赖文件,文件”clean”始终是最新的,命令永远不会 执行;为避免这个问题,可使用”.PHONY”指明该目标。如:
      .PHONY : clean
      这样执行”make clean”会无视”clean”文件存在与否。
      
  • special macro
    • $@ The file name of the target.
    • $< The name of the first dependency.
    • $* The part of a filename which matched a suffix rule.
    • $? The names of all the dependencies newer than the target separated by spaces.
    • $^ The names of all the dependencies separated by spaces, but with duplicate names removed.
    • $+ The names of all the dependencies separated by spaces with duplicate names included and in the same order as in the rule.

A Simple Makefile Tutorial
http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
GNU Make
http://www.gnu.org/software/make/manual/make.html

你可能感兴趣的:(Makefile 知识整理)