GNU Make 工具

來源:互聯網
上載者:User
1、概述1.1、Makefile檔案

make在執行時,需要命名一個Makefile檔案。Makefile檔案描述了整個工程的編譯和串連等規則。

make命令預設在目前的目錄下尋找makefile或者Makefile檔案,當自訂檔案時用 :make -f 檔案名稱

1.2、用法1.2.1、規則

目標列表:依賴列表

<Tab>  
 命令列表

如:

hello.o:hello.c

           gcc -c hello.c

命令必須用tab鍵開始

1.2.2、目標

第一條規則中確定最終目標

1.2.3、偽目標

沒有任何依賴,只有執行動作的目標(phony targets)

用法:

.PHONY:目標名


如:clean目標聲明為偽目標,然後執行動作

.PHONY:clean

clean:

          rm -f hello hello1.o  hello2.o

1.2.4、變數

為了動態修改參數的變化依賴,方便管理


1.2.4.1、系統預設變數$...

$^      : 代表所有依賴檔案

$@      : 代表目標

$<       :代表第一個依賴檔案

$?        :代表所有已修改的依賴檔案


如:

hello:hello1.o hello2.0

        gcc hello1.o hello2.o -o hello

==>

hello:hello1.o hello2.o

         gcc $^ -o $@

1.2.4.2、普通變數=

變數名 := 文本

變數名 = 文本

變數名 +=  文本

1.2.4.3、引用變數$

$變數名

如:

C=gcc

$C

1.2.5、雜項#、@1.2.5.1、#

#注釋

1.2.5.2、@

@:取消回顯(螢幕不列印編譯目標訊息)

1.2.6、執行個體

hello: hello1.o hello2.o        gcc hello1.o hello2.o -o hellohello1.o:hello1.c          gcc -c hello1.chello2.o:hello2.c         gcc - c hello2.c.PHONY:cleanclean:        rm -f hello hello1.o hello2.o 




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.