Makefile

tags: verilog digital design 邏輯設計 邏設

Makefile 是一個編譯程式原始碼常用的工具,透過 Makefile 檔案中自行定義好的敘述,即可用簡單的「make」指令,取代成一連串的指令。

特色

  • 輸入 make 指令後會在當前目錄下找尋 Makefile 文字檔 (沒有副檔名)。

  • Makefile 工具本身與 verilog 無關,學習這個工具可以節省打編譯指令時間。

  • 在這個課程中,只會學習到針對這門課,最基礎的 makefile 使用方法。若想學更多語法,請同學自行尋找網路上的資源。

  • 當我們在工作站上操作時,時常會需要輸入一長串的指令,例如:
    ncverilog ALU_tb.v ALU.v
    意思是使用 ncverilog 工具,執行所有 .v 檔及 testbench.v 的模擬。但是每次都要輸入一長串文字,如果設計的模組很多時,makefile 工具可以讓我們事先定義好,只需要輸入 make 指令即可取代一連串指令。

Example

下圖為 makefile 範例:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

程式碼說明:

  • 第1到12行,自行定義變數名稱與對應的字串,「=」的左邊為自行定義變數,「=」的右邊為取代的字串。例如:第1行的VLOG是自行定義的變數(變數名稱可以由同學自行決定),對應到的是 ncverilog 這個字串。

  • 反斜線(\): 例如:第3行的 FA.v 後面有個反斜線(\),意思是,緊接著的下一個字符,即下一行的字串 Adder32.v。其實也可以寫成 FA.v Adder32.v ALU.v 一長串,但是利用反斜線(\)是方便於排版,makefile 的可讀性。依同學喜好撰寫即可。

  • 先看到第16行,$( )中填寫的就是上面所定義的變數名稱。依照想要的指令順序一一填寫,

    • 例如:有一串指令是「ncverilog FA.v Adder32.v ALU.v testbench.v +access+r」,則我們將定義好的變數按照順序填寫「$(VLOG) $(SRC) $(VLOGARG)」即可。

    • 注意事項:第16行$(VLOG)前面的空白,必須使用Tab,而不可使用空白鍵space。請先看此頁最後面的注意事項。

  • 第15行,自行定義make指令,例如我們想做 simulation,所以自定義為「sim」。這麼一來,我們就可以輸入指令「make sim」來執行第16行的所有定義的字串。

  • 使用 makefile 來執行指令

    • 第14行,當我們只輸入「make」指令時,程式會從all開始檢查,而我們定義「all :: sim」的意思是,預設替代成「sim」這一串文字,所以在這個例子中「make」與「make sim」是一樣的。

    • 第17行,在 ncverilog 中,有個 check 語法的參數「-c」,我們也可以自定義「make check」來利用 ncverilog 檢查程式語法。

  • 第18行,自訂一個「make clean」來刪除模擬驗證過後的 work library 暫存檔以及 log 檔。通常若是不正常的終止模擬,在下一次模擬時可能會無法順利進行,就需要 clean 一下。(這裡用的是Linux的 remove指令「rm」)

    • 例如:先前模擬驗證過後出現的 work library 以及一些log檔:
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • 執行" make clean "後,即可刪除暫存檔:
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

注意事項

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

錯誤訊息:

若在打 make 後出現下面這行,則代表上圖要打 Tab 的地方沒有打 Tab !

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →