http://tetralet.luna.com.tw/?op=ViewArticle&articleId=185
問題:(timing of interpreting symobol)
"注意到,make 會將整個 Makefile 展開後,再決定變數的值。也就是說,變數的值將會是整個 Mackfile 中最後被指定的值。例:
x = foo
y = $(x) bar
x = xyz
# y 的值為 xyz bar
在上例中,y 的值將會是 xyz bar,而不是 foo bar。"
對策:
"您可以利用 := 來避開這個問題。:= 表示變數的值決定於它在 Makefile 中的位置,而不是整個 Makefile 展開後最終的值。
x := foo
y := $(x) bar
x := xyz
# y 的值為 foo bar
在上例中,y 的值將會是 foo bar,而不是 xyz bar 了。"
參考:
http://lxr.linux.no/#linux+v3.8.5/scripts/Makefile.build
...
PHONY := __build
__build:
# Init all relevant variables used in kbuild files so
# 1) they have correct type
# 2) they do not inherit any value from the environment
obj-y :=
obj-m :=
lib-y :=
lib-m :=
always :=
...