1. 基本格式
Target: Prerequisite
<tab> Command
2. PHONY
可以用來避免當你打make "target"時, 此target卻恰好是Makefile所屬資料夾中的另一個檔案名稱時
這樣會造成直接去compile target, 而不是所預期的依照著Makefile裡面的target去執行
以下為一範例
#===Makefile===
test:
@echo "hihi"
#===end of Makefile===
假如也正好有一個名稱叫做test的檔案放在同一個資料夾下
這時候打make test, 他會嘗試去看test檔案是否有更新再做動作
我們預期make test會根據Makefile印出"hihi", 但是通常會得到如下結果
[lab_linux test]$ make test
make: `test' is up to date.
若要能夠正確的印出"hihi"該怎麼做呢
再Makefile裡把.PHONY加上即可, .PHONY 可加在Makefile的最前面或最後面
以下為修改過的Makefile
#===Makefile===
test:
@echo "hihi"
.PHONY: test
#===end of Makefile===
這時打make test就能夠正確印出"hihi"了
[lab_linux test]$ make test
hihi
全站熱搜