如果我們的專案有指令是會重複執行的,透過 Makefile
可以集成內容,最方便的是多組合依序執行。
建立一個檔案名稱為 Makefile
:
基本應用
| init: |
| echo first command |
| echo second command |
| $ make init |
| echo first command |
| first command |
| echo second command |
| second command |
安靜輸出
如果你不希望 terminal 印出你下的命令內容,有幾種寫法可以避免。
| .SILENT: init |
| |
| init: |
| echo first command |
| echo second command |
| .SILENT: #影響全部 |
| |
| init: |
| echo first command |
| echo second command |
| init: |
| @echo first command |
| @echo second command |
多重步驟
| first_check: |
| echo first check |
| |
| second_check: |
| echo second check |
| |
| init: first_check second_check |
| echo init |
| $ make init |
| echo first check |
| first check |
| echo second check |
| second check |
| echo init |
| init |
變數
| file=default |
| |
| init: |
| @echo file is $(file) |
| $ make |
| file is default |
| |
| $ make file=new |
| file is new |
變數可以經由帶入方式覆蓋。