FOO ?= bar 如果FOO沒被定義過,則FOO等於bar。若FOO被定義過,則這行什麼也不做。



$@--目标文件,

$^--所有的依赖文件,

$<--第一个依赖文件。

自动环变量“$?”在这里表示依赖文件列表中被改变过的所有文件

"%"的意思是匹配零或若干字符,例如,“%.h”表示所有以“.h”结尾的文件。

用“@”字符在命令行前,那么,这个命令将不被make显示出来 @echo 正在编译XXX模块......

在的Makefile中使用“#”字符,可以用反斜框进行转义,如: “\#”。
最后,还值得一提的是,在Makefile中的命令,必须要以[Tab]键开始。

在Makefile使用include关键字可以把别的Makefile包含进来

如果你要传递变量到下级Makefile中,那么你可以使用这样的声明:
export
如果你不想让某些变量传递到下级Makefile中,那么你可以这样声明:
unexport



對新手來說講的不錯的網站

http://www.csie.cyut.edu.tw/~dywang/linuxProgram/node39.html



$(subst $(BAD_SLASH),$(GOOD_SLASH),../../../sha/bluetooth)
最左邊的$表示執行makefile的函數subst,subst把第三個參數的bad slash用good slash代替



Q:export specific variables to a sub-make
A:export variable ...



Q:prevent a variable from being exported
A:unexport variable ...



if you have three .mk files, a.mk, b.mk, and c.mk, and $(bar) expands to bish bash, then the following expression
include foo *.mk $(bar)

is equivalent to
include foo a.mk b.mk c.mk bish bash



?=就是如果變數沒定義就定義它為右邊的值的意思
This statement:
FOO ?= bar

is exactly equivalent to this (see The origin Function):
ifeq ($(origin FOO), undefined)
FOO = bar
endif

Note that a variable set to an empty value is still defined, so `?=' will not set that variable.



origin Function tells you something about a variable

$(origin variable)

return a string telling you how the variable variable was defined:like 'undefined','environment'...



.PHONY
gnu的網站解釋了一堆看不懂,結果其實只是照字面解釋把target設成假目標,就算make的目錄下沒有target同名的檔案或有同名的檔案卻沒有被更新過,仍可執行make 'target'

 

後來發現這樣寫也不太完全對,應該是在.PHONY後加上 target name,那這個target就會被當成假目標,不會每次make的時候都被執行,只有當特別make "target name"的時候會去執行,這樣可以節省每次make的時間和效率。常看到的例子就是clean,因為make clean不是每次make的時候都要做的,只有特別下make clean的時候會去做clean的動作。

Reference:

GNU make

Shell設計入門



DOS下執行chdir不加任何參數,會傳回當前目錄

target 通常是要产生的文件的名称,例如可执行文件或 OBJ文件,也可是一个执行的动作名称,诸如‘clean’。

${foo}, $(foo):可引用变量的值
'$' 的这种特殊作用是您在命令或文件名中必须写‘$$’才有单个‘$’的效果的原因。
?= 变量还没有定义的情况下有效。ex: FOO ?= bar


.PHONY in Makefile
Make 主要的工作目標都是針對檔案,所以萬一你定義的工作目標並不是檔案,或是正好與檔案重複的時候,其實是會讓人丈二金剛摸不著頭的。
所以,.PHONY 被用來定義假工作目標,這樣 Make 就知道這不是針對檔案。

Make 預設的假工作目標有:
all
install
clean
distclean
TAGS
info
check

目 前個人的理解是,一個makefile裡有兩個Target名稱,用 .phony 指定其中一個時,比如 clean,只有在下 make clean 指令時才會去做這個 clean 裡面的動作,只下 make 指令,就做原來 Target 裡的動作,有點像 switch case的感覺。

Reference:

make的參數

Makefile工具的使用


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 lver76 的頭像
    lver76

    Iver's Blog

    lver76 發表在 痞客邦 留言(0) 人氣()