2008-03-02

Makefile: debug notes

# online resources
http://make.paulandlesley.org/
http://make.paulandlesley.org/rules.html
http://make.paulandlesley.org/autodep.html
...


=== 变量 & 函数===
1. 变量必须带 () or {}, 除非变量名只包含一个字符
2. MAKEFILES 及其他环境变量
3. 使用subst时, ","后面的空格会给字符串中加入多余的空格
4. $ should be "$$" (not \$); % should be \& (see example below)
5. 单引号、双引号不影响makefile的变量扩展 (see example below)
6. makefile中扩展变量和函数用的都是$();shell中,变量用${},函数用$()或是``
7. makefile的文件名函数 (manual-8.3) 与shell中的dirname, basename, 以及${} 有一定的区别
例如:使用 makefile 中的 suffix & basename 时,目录中的 "." 是被忽略的
8. 模式匹配时, 目录部分首先被去掉,匹配成功后再加上,see also manual-10.5.4

# example: 变量扩展
shell:
export CC=gcc
makefile:
CC = icc
@echo "$(CC)" # icc
@echo '$(CC)' # icc
@echo "\$(CC)" # icc
@echo "$$CC" # icc !!
@echo '$$CC' # $CC

# example: filename functions
shell:
dirname src/ # .
dirname src # .
basename src/ # src
basename src # src
1. a = src
@echo $(dir $a) # ./
@echo $(notdir $a) # src
2. a = src/
@echo $(dir $a) # src/
@echo $(notdir $a) # null


=== 命令 ===
1. 命令必须以 Tab 开头: "^ \t" error; "\t#" 是命令而不是注释

# example: 命令效果延续
cd src; pwd
cd src && pwd

No comments: