nnop / notes

notes
1 stars 0 forks source link

makefile tricks #209

Open nnop opened 6 years ago

nnop commented 6 years ago

6.3.1 Substitution References

A substitution reference substitutes the value of a variable with alterations that you specify. It has the form $(var:a=b) (or ${var:a=b}) and its meaning is to take the value of the variable var, replace every a at the end of a word with b in that value, and substitute the resulting string.

A substitution reference is actually an abbreviation for use of the patsubst expansion function

nnop commented 6 years ago

rpath

$ORIGIN is a special variable that means ‘this executable’, and it means the actual executable filename, as readlink would see it, so symlinks are followed. In other words, $ORIGIN is special and resolves to wherever the binary is at runtime.

You need to pass the literal string $ORIGIN/../lib as an argument to your linker. The $ORIGIN token is kept inside your program after it's created and when the runtime linker starts to run your program it will replace $ORIGIN with the current path that your program was invoked from.

In order to pass a literal $ to the command invoked by a make recipe, you have to escape the $ by doubling it: $$. Otherwise, make will see the $ as introducing a make variable or function. Remember, it's perfectly legal for a make variable to avoid the parentheses etc., if it's a single character (note, $@, $<, etc.)

nnop commented 6 years ago

dependencies auto-generation

nnop commented 6 years ago

Makefile

rules

ordinary rules

static pattern rules

implicit rules

其实是一些惯用的(customary)处理方法。

built-in rules

pattern rules

multiple targets

对于ordinary rules

对于implicit rules

自动依赖生成

编译器参数

directory organization

rules的选择顺序

1. ordinary rules

2. static pattern rules

3. implicit rules即pattern rules

4. chain rules

expansion

target和prerequisite立刻展开

运行机理

1st phase: 建依赖图

2nd phase: 决定哪些需要rebuild