Makefile

(1)wildcard
    $(wildcard *.c)
    $(patsubst %.c,%.o,$(wildcard *.c))
   
(2)VPATH
    make uses VPATH as a search list for both prerequisites and targets of rules.
    VPATH = src:../headers
        specifies a path containing two directories, src and ../headers, which make searches in
        that order.
       
(3)vpath
    vpath pattern directories   -->Specify the search path directories for file names that match pattern.
    vpath pattern                       -->Clear out the search path associated with pattern.
    vpath                               -->Clear all search paths previously specified with vpath directives.
   
    vpath %.c foo:bar
    vpath % blish
    -->will look for a file ending in ‘.c’ in foo, then blish, then bar
   
(4)$$   --> a dollar sign
   =    -->recursively expanded variable
  :=    -->simple expanded variable
  +=    -->add more text to the value of a variable already defined
(5)Phony target (fake target)
    A phony target is one that is not really the name of a file; rather it is just a name for a
    recipe to be executed when you make an explicit request. (顯示的請求)

 

(6)Substitution References
    It has the form ‘$(var:a=b)’ (or ‘${var:a=b}’)
    foo := a.o b.o c.o
    bar := $(foo:.o=.c)
    sets ‘bar’ to ‘a.c b.c c.c’
   
(7)functions
    $(subst from,to,text)   -->Performs a textual replacement on the text text: each occurrence of from is
                                replaced by to.

 

    $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)   -->$(OBJDIR)/foo.o $(OBJDIR)/bar.o $(OBJDIR)/baz.o

 

    $(foreach var,list,text)
        dirs := a b c d
        files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))]
       
        --->for dir in $(dirs)
                files := $(wildcard $(dir)/*)
    
    $(call variable,param,param,...)
            Variable values of the top-level make can be passed to the sub-make through the environment
        by explicit request.   
            When make expands this function, it assigns each param to temporary variables $(1),$(2), etc.
        The variable $(0) will contain variable.
   
    $(origin variable)
        it tells you something about a variable. Specifically, it tells you where it came from.

(8)include
    include filenames...
        filenames can contain shell file name patterns.
   
    ‘-I’ or ‘--include-dir’ option are searched.
        Then the following directories (if they exist) are searched,
        in this order: prefix/include (normally /usr/local/include1) /usr/gnu/include, /usr/local/include, /usr/include.
  
    -include(sinclude) filenames...
        This acts like include in every way except that there is no error.if any of the filenames (or any prerequisites of any of the filenames) do not exist or cannot be remade.
       
(9)Automatic Variables
    $@ ->The file name of the target of the rule.
    $< ->The name of the first prerequisite.
    $^ The names of all the prerequisites, with spaces between them.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章