Variables defined with ‘=’ are recursively expanded variables. It means that value of this variable will be the last value gived by ‘=’ in makefile. For example:
a = foo
In this case, the value of b will be oof abc.
Variables defined with ‘:=’ are simply expanded variables. Just like “=“ in other language(C/C++/C#/Java). For example:
a := foo
In this case, the value of b will be foo abc.
We can use ‘?=’ to set a value to a variable only if this variable is not set yet. For example:
a ?= foo
It is similar to:
ifeq ($(origin a), undefined)
‘+=’ is using for appending text. It will appending a space between two text.For example:
a = first
In this case, the value of a will be first second.
In makefile, functions should be called like this:
var = $(functionname arg1,arg2,arg3...)
wildcard will help you get specific file name list in a dir.For example:
SRC_DIR := src
In this case, SUORCES will be set like this(if *.cpp exists in SRC_DIR):
src/a.cpp src/b.cpp src/c.cpp
addprefix is using for add one value to the front of another value. For example:
a = $(addsuffix .o,foo bar)
a will be set as ‘foo.o bar.o‘
$(patsubst pattern,replacement,text):Finds whitespace-separated words in text that match pattern and replaces them with replacement(gnu.org)
a = $(patsubst %.cpp,%.o,a.cpp b.h c.cpp)
a will be set as ‘a.o b.h c.o‘
$(notdir names…):remove dir in names.For example:
a = $(notdir src/foo.c src/bar.c)
a will be set as ‘foo.c bar.c‘
If we have a recipe :
It will works well until one day you add one file called clean. In this case, you need add .PHONY:
If we do this, ‘make clean’ will run the recipe regardless of whether there is a file named clean.