GNU Make Note

GNU Make C1-C2

  1. Makefile: Top-down style

  2. phony target makes reusing commond easily. Sytanx: .PHONY: target_name

  3. 6 Core Automatic Variable for avoiding code dupliaction: p21

    1. $@ target file name

    2. $% filename of an archive member specification

    3. $< filename of first prerequisite

    4. $? prerequisites newer than target

    5. $^ all prerequisites without duplicates

    6. $+ all prerequisites

    7. $* stem of target filename (the portion before the suffix)

  4. VPATH, specify the paths to find prerequisites. if any files has same file name in different paths. It returns first one.  vpath directive is a more precise way to achieve the goal- find right source files: vpath %.c src

  5. suffix rules. .cpp.o :  ==  %.o:%.cpp

  6. implicit ruls: default settings of make. make -p    to print.

  7. useful special target aside PHONY

  8. d file stand for dependency. We use d file when we when to add dependencies without recompile source code. (need to talk to forest)

  9. use ar commond to update achieve file. sample:  ar rv xxx.a  xx.o r means replace. the object in the achieve flle was updated. or,  we can just replace one objet by: xx.a(xx.o):xx.o

C3-C4

  1. two varible type: expand(:=) and recursively expanded variable(=).

  2. ?= set varible only it hasn's been set early

  3. def macro to reuse commonds:

    • define free-space(macro name)

    • xxxxxx

    • endef

  4. condition

    • ifeq $(a), $(b)

    • do something

    • endif

  5. function can be passed arguments. Like bash, $1 stand for the first argument

  6. built in functions(texts):

    1. filter. $(filter pattern... ,text)   sample: $(ui_library): $(filter ui/%.o,$(objects))

    2. replacement. $(patsubst search-pattern,replace-pattern,text)

    3. return text list sparated by whitespace: $(words text)

    4. return nth word in text. $(word n,text)

    5. return a range of texts. $(wordlist start,end,text)

  7. built in function(file name):

    1. return non-duplicated sorted list. sort  $(sort list)

    2. $(shell command)

    3. $(wildcard ./*.cpp) wildcard for file name

    4. $(dir) and $(notdir) handle with path

    5. $(basename) and $(suffix) handle with file name

    6. $(addsuffix) append suffix to names

  8. built in functions(flow control

    1. $(if condition,then-part,else-part)

page 74

你可能感兴趣的:(GNU Make Note)