GNU Make C1-C2
-
Makefile: Top-down style
-
phony target makes reusing commond easily. Sytanx: .PHONY: target_name
-
6 Core Automatic Variable for avoiding code dupliaction: p21
-
$@ target file name
-
$% filename of an archive member specification
-
$< filename of first prerequisite
-
$? prerequisites newer than target
-
$^ all prerequisites without duplicates
-
$+ all prerequisites
-
$* stem of target filename (the portion before the suffix)
-
-
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
-
suffix rules. .cpp.o : == %.o:%.cpp
-
implicit ruls: default settings of make. make -p to print.
-
useful special target aside PHONY
-
d file stand for dependency. We use d file when we when to add dependencies without recompile source code. (need to talk to forest)
-
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
-
two varible type: expand(:=) and recursively expanded variable(=).
-
?= set varible only it hasn's been set early
-
def macro to reuse commonds:
-
define free-space(macro name)
-
xxxxxx
-
endef
-
-
condition
-
ifeq $(a), $(b)
-
do something
-
endif
-
-
function can be passed arguments. Like bash, $1 stand for the first argument
-
built in functions(texts):
-
filter. $(filter pattern... ,text) sample: $(ui_library): $(filter ui/%.o,$(objects))
-
replacement. $(patsubst search-pattern,replace-pattern,text)
-
return text list sparated by whitespace: $(words text)
-
return nth word in text. $(word n,text)
-
return a range of texts. $(wordlist start,end,text)
-
-
built in function(file name):
-
return non-duplicated sorted list. sort $(sort list)
-
$(shell command)
-
$(wildcard ./*.cpp) wildcard for file name
-
$(dir) and $(notdir) handle with path
-
$(basename) and $(suffix) handle with file name
-
$(addsuffix) append suffix to names
-
-
built in functions(flow control
-
$(if condition,then-part,else-part)
-
page 74